# -*- 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 92887 2012-05-10 07:02:23Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               php 1.0

name                    php
categories              lang php www
platforms               darwin freebsd
maintainers             ryandesign jwa
license                 PHP-3.01
master_sites            php
use_parallel_build      yes
use_bzip2               yes
livecheck.type          none

description             PHP: Hypertext Preprocessor

long_description        PHP is a widely-used general-purpose scripting \
                        language that is especially suited for developing \
                        web sites, but can also be used for command-line \
                        scripting.

# The list of PHP branches this port provides.
php.branches            5.3 5.4

# Fix for users specifying the subport name with the wrong case.
set subport             [string tolower ${subport}]

# Get rootname from subport.
regexp {^php\d+-(.+)$} ${subport} -> php.rootname

# Returns true if the subport is a SAPI, false otherwise (extension, stub port).
proc is_sapi_subport {} {
    global name subport php.rootname
    if {${name} == ${subport}} {
        return no
    }
    if {[regexp {^php\d+$} ${subport}]} {
        return yes
    }
    return [expr {-1 != [lsearch -exact [list apache2handler cgi fpm] ${php.rootname}]}]
}

# Returns true if the subport is an extension, false otherwise (SAPI, stub port).
proc is_extension_subport {} {
    global name subport
    if {${name} == ${subport}} {
        return no
    }
    return [expr {![is_sapi_subport]}]
}

if {![is_extension_subport]} {
    homepage            http://www.php.net/
}

set subport_branch      [php.branch_from_subport]

# Remember to increment revision of ${php}-eaccelerator when updating version of ${php}.
switch ${subport_branch} {
    5.3 {
        version         5.3.13
        set suhosin_available       yes
        set suhosin_patch_version   5.3.9-0.9.10
        set suhosin_patch           suhosin-patch-${suhosin_patch_version}.patch.gz
        checksums       [suffix ${distname}] \
                        rmd160  1ad55e7bd1262471c66d2236fbba76c137960029 \
                        sha256  ef1a7235b16be449f31f73f60d5770a133b863d225d65a218546cfb7d031d99b \
                        ${suhosin_patch} \
                        rmd160  ce43921fd9b183b154713ecda98294f6c68d5f22 \
                        sha256  4438caeab0a10c6c94aee9f7eaa703f5799f97d4e0579f43a947bb7314e38317
    }
    5.4 {
        epoch           1
        version         5.4.3
        set suhosin_available       no
        checksums       [suffix ${distname}] \
                        rmd160  a6c0ab078283a3499bf1d10ac2b6e67716fa2cba \
                        sha256  d7e0c987586b6554ee08e3b71cc2806ddd1b192451159083d861c132994bc1bd
    }
}

