# -*- 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

PortSystem          1.0

name                pear-install-phar
version             20170831
categories          php www
platforms           darwin
maintainers         pixilla openmaintainer
homepage            http://pear.php.net
master_sites        http://pear.php.net

subport php5-pear {}

subport php53-pear {

    set php.port        [lindex [split $subport -] 0]
    set php.db          /var/db/${php.port}
    depends_lib         port:${php.port}
}

subport php54-pear {

    set php.port        [lindex [split $subport -] 0]
    set php.db          /var/db/${php.port}
    depends_lib         port:${php.port}
}

subport php55-pear {

    set php.port        [lindex [split $subport -] 0]
    set php.db          /var/db/${php.port}
    depends_lib         port:${php.port}
}

subport php56-pear {

    set php.port        [lindex [split $subport -] 0]
    set php.db          /var/db/${php.port}
    depends_lib         port:${php.port}
}

subport php70-pear {

    set php.port        [lindex [split $subport -] 0]
    set php.db          /var/db/${php.port}
    depends_lib         port:${php.port}
}

subport php71-pear {

    set php.port        [lindex [split $subport -] 0]
    set php.db          /var/db/${php.port}
    depends_lib         port:${php.port}
}

use_configure       no

if {${name} == ${subport}} {

    license             PHP-3 LGPL-2.1+
    description         PEAR installer phar
    long_description    ${description}

    livecheck.type      moddate
#     Keeping this in Portfile because of frequent stealth updates.
#     dist_subdir         ${name}-${version}
    distfiles           install-pear-nozlib.phar

    checksums           rmd160  f0d0388e5fe170557f2815efed7dee7f5b9df073 \
                        sha256  41f36cc001833ddfbd935f86113bf8c324de4b526ec44321d120bb865715dad9

    set buildpath       ${worksrcpath}/build
    set libpath         /lib/php/pear

    extract.mkdir       yes
    extract {

        xinstall -d ${buildpath}${libpath}
        file copy ${distpath}/install-pear-nozlib.phar ${buildpath}${libpath}
    }

    build {}
    destroot {

        xinstall -d ${destroot}${prefix}${libpath}
        file copy ${buildpath}${libpath}/install-pear-nozlib.phar ${destroot}${prefix}${libpath}
    }
} elseif {${subport} eq {php5-pear}} {

    replaced_by         php55-pear
    PortGroup           obsolete 1.0
} else {

    license             BSD
    description         Optional port adds the PEAR repository to the include path for ${php.port}.
    long_description    ${description}

    distfiles

    worksrcdir          ${php.port}-pear
    extract.dir         ${worksrcpath}
    extract.mkdir       yes
    post-extract {

        copy ${filespath}/pear-ini.php ${worksrcpath}/pear-ini.php
        copy ${filespath}/pear.ini ${worksrcpath}/pear.ini
    }

    post-patch {

        reinplace "s,@PHP.PORT@,${php.port},g" \
            ${worksrcpath}/pear.ini
        reinplace "s,@PREFIX@,${prefix},g" \
            ${worksrcpath}/pear-ini.php \
            ${worksrcpath}/pear.ini
    }

    use_configure       no
    build {}

    destroot {

        xinstall -d -m 0755 ${destroot}${prefix}/var/db/${php.port}/pear
        xinstall -m 0644 ${worksrcpath}/pear-ini.php \
            ${destroot}${prefix}/var/db/${php.port}/pear/pear-ini.php
        xinstall -m 0644 ${worksrcpath}/pear.ini \
            ${destroot}${prefix}/var/db/${php.port}/pear.ini
    }
}