# -*- 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 108279 2013-07-17 21:26:28Z cal@macports.org $

PortSystem              1.0
PortGroup               perl5 1.0

# replicate perl5.setup to create the subports
name                    p5-eperl
version                 2.2.14
revision                6
distname                eperl-${version}
license                 {Artistic GPL}
platforms               darwin
categories              perl www
maintainers             cal openmaintainer

description             Embedded Perl Language
long_description        ePerl interprets an ASCII file bristled with Perl 5 \
                        program statements by evaluating the Perl 5 code while \
                        passing through the plain ASCII data.

homepage                http://www.ossp.org/pkg/tool/eperl/

master_sites            ftp://ftp.ossp.org/pkg/tool/eperl/ \
                        ftp://freebsd.isc.org/pub/FreeBSD/ports/distfiles/ \
                        http://freebsd.isc.org/pub/FreeBSD/ports/distfiles/

checksums               rmd160  708c72d4a2bc494e9b3e953aa13efd0fe7933b98 \
                        sha256  a9add61ed59e3030027e0ff5c00195627d7309be48162c9b315f57d27730a295

use_configure           yes

perl5.branches          5.8 5.10 5.12 5.14 5.16

## Most patches are copied from the Debian distribution, which uses patch
## files with a prefix
patch.pre_args          -p1
patchfiles              0001-copyright-updates.diff \
                        0002-eperl_2.2.14-15.2.diff \
                        0003-fix-spelling-errors.diff \
                        0004-document-double-shebang.diff \
                        0005-fix-preprocessor-comments-to-behave-as-documented.diff \
                        0006-fix-format-string-error-in-perl-stderr.diff \
                        0007-debian-2.2.14-16-modified-and-added-shtool.diff \
                        0008-wml-2.0.11-merge.diff \
                        0009-configure-use-correct-perl.diff

if {$subport != $name} {
    post-patch {
        # this file is added by 0007-*.diff, but must be executable
        file attributes "${worksrcpath}/etc/shtool" -permissions +x
    }
}

# replaced_by and subport magic
if {[string match p5-* $name]} {
    set rootname        [string range $name 3 end]

    foreach v ${perl5.branches} {
        subport p${v}-${rootname} {
            depends_lib port:perl${v}
            perl5.major ${v}
            livecheck.type none
        }
    }

    if {$subport == $name} {
        perl5.major
        distfiles
        supported_archs noarch
        replaced_by p[option perl5.default_branch]-${rootname}
        depends_lib port:p[option perl5.default_branch]-${rootname}
        use_configure no
        patch {}
        build {}
        destroot {
            xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
            system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README"
        }

        livecheck.type      regex
        livecheck.version   ${version}
        livecheck.url       ${homepage}
        livecheck.regex     {class="heavy">(\d+(?:\.\d+)*)<}
    }
}

# keep this behind the block setting perl5.major
configure.args          --with-perl=${perl5.bin} \
                        --enable-debug \
                        CC=\"${configure.cc} [get_canonical_archflags cc]\" \
                        LD=\"${configure.cc} [get_canonical_archflags ld]\"

destroot.destdir        prefix=${destroot}${prefix} \
                        mandir=${destroot}${prefix}/share/man/man1

test.run                yes
