# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 80451 2011-07-13 13:24:34Z jmr@macports.org $

PortSystem      1.0

name            perl5
version         5.12.3
revision        1
categories      lang
license         BSD
platforms       darwin freebsd linux
maintainers     ricci mcalhoun
supported_archs noarch

description         Wrapper port for perl 5.x
long_description    ${description}

homepage        http://www.perl.org/
distfiles

use_configure       no
build {}

if {[variant_isset perl5_8]} {
    set branch 5.8
} elseif {[variant_isset perl5_10]} {
    set branch 5.10
} elseif {[variant_isset perl5_14]} {
    set branch 5.14
} else {
    set branch 5.12
    default_variants +perl5_12
}

##
## Note:  the destroot section below currently uses lists of files
##   to know what files to link.  In the future we can use
##   something like:
##     set contents_list [registry_port_registered $portname])
##   to get the lists of binaries and man pages installed by
##   the perl5.x ports.
##
destroot {
    if {[file exists ${prefix}/bin/perl${branch}]} {
        ln -s perl${branch} ${destroot}${prefix}/bin/${name}
        ln -s perl${branch} ${destroot}${prefix}/bin/perl
    } else {
        ui_error "Can't find perl ${branch} (as ${prefix}/bin/perl${branch}) so can't link $name to it."
        return -code error "perl${version} is missing"
    }
    # some binaries are not included in the list because they would conflict
    # with module ports:
    # config_data    -> p5-module-build (ticket #24025)
    # corelist       -> p5-module-corelist (ticket #28485)
    # instmodsh      -> p5-extutils-makemaker (ticket #24590)
    # ptar, ptardiff -> p5-archive-tar (ticket #28255)
    # shasum         -> p5-digest-sha (ticket #28580)
    foreach list {binList man1pList man3pList} {
        set fd [open ${filespath}/${list}]; set $list [read $fd]; close $fd
    }
    foreach binFile $binList {
        if {[file exists ${prefix}/bin/${binFile}-${branch}]} {
            ln -s ${binFile}-${branch} ${destroot}${prefix}/bin/${binFile}
        }
    }
    file mkdir ${destroot}${prefix}/share/man/man1p
    foreach manFile $man1pList {
        if {[file exists ${prefix}/share/man/man1p/${manFile}-${branch}.1pm]} {
            ln -s ${manFile}-${branch}.1pm ${destroot}${prefix}/share/man/man1p/${manFile}.1pm
        }
    }
    file mkdir ${destroot}${prefix}/share/man/man3p
    foreach manFile $man3pList {
        if {[file exists ${prefix}/share/man/man3p/${manFile}-${branch}.3pm]} {
            ln -s ${manFile}-${branch}.3pm ${destroot}${prefix}/share/man/man3p/${manFile}.3pm
        }
    }
}

variant perl5_8 conflicts perl5_10 perl5_12 perl5_14 description { use perl 5.8 instead of perl 5.10, perl 5.12, or perl 5.14} {
    depends_lib-append  port:perl5.8
}

variant perl5_10 conflicts perl5_8 perl5_12 perl5_14 description { use perl 5.10 instead of perl 5.8, perl 5.12, perl 5.14} {
    depends_lib-append  port:perl5.10
}

variant perl5_12 conflicts perl5_8 perl5_10 perl5_14 description { use perl 5.12 instead of perl 5.8, perl 5.10, or perl 5.14} {
    depends_lib-append  port:perl5.12
}

variant perl5_14 conflicts perl5_8 perl5_10 perl5_12 description { use perl 5.14 instead of perl 5.8, perl 5.10, or perl 5.12} {
    depends_lib-append  port:perl5.14
}

livecheck.type     none
