# -*- 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 116481 2014-01-26 17:19:15Z pixilla@macports.org $

PortSystem          1.0

name                pear-install-phar
version             20130325
categories          php www
license             BSD PHP-3 LGPL-2.1+
platforms           darwin
maintainers         pixilla
homepage            http://pear.php.net
master_sites        http://pear.php.net

subport php5-pear {

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

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}
}

use_configure       no

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

    description         PEAR installer phar
    long_description    ${description}

    livecheck.type      moddate

    dist_subdir         ${name}-${version}
    distfiles           install-pear-nozlib.phar

    checksums           rmd160  21ef3a980d2ef2fd3bcededc2291ac0a82f57dd6 \
                        sha256  c45983a5065b8bd2e4fbb9191786aacd43a0d4736493e5008f6f844c13a14563

    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}
    }
} else {

    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
    }
}
