# -*- 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 87343 2011-11-17 17:26:19Z pixilla@macports.org $

PortSystem          1.0

name                php5-pear
version             20110901
revision            2
categories          php www
platforms           darwin
maintainers         pixilla
description         PEAR build and repository support for php5
long_description    ${description}
homepage            http://pear.php.net
master_sites        http://pear.php.net
livecheck.type      moddate

depends_lib         port:php5

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

checksums           rmd160  1eef5e3a68b5521e2d42e68d031fd79828709923 \
                    sha256  06757ae34c93d4aad8a3abc63958106ca11bb1a9a5f85e7e013d70077e4aafa1

set buildpath       ${worksrcpath}/build
set libpath         /lib/php/pear
set dbpath          /var/db/php5

extract.mkdir       yes
extract {
    xinstall -d ${buildpath}${libpath}
    file copy ${distpath}/install-pear-nozlib.phar ${buildpath}${libpath}
}
use_configure       no
build {
    xinstall -d ${buildpath}${libpath}
    set fp [open ${buildpath}${libpath}/pear-ini.php w]
    puts $fp "<?php"
    puts $fp "# Automatically add the PEAR repository path to PHP's include_path."
    puts $fp "set_include_path ( get_include_path (  ) . PATH_SEPARATOR . '${prefix}/lib/php/pear' ) ;"
    close $fp

    xinstall -d ${buildpath}${dbpath}
    set fp [open ${buildpath}${dbpath}/pear.ini w]
    puts $fp "; Do not edit this file; it is automatically generated by MacPorts."
    puts $fp "; Any changes you make will be lost if you upgrade or uninstall php5-pear."
    puts $fp "; To configure PHP, edit ${prefix}/etc/php5/php.ini."
    puts $fp "auto_prepend_file = '${prefix}/lib/php/pear/pear-ini.php'"
    close $fp
}

destroot {
    xinstall -d ${destroot}${prefix}${libpath}
    xinstall -d ${destroot}${prefix}${dbpath}
    file copy ${buildpath}${libpath}/pear-ini.php ${destroot}${prefix}${libpath}/pear-ini.php
    file copy ${buildpath}${dbpath}/pear.ini ${destroot}${prefix}${dbpath}/pear.ini
    file copy ${buildpath}${libpath}/install-pear-nozlib.phar ${destroot}${prefix}${libpath}
}
