# -*- 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 55185 2009-08-07 11:43:02Z snc@macports.org $

PortSystem      1.0

name            perl5.8
version         5.8.9
revision        3
categories      lang
platforms       darwin freebsd linux
maintainers     ricci openmaintainer
description     Perl 5.8.x - Practical Extraction and Report Language

long_description \
    Perl is a general-purpose programming language originally developed \
    for text manipulation and now used for a wide range of tasks including \
    system administration, web development, network programming, GUI \
    development, and more.

distname        perl-${version}
use_bzip2       yes
homepage        http://www.perl.org/
master_sites    http://www.cpan.org/src/

checksums        \
    md5     1cb52a76ce77fa300218da96577793ec \
    sha1    19843b5a7585cf35d96c07dbcd419bbdd5813617 \
    rmd160  680004238d626ec985075e1b4519b7f0b34f57e5

patchfiles  patch-perl.c.diff patch-Configure.diff

post-patch {
    reinplace "s|/opt/local|${prefix}|g" ${worksrcpath}/Configure
    # Ensure that the ld value set in configure.args is used
    reinplace "s|ld='cc';||" ${worksrcpath}/hints/darwin.sh
}

configure.ccache    no
configure.env       LC_ALL=C
configure.cmd       /bin/sh Configure
configure.pre_args
configure.args \
    -des \
    -D prefix='${prefix}' \
    -D scriptdir='${prefix}/bin' \
    -D cppflags="\${CPPFLAGS}" \
    -D ldflags="\${LDFLAGS}" \
    -D vendorprefix='${prefix}' \
    -D man1ext='1pm' \
    -D man3ext='3pm' \
    -D cc=\${CC} \
    -D ld=\${CC} \
    -D man1dir='${prefix}/share/man/man1p' \
    -D man3dir='${prefix}/share/man/man3p' \
    -D siteman1dir='${prefix}/share/man/man1' \
    -D siteman3dir='${prefix}/share/man/man3' \
    -D vendorman1dir='${prefix}/share/man/man1' \
    -D vendorman3dir='${prefix}/share/man/man3'

# Allow perl to find p5-* port installed by the last version
if { [variant_isset threads] } {
    configure.args-append "-D inc_version_list=\"5.8.8 5.8.8/${os.platform}-thread-multi-2level\""
} else {
    configure.args-append "-D inc_version_list=\"5.8.8 5.8.8/${os.platform}-2level\""
}

set exclude_libs {bind gdbm db}

post-patch {
    foreach lib ${exclude_libs} {
        configure.args-append  -U i_${lib}
        reinplace "s|\\(libswanted=.*\\)${lib} *\\(.*\\)|\\1\\2|" ${worksrcpath}/Configure
    }
}

universal_variant   no

test.run            yes

post-destroot {
    ln -s perl${version} ${destroot}${prefix}/bin/$name
}

variant threads description {Build with thread support} {
    configure.args-append   -Dusethreads
}

variant shared description {Build shared perl library} {
    configure.args-append   -Duseshrplib
}

variant gdbm description {Build with gdbm support} {
    depends_lib-append port:gdbm
    set exclude_libs [ldelete ${exclude_libs} gdbm]
}

variant db description {Build with Berkeley Data Base support} {
    depends_lib-append port:db47
    set exclude_libs [ldelete ${exclude_libs} db]
    
    post-patch {
        reinplace "s|${prefix}/include|${prefix}/include ${prefix}/include/db47|g" ${worksrcpath}/Configure
        reinplace "s|${prefix}/lib|${prefix}/lib ${prefix}/lib/db47|g" ${worksrcpath}/Configure
    }
}

livecheck.check regex
livecheck.url   http://www.cpan.org/src
livecheck.regex {perl-(5\.8\.\d)\.}