# Iterate through branches in reverse order, so that the list of subports in
# "port info" will show newer versions before older versions.
set i [llength ${php.branches}]
while {[incr i -1] >= 0} {

set branch              [lindex ${php.branches} ${i}]
set major               [lindex [split ${branch} .] 0]
set php                 php[php.suffix_from_branch ${branch}]

if {[regexp "^${php}" ${subport}]} {

dist_subdir             php${major}

if {[is_sapi_subport]} {
    
    depends_build       port:pkgconfig
    
    if {${subport} != ${php}} {
        depends_lib     port:${php}
    }
    
    depends_lib-append  path:bin/gsed:gsed \
                        port:libiconv \
                        port:libxml2 \
                        port:bzip2 \
                        port:mhash \
                        port:pcre \
                        port:zlib
    
    # Use -p1 to accommodate the Suhosin patch
    patch.pre_args      -p1
    patchfiles          patch-${php}-scripts-php-config.in.diff
    
    if {${configure.compiler} == "clang"} {
        configure.compiler llvm-gcc-4.2
    }
    
    set phpinidir       ${prefix}/etc/${php}
    set extraphpinidir  ${prefix}/var/db/${php}
    
    configure.args      --mandir=${prefix}/share/man \
                        --infodir=${prefix}/share/info \
                        --program-suffix=[php.suffix_from_branch ${branch}] \
                        --includedir=${prefix}/include/${php} \
                        --libdir=${prefix}/lib/${php} \
                        --with-config-file-path=${phpinidir} \
                        --with-config-file-scan-dir=${extraphpinidir} \
                        --disable-all \
                        --enable-bcmath \
                        --enable-ctype \
                        --enable-dom \
                        --enable-fileinfo \
                        --enable-filter \
                        --enable-hash \
                        --enable-json \
                        --enable-libxml \
                        --enable-pdo \
                        --enable-phar \
                        --enable-session \
                        --enable-simplexml \
                        --enable-tokenizer \
                        --enable-xml \
                        --enable-xmlreader \
                        --enable-xmlwriter \
                        --with-bz2=${prefix} \
                        --with-mhash=${prefix} \
                        --with-pcre-regex=${prefix} \
                        --with-libxml-dir=${prefix} \
                        --with-zlib=${prefix} \
                        --without-pear \
                        --disable-cgi \
                        --disable-cli \
                        --disable-fpm
    
    # ${php}-mysql +mysqlnd needs mysqlnd support compiled into the SAPI
    configure.env       PHP_MYSQLND_ENABLED=yes
    
    configure.universal_args-delete --disable-dependency-tracking
    
    test.run            yes
    
    destroot.args       INSTALL_ROOT=${destroot}
    
    variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {
        configure.args-append   --enable-debug
    }
    
    variant suhosin description {Add Suhosin patch} {
        pre-fetch {
            if {"darwin" == ${os.platform} && ${os.major} < 9} {
                ui_error "The suhosin variant requires Mac OS X 10.5 or greater."
                return -code error "incompatible Mac OS X version"
            }
            if {!${suhosin_available}} {
                ui_error "There is no suhosin patch for PHP ${version} yet. Please check back later."
            }
            if {![file exists ${extraphpinidir}/suhosin.ini]} {
                ui_msg "You may also be interested in the suhosin extension, a related but different piece of software. See the ${php}-suhosin port."
            }
            if {!${suhosin_available}} {
                return -code error "unavailable variant"
            }
        }
        patch_sites-append          http://download.suhosin.org/
        if {${suhosin_available}} {
            patchfiles-append       ${suhosin_patch}
        }
    }
    
    if {${subport} != ${php}} {
        notes-append "If this is your first install, you need to enable ${subport} in your web server."
    }
    
}

}

### CLI SAPI ###

subport ${php} {
    PortGroup               select 1.0
    
    depends_run             port:php_select
    
    select.group            php
    select.file             ${filespath}/${subport}
    
    configure.args-delete   --disable-cli
    configure.args-append   --enable-cli
    
    destroot.target         install-cli install-build install-headers install-programs
    
    destroot.keepdirs       ${destroot}${extraphpinidir}
    
    post-destroot {
        # Copy the default php.ini files.
        xinstall -m 755 -d ${destroot}${phpinidir}
        xinstall -m 644 -W ${worksrcpath} \
            php.ini-development \
            php.ini-production \
            ${destroot}${phpinidir}
        
        # Copy mysqlnd headers.
        xinstall -d ${destroot}${prefix}/include/${php}/php/ext/mysqlnd
        eval xinstall -m 644 [glob ${worksrcpath}/ext/mysqlnd/*.h] ${destroot}${prefix}/include/${php}/php/ext/mysqlnd
    }
    
    # Include the readline extension http://www.php.net/readline directly in
    # the PHP CLI SAPI because until PHP 6 the interactive mode "php -a" won't
    # work with a separately built readline extension.
    # https://bugs.php.net/bug.php?id=53878
    # Users might prefer readline over libedit because only readline supports
    # readline_list_history() (http://www.php.net/readline-list-history).
    # On the other hand we want libedit to be the default because its license
    # is compatible with PHP's which means PHP can be distributable.
    variant libedit conflicts readline description {Build readline extension using libedit library} {
        depends_lib-append      port:libedit
        configure.args-append   --with-libedit=${prefix}
    }
    variant readline conflicts libedit description {Build readline extension using readline library} {
        depends_lib-append      port:readline
        configure.args-append   --with-readline=${prefix}
    }
    if {![variant_isset readline]} {
        default_variants +libedit
    }
    
    if {![file exists ${phpinidir}/php.ini]} {
        notes-append "
To customize ${php}, copy\
${phpinidir}/php.ini-development (if this is a development server) or\
${phpinidir}/php.ini-production (if this is a production server) to\
${phpinidir}/php.ini and then make changes.
"
    } else {
        notes-append "
You may need to update your php.ini for any changes that have been made\
in this version of ${php}. Compare ${phpinidir}/php.ini with\
${phpinidir}/php.ini-development (if this is a development server) or\
${phpinidir}/php.ini-production (if this is a production server).
"
    }
    
    # Enable livecheck for the two most recent PHP branches.
    if {[vercmp ${branch} [lindex ${php.branches} end-1]] >= 0} {
        livecheck.type      regex
        livecheck.url       ${homepage}downloads.php
        livecheck.regex     get/php-([strsed ${branch} {g/\\./\\./}](?:\\.\[0-9.\]+)*)\\.tar
    }
}

### Apache 2 handler SAPI ###

subport ${php}-apache2handler {
    description             ${php} Apache 2 Handler SAPI
    
    long_description        ${description}
    
    homepage                http://www.php.net/install.unix.apache2
    
    depends_lib-append      port:apache2
    
    set apxs ${prefix}/apache2/bin/apxs
    set confdir ${prefix}/apache2/conf
    set moduledir ${prefix}/apache2/modules
    
    pre-configure {
        # Checking for mod_cgi.so is a convenient way to verify apache2 is using its
        # +preforkmpm variant. (+eventmpm and +workermpm instead provide mod_cgid.so.)
        if {![file exists ${moduledir}/mod_cgi.so]} {
            ui_error "To use ${subport}, apache2 must be installed with the +preforkmpm variant."
            return -code error "incompatible apache2 installation"
        }
    }
    
    configure.args-append   --with-apxs2=${apxs}
    
    build.target            libs/libphp5.bundle
    
    destroot.violate_mtree  yes
    
    destroot {
        xinstall -m 755 -d ${destroot}${moduledir} ${destroot}${confdir}/extra
        xinstall -m 644 ${worksrcpath}/libs/libphp5.so ${destroot}${moduledir}/mod_${php}.so
        xinstall -m 644 ${filespath}/mod_php.conf ${destroot}${confdir}/extra/mod_${php}.conf
    }
    
    notes-append "

To enable ${subport}, run:

    cd ${moduledir}
    sudo ${apxs} -a -e -n php${major} mod_${php}.so
"
}

### CGI SAPI ###

subport ${php}-cgi {
    description             ${php} CGI SAPI
    
    long_description        ${description}
    
    homepage                http://www.php.net/install.unix.commandline
    
    configure.args-delete   --disable-cgi
    configure.args-append   --enable-cgi
    
    if {[vercmp ${branch} 5.4] >= 0} {
        build.target        cgi
        destroot.target     install-cgi
    } else {
        destroot {
            xinstall ${worksrcpath}/sapi/cgi/php-cgi ${destroot}${prefix}/bin/php-cgi[php.suffix_from_branch ${branch}]
        }
    }
    
}

### FPM SAPI ###

subport ${php}-fpm {
    description             ${php} FPM SAPI
    
    long_description        ${description}
    
    homepage                http://www.php.net/install.fpm
    
    set fpmuser             nobody
    set fpmgroup            nobody
    
    patchfiles-append       patch-${php}-sapi-fpm-php-fpm.conf.in.diff
    
    post-patch {
        reinplace "s|@PHP@|${php}|g" ${worksrcpath}/sapi/fpm/php-fpm.conf.in
    }
    
    configure.args-delete   --disable-fpm
    configure.args-append   --enable-fpm \
                            --sysconfdir=${phpinidir} \
                            --with-fpm-user=${fpmuser} \
                            --with-fpm-group=${fpmgroup}
    
    build.target            fpm
    
    destroot.target         install-fpm
    
    destroot.keepdirs       ${destroot}${prefix}/var/log/${php} \
                            ${destroot}${prefix}/var/run/${php}
    
    post-destroot {
        xinstall -d -o ${fpmuser} -g ${fpmgroup} ${destroot}${prefix}/var/log/${php} ${destroot}${prefix}/var/run/${php}
    }
    
    startupitem.create      yes
    startupitem.executable  ${prefix}/sbin/php-fpm[php.suffix_from_branch ${branch}]
    
    if {![file exists ${phpinidir}/php-fpm.conf]} {
        notes-append "

To use ${subport}, copy\
${phpinidir}/php-fpm.conf.default to\
${phpinidir}/php-fpm.conf and make changes if desired.
"
    } else {
        notes-append "

You may need to update your php-fpm.conf for any changes that have been made\
in this version of ${subport}. Compare ${phpinidir}/php-fpm.conf with\
${phpinidir}/php-fpm.conf.default.
"
    }
}

### Bundled extensions ###

subport ${php}-calendar {
    description             a PHP extension for converting between different \
                            calendar formats
    
    long_description        ${description}
}

subport ${php}-curl {
    categories-append       net www
    
    description             a PHP interface to the curl library, which lets you \
                            download files from servers with a variety of protocols
    
    long_description        ${description}
    
    depends_lib-append      port:curl
    
    configure.args-append   --with-curl=${prefix}
}

subport ${php}-dba {
    categories-append       databases
    
    description             a PHP interface for accessing DBM databases such as \
                            BerkeleyDB
    
    long_description        ${description}
    
    variant gdbm conflicts qdbm description {Add GDBM support} {
        depends_lib-append      port:gdbm
        configure.args-append   --with-gdbm=${prefix}
    }
    
    variant qdbm conflicts gdbm description {Add QDBM support} {
        depends_lib-append      port:qdbm
        configure.args-append   --with-qdbm=${prefix}
    }
}

subport ${php}-exif {
    categories-append       graphics
    
    description             a PHP interface to the EXIF image metadata functions
    
    long_description        ${description}
}

subport ${php}-ftp {
    categories-append       net
    
    description             a PHP extension for accessing file servers using the \
                            File Transfer Protocol
    
    long_description        ${description}
    
    depends_lib-append      port:openssl
    
    configure.args-append   --with-openssl-dir=${prefix}
}

subport ${php}-gd {
    categories-append       graphics
    
    description             a PHP interface to the gd library
    
    long_description        ${description}
    
    depends_lib-append      port:freetype \
                            port:jpeg \
                            port:libpng \
                            port:zlib
    
    configure.args-append   --with-freetype-dir=${prefix} \
                            --with-jpeg-dir=${prefix} \
                            --with-png-dir=${prefix} \
                            --with-zlib-dir=${prefix} \
                            --enable-gd-native-ttf
    
    variant t1lib description {Add PostScript Type 1 font support with t1lib} {
        depends_lib-append      port:t1lib
        configure.args-append   --with-t1lib=${prefix}
    }
}

subport ${php}-gettext {
    categories-append       devel
    
    description             a PHP interface to the gettext natural language \
                            support functions
    
    long_description        ${description}
    
    depends_lib-append      port:gettext
    
    configure.args-append   --with-gettext=${prefix}
}

subport ${php}-gmp {
    categories-append       devel math
    
    description             a PHP interface to GMP, the GNU multiprocessing \
                            library through which you can work with \
                            arbitrary-length integers
    
    long_description        ${description}
    
    depends_lib-append      port:gmp
    
    configure.args-append   --with-gmp=${prefix}
}

subport ${php}-iconv {
    categories-append       textproc
    
    description             a PHP interface to the libiconv character encoding \
                            conversion functions
    
    long_description        ${description}
    
    depends_lib-append      port:libiconv
    
    configure.args-append   --with-iconv=${prefix}
}

subport ${php}-imap {
    categories-append       mail
    
    description             a PHP interface to the IMAP protocol
    
    long_description        ${description}
    
    depends_build-append    port:cclient
    
    configure.args-append   --with-imap=${prefix} \
                            --with-imap-ssl=${prefix}
    
    platform macosx {
        configure.args-append   --with-kerberos=/usr
    }
}

subport ${php}-intl {
    categories-append       devel
    
    description             internationalization extension for PHP
    
    long_description        Internationalization extension implements ICU \
                            library functionality in PHP.
    
    depends_lib-append      port:icu
}

subport ${php}-ldap {
    categories-append       databases
    
    description             a PHP interface to LDAP
    
    long_description        ${subport} is ${description}, the Lightweight Directory \
                            Access Protocol, which is used to access Directory \
                            Servers.
    
    depends_lib-append      port:openldap \
                            port:cyrus-sasl2
    
    configure.args-append   --with-ldap=${prefix} \
                            --with-ldap-sasl=${prefix}
}

subport ${php}-mbstring {
    categories-append       textproc
    
    description             a PHP extension for manipulating strings in multibyte \
                            encodings
    
    long_description        ${description}
}

subport ${php}-mcrypt {
    categories-append       security
    
    description             a PHP interface to the mcrypt library, which offers \
                            a wide variety of algorithms
    
    long_description        ${description}
    
    depends_lib-append      port:libmcrypt
    
    # The mcrypt extension may be using libtool unnecessarily; monitor
    # https://bugs.php.net/bug.php?id=54500
    depends_lib-append      port:libtool
    
    configure.args-append   --with-mcrypt=${prefix}
}

subport ${php}-mssql {
    php.extensions          mssql pdo_dblib
    
    categories-append       databases
    
    description             a PHP interface to MSSQL using FreeTDS, including \
                            the mssql and pdo_dblib extensions
    
    long_description        ${description}
    
    depends_lib-append      port:freetds
    
    configure.args-append   --with-mssql=${prefix} \
                            --with-pdo-dblib=${prefix}
}

subport ${php}-mysql {
    php.extensions          mysql mysqli pdo_mysql
    
    categories-append       databases
    
    description             a PHP interface to MySQL databases, including the \
                            mysql, mysqli and pdo_mysql extensions
    
    long_description        ${description}
    
    depends_lib-append      port:zlib
    
    configure.args-append   --with-zlib-dir=${prefix}
    
    variant mysqlnd conflicts mysql4 mysql5 description {Use MySQL Native Driver} {
        configure.args-append   --with-mysql=mysqlnd \
                                --with-mysqli=mysqlnd \
                                --with-pdo-mysql=mysqlnd
        
        configure.cppflags-append   -I${worksrcpath}
        
        post-install {
            set phpini ${prefix}/etc/${php}/php.ini
            if {1} {
                ui_msg "To use mysqlnd with a local MySQL server, edit ${phpini} and set"
                ui_msg "mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket"
                ui_msg "to ${prefix}/var/run/mysql5/mysqld.sock"
            }
        }
    }
    
    variant mysql4 conflicts mysql5 mysqlnd description {Use MySQL 4 libraries} {
        depends_lib-append      port:mysql4
        
        configure.args-append   --with-mysql=${prefix} \
                                --with-pdo-mysql=${prefix}
    }
    
    variant mysql5 conflicts mysql4 mysqlnd description {Use MySQL 5 libraries} {
        depends_lib-append      path:bin/mysql_config5:mysql5
        
        post-extract {
            file mkdir ${workpath}/mysql5
            file link -symbolic ${workpath}/mysql5/lib ${prefix}/lib/mysql5
            file link -symbolic ${workpath}/mysql5/include ${prefix}/include/mysql5
        }
        
        configure.args-append   --with-mysql=${workpath}/mysql5 \
                                --with-mysqli=${prefix}/bin/mysql_config5 \
                                --with-pdo-mysql=${prefix}/bin/mysql_config5 \
                                --with-mysql-sock=${prefix}/var/run/mysql5/mysqld.sock
    }
    
    if {![variant_isset mysql4] && ![variant_isset mysql5]} {
        default_variants +mysqlnd
    }
}

subport ${php}-odbc {
    php.extensions          odbc pdo_odbc
    
    categories-append       databases
    
    description             a PHP interface for accessing databases via Open \
                            DataBase Connectivity (ODBC)
    
    long_description        ${description}
    
    variant iodbc conflicts unixodbc description {Use iODBC} {
        depends_lib-append      port:libiodbc
        
        patchfiles-append       patch-${php}-iODBC.diff
        
        configure.args-append   --with-iODBC=${prefix} \
                                --with-pdo-odbc=iODBC,${prefix}
    }
    
    variant unixodbc conflicts iodbc description {Use unixODBC} {
        depends_lib-append      port:unixODBC
        
        patchfiles-append       patch-${php}-unixODBC.diff
        
        configure.args-append   --with-unixODBC=${prefix} \
                                --with-pdo-odbc=unixODBC,${prefix}
    }
    
    if {![variant_isset iodbc] && ![variant_isset unixodbc]} {
        default_variants +unixodbc
    }
}

subport ${php}-openssl {
    categories-append       devel security
    
    description             a PHP interface to OpenSSL signature-generation \
                            and -verification and data-encryption and \
                            -decryption functions
    
    long_description        ${description}
    
    depends_lib-append      port:openssl
    
    post-extract {
        move ${build.dir}/config0.m4 ${build.dir}/config.m4
    }
    
    configure.args-append   --with-openssl=${prefix}
    
    platform macosx {
        configure.args-append   --with-kerberos=/usr
    }
}

subport ${php}-oracle {
    php.extensions          oci8 pdo_oci
    
    categories-append       databases
    
    description             a PHP interface to Oracle, including the oci8 and \
                            pdo_oci extensions
    
    long_description        ${description}
    
    depends_lib-append      port:oracle-instantclient
    
    configure.args-append   --with-oci8=instantclient,${prefix}/lib/oracle \
                            --with-pdo-oci=instantclient,${prefix}/lib/oracle,10.1
}

subport ${php}-pcntl {
    categories-append       sysutils
    
    description             a PHP interface to Unix-style process creation, \
                            program execution, signal handling and process \
                            termination functions
    
    long_description        ${description}
    
    notes "
${subport} should not be enabled within a web server environment.\
Unexpected results may occur if any process control functions are used within\
a web server environment.
"
}

subport ${php}-posix {
    categories-append       sysutils
    
    description             a PHP interface to additional POSIX functions
    
    long_description        a PHP interface to those functions defined in the \
                            IEEE 1003.1 (POSIX.1) standards document which are \
                            not accessible through other means
}

subport ${php}-postgresql {
    php.extensions          pgsql pdo_pgsql
    
    categories-append       databases
    
    homepage                http://www.php.net/pgsql
    
    description             a PHP interface to PostgreSQL, including \
                            the pgsql and pdo_pgsql extensions
    
    long_description        ${description}
    
    variant postgresql82 conflicts postgresql83 postgresql84 postgresql90 postgresql91 description {Use PostgreSQL 8.2 libraries} {
        depends_lib-append      port:postgresql82
        
        configure.args-append   --with-pgsql=${prefix}/lib/postgresql82/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql82/bin
    }
    
    variant postgresql83 conflicts postgresql82 postgresql84 postgresql90 postgresql91 description {Use PostgreSQL 8.3 libraries} {
        depends_lib-append      port:postgresql83
        
        configure.args-append   --with-pgsql=${prefix}/lib/postgresql83/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql83/bin
    }
    
    variant postgresql84 conflicts postgresql82 postgresql83 postgresql90 postgresql91 description {Use PostgreSQL 8.4 libraries} {
        depends_lib-append      port:postgresql84
        
        configure.args-append   --with-pgsql=${prefix}/lib/postgresql84/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql84/bin
    }
    
    variant postgresql90 conflicts postgresql82 postgresql83 postgresql84 postgresql91 description {Use PostgreSQL 9.0 libraries} {
        depends_lib-append      port:postgresql90
        
        configure.args-append   --with-pgsql=${prefix}/lib/postgresql90/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql90/bin
    }
    
    variant postgresql91 conflicts postgresql82 postgresql83 postgresql84 postgresql90 description {Use PostgreSQL 9.1 libraries} {
        depends_lib-append      port:postgresql91
        
        configure.args-append   --with-pgsql=${prefix}/lib/postgresql91/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql91/bin
    }
    
    if {![variant_isset postgresql82] && ![variant_isset postgresql83] && ![variant_isset postgresql84] && ![variant_isset postgresql90] && ![variant_isset postgresql91]} {
        default_variants +postgresql91
    }
}

subport ${php}-pspell {
    categories-append       textproc
    
    description             a PHP interface to the aspell library, which lets you \
                            check spelling and offer spelling suggestions
    
    long_description        ${description}
    
    depends_lib-append      port:aspell
    
    configure.args-append   --with-pspell=${prefix}
}

subport ${php}-snmp {
    categories-append       sysutils
    
    description             a PHP interface to the Simple Network Management \
                            Protocol (SNMP)
    
    long_description        ${description}
    
    depends_lib-append      port:net-snmp
    
    configure.args-append   --with-snmp=${prefix}
}

subport ${php}-soap {
    categories-append       net
    
    description             a PHP extension for writing SOAP clients and servers
    
    long_description        ${description}
    
    depends_lib-append      port:libxml2
    
    configure.args-append   --with-libxml-dir=${prefix}
}

subport ${php}-sockets {
    categories-append       net
    
    description             a PHP interface to BSD socket communication \
                            functions
    
    long_description        ${description}
}

subport ${php}-sqlite {
    php.extensions          sqlite sqlite3 pdo_sqlite
    
    categories-append       databases
    
    description             a PHP interface to SQLite, including the sqlite, sqlite3 \
                            and pdo_sqlite extensions
    
    if {[vercmp ${branch} 5.4] >= 0} {
        php.extensions-delete sqlite
        description-delete "sqlite,"
    }
    
    long_description        ${description}
    
    depends_lib-append      port:sqlite3
    
    post-extract {
        move ${worksrcpath}/ext/sqlite3/config0.m4 ${worksrcpath}/ext/sqlite3/config.m4
    }
    
    configure.args-append   --with-sqlite3=${prefix} \
                            --with-pdo-sqlite=${prefix} \
                            --enable-sqlite-utf8
}

subport ${php}-tidy {
    categories-append       www
    
    description             a PHP interface to tidy, the HTML cleaning and \
                            repair utility
    
    long_description        ${description}
    
    depends_lib-append      port:tidy
    
    configure.args-append   --with-tidy=${prefix}
}

subport ${php}-wddx {
    categories-append       textproc
    
    description             a PHP interface to Web Distributed Data Exchange
    
    long_description        ${description}
    
    depends_build-append    port:expat \
                            port:libxml2
    
    configure.args-append   --with-libexpat-dir=${prefix} \
                            --with-libxml-dir=${prefix}
}

subport ${php}-xmlrpc {
    categories-append       textproc
    
    description             a PHP extension for writing XML-RPC clients and servers
    
    long_description        ${description}
    
    depends_build-append    port:libiconv \
                            port:libxml2
    
    depends_lib-append      port:expat
    
    configure.args-append   --with-iconv-dir=${prefix} \
                            --with-libexpat-dir=${prefix} \
                            --with-libxml-dir=${prefix}
    
    pre-configure {
        configure.cppflags-append [exec ${prefix}/bin/xml2-config --cflags]
    }
}

subport ${php}-xsl {
    categories-append       textproc
    
    description             a PHP interface to libxslt, which implements the XSL \
                            standard and lets you perform XSL transformations
    
    long_description        ${description}
    
    depends_lib-append      port:libxslt
    
    configure.args-append   --with-xsl=${prefix}
    
    configure.cppflags-append   -I${prefix}/include/${php}/php/ext/dom
}

subport ${php}-zip {
    categories-append       archivers
    
    description             PHP zip functions
    
    long_description        ${description}
    
    depends_build-append    port:pcre
    
    depends_lib-append      port:zlib
}

}

# These variables are not only required by the subsequent code but also by
# preceding code in phase blocks.
set branch              ${subport_branch}
set php                 php[php.suffix_from_branch ${branch}]

# Set up the stub port.
if {${name} == ${subport}} {
    version             ${branch}
    supported_archs     noarch
    distfiles
    depends_run         port:${php}
    use_configure       no
    build {}
    destroot {
        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
        system "echo \"${name} is a stub port\" > ${destroot}${prefix}/share/doc/${subport}/README"
    }
}

# Set up the php portgroup, for extension subports.
if {[is_extension_subport]} {
    if {![info exists php.extensions]} {
        php.extensions ${php.rootname}
    }
    php.setup ${php.extensions} ${version}
    
    default homepage    http://www.php.net/${php.rootname}
    
    pre-extract {
        # Speed up extraction by extracting only the modules we're going to be building.
        foreach extension ${php.extensions} {
            extract.post_args-append ${worksrcdir}/ext/${extension}
        }
    }
    
    post-extract {
        # The PDO extensions need the PDO headers which are installed by the ${php} port.
        foreach extension ${php.extensions} {
            if {[regexp {^pdo_} ${extension}]} {
                file mkdir ${worksrcpath}/ext/${extension}/ext
                ln -s ${prefix}/include/${php}/php/ext/pdo ${worksrcpath}/ext/${extension}/ext
            }
        }
    }
    
    pre-configure {
        set php_version [exec ${php.config} --version 2>/dev/null]
        if {${version} != ${php_version}} {
            ui_error "${subport} @${version} requires ${php} @${version} but you have ${php} @${php_version}."
            return -code error "incompatible ${php} installation"
        }
    }
    
    destroot.target     install-modules install-headers
}
