# -*- 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
PortGroup               php 1.1
PortGroup               openssl 1.0

# Disable by default adding openssl support.
# Specific sub-ports below enable as required.
openssl.branch          no_version

name                    php
platforms               darwin freebsd
maintainers             {ryandesign @ryandesign}
license                 PHP-3.01
master_sites            https://www.php.net/distributions/
use_parallel_build      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.2 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.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} eq ${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} eq ${subport}} {
        return no
    }
    return [expr {![is_sapi_subport]}]
}

if {![is_extension_subport]} {
    categories          lang www
    homepage            https://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.2 {
        version         5.2.17
        master_sites    https://museum.php.net/php5/
        use_bzip2       yes
        set suhosin_available       yes
        set suhosin_patch_version   5.2.16-0.9.7
        set suhosin_patch           suhosin-patch-${suhosin_patch_version}.patch.gz
        checksums       ${distname}${extract.suffix} \
                        md5     b27947f3045220faf16e4d9158cbfe13 \
                        rmd160  567fa8d718b93fb83a89494c83a8bec224ac99e9 \
                        sha256  e81beb13ec242ab700e56f366e9da52fd6cf18961d155b23304ca870e53f116c \
                        size    9092312 \
                        ${suhosin_patch} \
                        rmd160  b28b70faf136b3e04c5b483da0f4c2279378f43a \
                        sha256  aae115a318d80b3f32cedf876e7a8e4b932febb1b0c743c0b398003ebe122f91 \
                        size    23069
    }
    5.3 {
        version         5.3.29
        use_bzip2       yes
        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       ${distname}${extract.suffix} \
                        md5     9469e240cbe6ac865aeaec89b253dd30 \
                        rmd160  e57beb4fdda41bca81b5856161bc97f3c5e3e9da \
                        sha256  c4e1cf6972b2a9c7f2777a18497d83bf713cdbecabb65d3ff62ba441aebb0091 \
                        size    11396771 \
                        ${suhosin_patch} \
                        rmd160  ce43921fd9b183b154713ecda98294f6c68d5f22 \
                        sha256  4438caeab0a10c6c94aee9f7eaa703f5799f97d4e0579f43a947bb7314e38317 \
                        size    40967
    }
    5.4 {
        epoch           1
        version         5.4.45
        use_bzip2       yes
        checksums       rmd160  352a0ea8fb75a447301c1434609ac0e4b96acc0c \
                        sha256  4e0d28b1554c95cfaea6fa2b64aac85433f158ce72bb571bcd5574f98f4c6582 \
                        size    12703324
    }
    5.5 {
        epoch           2
        version         5.5.38
        use_xz          yes
        checksums       rmd160  08d200f9458f37ffd69a2daf30436c5f25fc948f \
                        sha256  cb527c44b48343c8557fe2446464ff1d4695155a95601083e5d1f175df95580f \
                        size    11077780
    }
    5.6 {
        epoch           2
        version         5.6.40
        use_xz          yes
        checksums       rmd160  43b648cf24cdea59765a1d12c247f83f60af283f \
                        sha256  1369a51eee3995d7fbd1c5342e5cc917760e276d561595b6052b21ace2656d1c \
                        size    12472236
    }
    7.0 {
        epoch           2
        version         7.0.33
        use_xz          yes
        checksums       rmd160  621c2459c182de0a071f591eec45e4a3c32d8bdd \
                        sha256  ab8c5be6e32b1f8d032909dedaaaa4bbb1a209e519abb01a52ce3914f9a13d96 \
                        size    12033040
    }
    7.1 {
        epoch           2
        version         7.1.33
        use_xz          yes
        checksums       rmd160  378d66957d3488ce92c74745c4bc799b7b04105a \
                        sha256  bd7c0a9bd5433289ee01fd440af3715309faf583f75832b64fe169c100d52968 \
                        size    12370228
    }
    7.2 {
        epoch           2
        version         7.2.34
        use_xz          yes
        checksums       rmd160  52a993c201241e2dce521bad225f07330505b2cc \
                        sha256  409e11bc6a2c18707dfc44bc61c820ddfd81e17481470f3405ee7822d8379903 \
                        size    12309432
    }
    7.3 {
        epoch           2
        version         7.3.33
        use_xz          yes
        checksums       rmd160  b35e975ea04ab1a86a95d17a4f8048d295ab1475 \
                        sha256  166eaccde933381da9516a2b70ad0f447d7cec4b603d07b9a916032b215b90cc \
                        size    12143820
    }
    7.4 {
        epoch           2
        version         7.4.33
        use_xz          yes
        checksums       rmd160  60d30e6ae3e711d1cdc2623a9ca4354018194299 \
                        sha256  924846abf93bc613815c55dd3f5809377813ac62a9ec4eb3778675b82a27b927 \
                        size    10420144
    }
    8.0 {
        epoch           2
        version         8.0.30
        use_xz          yes
        checksums       rmd160  ef96103dc367a7ffbac94eb239fde4939ee83ddd \
                        sha256  216ab305737a5d392107112d618a755dc5df42058226f1670e9db90e77d777d9 \
                        size    10821076
    }
    8.1 {
        epoch           2
        version         8.1.30
        use_xz          yes
        checksums       rmd160  9a94a84bdcdd30957c39f8907eceb0d7ada0995a \
                        sha256  f24a6007f0b25a53cb7fbaee69c85017e0345b62089c2425a0afb7e177192ed1 \
                        size    11850340
    }
    8.2 {
        epoch           2
        version         8.2.24
        use_xz          yes
        checksums       rmd160  767162c5683a200cd1f994e301bcd9e5a32cc2c5 \
                        sha256  80a5225746a9eb484475b312d4c626c63a88a037d8e56d214f30205e1ba1411a \
                        size    12110000
    }
    8.3 {
        epoch           2
        version         8.3.12
        use_xz          yes
        checksums       rmd160  fd7d34f0528bcebd1ab33ff180bab40c4f2cd466 \
                        sha256  f774e28633e26fc8c5197f4dae58ec9e3ff87d1b4311cbc61ab05a7ad24bd131 \
                        size    12493432
    }
    8.4 {
        # When this becomes a stable version, remove the overrides for homepage,
        # master_sites and livecheck, and update php.latest_stable_branch in the
        # php-1.1 portgroup.
        epoch           1
        version         8.4.0RC1
        homepage        https://qa.php.net/
        master_sites    https://downloads.php.net/~saki/
        use_xz          yes
        checksums       rmd160  be0e3528c5e5551c06686f0c2fe42d57bc9ffe91 \
                        sha256  0b3db6af3e0643e310c9c32b407faf4be6fe265c0f37c5b2fed911d6e9ab046e \
                        size    13510864

        livecheck.url   ${homepage}
        livecheck.regex php-([strsed ${subport_branch} {g/\\./\\./}](?:\\.\[0-9.\]+)*(?:(?:alpha|beta|RC)\\d+|-latest))\\.tar
    }
}

# https://www.php.net/eol.php
set php.oldest_supported_branch 8.1

# 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}]} {

if {${major} > 5} {
    dist_subdir         ${php}
} else {
    dist_subdir         php${major}
}

configure.checks.implicit_function_declaration.whitelist-append strchr

if {[is_sapi_subport]} {

    platform darwin {
        if {[vercmp ${branch} < 7.0] && [vercmp ${xcodeversion} >= 12.0]} {
            # Implicit function declarations. Need to backport upstream fixes from php73+.
            # https://bugs.php.net/80176
            # https://trac.macports.org/ticket/60988
            known_fail          yes
            pre-fetch {
                ui_error "${subport} @${version} cannot currently be compiled with Xcode 12 or later"
                return -code error "incompatible Xcode version"
            }
        }
    }

    depends_build       path:bin/pkg-config:pkgconfig

    if {${subport} ne ${php}} {
        depends_lib     port:${php}
    }

    depends_lib-append  path:bin/gsed:gsed \
                        port:libiconv \
                        port:libxml2 \
                        port:bzip2 \
                        port:mhash \
                        port:zlib

    if {[vercmp ${branch} < 7.3]} {
        depends_lib-append  port:pcre
    } else {
        depends_lib-append  port:pcre2
    }

    # Use -p1 to accommodate the Suhosin patch
    patch.pre_args-replace  -p0 -p1
    patchfiles-append   patch-${php}-scripts-php-config.in.diff

    if {[vercmp ${branch} >= 8.2]} {
        patchfiles-append \
                        patch-${php}-atomic.diff
    } else {
        patchfiles-append \
                        patch-${php}-libxml2-2.12.diff
    }
    if {[vercmp ${branch} >= 8.0]} {
        if {[vercmp ${branch} < 8.2]} {
        patchfiles-append \
                        patch-${php}-conditional-Wno-implicit-fallthrough.diff
        }
        use_autoreconf  yes
        autoreconf.cmd  ./buildconf
        autoreconf.args --debug --force
        autoreconf.env  "PHP_AUTOCONF=${prefix}/bin/autoconf" \
                        "PHP_AUTOHEADER=${prefix}/bin/autoheader"
        depends_build-append \
                        port:autoconf \
                        port:libtool
    }
    if {[vercmp ${branch} < 7.4]} {
        patchfiles-append \
                        patch-${php}-libxml2-overlinking.diff
    }
    if {[vercmp ${branch} >= 7.0] && [vercmp ${branch} <= 7.2]} {
        patchfiles-append \
                        patch-${php}-implicit.diff
    }
    if {[vercmp ${branch} <= 5.3]} {
        patchfiles-append \
                        patch-${php}-configure.diff
    }
    if {[vercmp ${branch} <= 5.2]} {
        patchfiles-append \
                        patch-${php}-libxml2-2.9.diff \
                        patch-${php}-pcre-8.30.diff
    }
    if {[vercmp ${branch} >= 7.3] && [vercmp ${branch} < 8.5]} {
        patchfiles-append \
                        patch-${php}-zend_string_equal_val.diff
    }

    # https://trac.macports.org/ticket/31590
    # Tested all subports (except oracle) and they built with clang-425.  The reported failure was with Xcode 4.2.
    # Xcode 4.3 may work, but leaving it blacklisted due to lack of testing
    compiler.blacklist  {clang < 400}

    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-filter \
                        --enable-pdo \
                        --enable-session \
                        --enable-simplexml \
                        --enable-tokenizer \
                        --enable-xml \
                        --enable-xmlreader \
                        --enable-xmlwriter \
                        --with-bz2=${prefix} \
                        --with-mhash=${prefix} \
                        --with-zlib=${prefix} \
                        --disable-cgi \
                        --disable-cli

    if {[vercmp ${branch} < 8.0]} {
        # JSON support is always on as of PHP 8.
        # https://github.com/php/php-src/pull/5495
        configure.args-append   --enable-json
    }

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --enable-hash \
                                --enable-libxml \
                                --with-libxml-dir=${prefix} \
                                --with-pcre-regex=${prefix} \
                                --without-pear
    } else {
        configure.args-append   --with-libxml \
                                --with-external-pcre=${prefix}
    }

    # Ensure we don't regenerate the parsers even if flex/re2c/bison are installed.
    configure.env       LEX=true \
                        RE2C=true \
                        YACC=true

    if {[vercmp ${branch} == 7.3]} {
        # Regenerate datetime parsers with re2c < 0.16 to avoid
        # miscompilation by clang > 700.1.81 < 802.0.38 that results in
        # a runtime hang. See https://bugs.php.net/80376.
        depends_build-append \
                        port:re2c-0.15

        pre-configure {
            foreach parser {parse_date parse_iso_intervals} {
                # See https://github.com/derickr/timelib/blob/2018.04/Makefile#L32-L36
                system -W ${worksrcpath}/ext/date/lib "${prefix}/bin/re2c-0.15 -d -b ${parser}.re > ${parser}.c"
            }
        }
    }

    if {[vercmp ${branch} >= 5.3]} {
        configure.args-append \
                        --enable-fileinfo \
                        --enable-phar \
                        --disable-fpm

        # ${php}-mysql +mysqlnd needs mysqlnd support compiled into the SAPI
        configure.env-append \
                        PHP_MYSQLND_ENABLED=yes
    }

    if {[vercmp ${branch} == 5.4]} {
        # https://bugs.php.net/bug.php?id=68114
        configure.args-append ac_cv_decimal_fp_supported=no
    }

    if {[vercmp ${branch} >= 7.2]} {
        depends_lib-append \
                        port:argon2

        configure.args-append \
                        --with-password-argon2=${prefix} \
                        --without-valgrind
    }

    configure.universal_args-delete --disable-dependency-tracking

    test.run            yes

    destroot.destdir    INSTALL_ROOT=${destroot}

    variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {
        configure.args-append   --enable-debug
    }

    if {[vercmp ${branch} <= 5.3]} {
    variant suhosin description {Add Suhosin patch} {
        pre-fetch {
            if {${os.platform} eq "darwin" && ${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}} {
            if {[vercmp ${branch} >= 5.3]} {
                patchfiles-append   patch-${php}-suhosin-before.diff
            }
            patchfiles-append       ${suhosin_patch}
            if {[vercmp ${branch} >= 5.3]} {
                patchfiles-append   patch-${php}-suhosin-after.diff
            }
        }
    }
    }

    if {${subport} ne ${php}} {
        notes-append "If this is your first install, you need to enable ${subport} in your web server."
    }

}

}

### CLI SAPI ###

subport ${php} {
    PortGroup               muniversal 1.0
    PortGroup               select 1.0

    switch -- ${version} {
        5.2.17              {revision 18}
        5.3.29              {revision 9}
        5.4.45              {revision 8}
        5.5.38              {revision 9}
        5.6.40              {revision 7}
        7.0.33              {revision 7}
        7.1.33              {revision 5}
        7.2.34              {revision 6}
        7.3.33              {revision 4}
        7.4.33              {revision 2}
        8.0.30              {revision 1}
        8.1.30              {revision 1}
        8.2.24              {revision 1}
        8.3.12              {revision 1}
        8.4.0RC1            {revision 1}
    }

    depends_run             port:php_select

    select.group            php
    select.file             ${filespath}/${subport}

    if {[vercmp ${branch} == 5.3]} {
        patchfiles-append   patch-${php}-C++11.diff
    }

    if {[vercmp ${branch} >= 5.5] && [vercmp ${branch} < 7.0]} {
        patchfiles-append   patch-${php}-Zend-EX_TMP_VAR.diff
    }

    if {[vercmp ${branch} >= 5.3] && [vercmp ${branch} < 7.2]} {
        patchfiles-append   patch-${php}-icu-61.diff
    }

    if {[vercmp ${branch} < 7.4]} {
        patchfiles-append   dynamic_lookup-11.patch
    }

    if {[vercmp ${branch} >= 7.0] && [vercmp ${branch} < 7.4]} {
        patchfiles-append   patch-${php}-icu-71.diff
    }

    if {[vercmp ${branch} < 8.0]} {
    post-patch {
        # Ensure the build date is the same for all universal archs.
        reinplace "s|^PHP_BUILD_DATE=.*$|PHP_BUILD_DATE=[clock format [clock seconds] -format {%Y-%m-%d}]|g" ${worksrcpath}/configure
    }
    }

    configure.args-replace  --disable-cli --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}
        if {[vercmp ${branch} >= 5.3]} {
            xinstall -m 644 -W ${worksrcpath} \
                php.ini-development \
                php.ini-production \
                ${destroot}${phpinidir}
        } else {
            xinstall -m 644 -W ${worksrcpath} \
                php.ini-dist \
                php.ini-recommended \
                ${destroot}${phpinidir}
        }

        if {[vercmp ${branch} >= 5.3]} {
            # Copy mysqlnd headers.
            xinstall -d ${destroot}${prefix}/include/${php}/php/ext/mysqlnd
            xinstall -m 644 {*}[glob ${worksrcpath}/ext/mysqlnd/*.h] ${destroot}${prefix}/include/${php}/php/ext/mysqlnd
        }

        # Verify the executable works.
        system -W ${destroot}${prefix}/bin "./${php} -n -v"
    }

    # Include the readline extension https://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() (https://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 port:ncurses
        if {[vercmp ${branch} < 7.4]} {
            configure.args-append   --with-libedit=${prefix}
        } else {
            configure.args-append   --with-libedit
        }
    }
    variant readline conflicts libedit description {Build readline extension using readline library} {
        depends_lib-append      port:ncurses port:readline
        configure.args-append   --with-readline=${prefix}
    }
    if {![variant_isset readline]} {
        default_variants +libedit
    }

    if {[vercmp ${branch} < ${php.oldest_supported_branch}]} {
        notes-append "
PHP ${branch} has reached end-of-life. Please upgrade to PHP ${php.oldest_supported_branch} or newer. The newest stable version is ${php.latest_stable_branch}.

To learn how to update your code, please read the following guide:

    https://www.php.net/manual/en/migration[php.suffix_from_branch ${php.latest_stable_branch}].php


"
    }

    if {[vercmp ${branch} > ${php.latest_stable_branch}]} {
        notes-append "${php} @${version} is a development preview—do not use it in production!\n\n\n"
    }

    if {![file exists ${phpinidir}/php.ini]} {
        if {[vercmp ${branch} >= 5.3]} {
            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 "
To customize ${php}, copy ${phpinidir}/php.ini-recommended to\
${phpinidir}/php.ini and then make changes.
"
        }
    } else {
        if {[vercmp ${branch} >= 5.3]} {
            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).
"
        } 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-recommended.
"
        }
    }

    # Enable livecheck for all supported PHP branches and the development branch.
    if {[vercmp ${branch} >= ${php.oldest_supported_branch}]} {
        livecheck.type      regex
        default livecheck.url   ${homepage}/downloads.php
        default livecheck.regex {[quotemeta /php-([quotemeta ${branch}](?:\\.\[0-9.\]+)*)\\.tar]}
    }
}

### Apache 2 handler SAPI ###

subport ${php}-apache2handler {
    PortGroup               active_variants 1.1

    switch -- ${version} {
        5.2.17              {revision 4}
        5.3.29              {revision 4}
        5.4.45              {revision 4}
        5.5.38              {revision 4}
        5.6.40              {revision 2}
        7.0.33              {revision 2}
        7.1.33              {revision 2}
        7.2.34              {revision 3}
        7.3.33              {revision 2}
        7.4.33              {revision 1}
        8.0.30              {revision 1}
        8.1.30              {revision 1}
        8.2.24              {revision 1}
        8.3.12              {revision 1}
        8.4.0RC1            {revision 1}
    }

    description             ${php} Apache 2 Handler SAPI

    long_description        ${description}

    homepage                https://www.php.net/install.unix.apache2

    depends_lib-append      port:apache2

    require_active_variants apache2 preforkmpm

    set apxs ${prefix}/bin/apxs
    set confdir ${prefix}/etc/apache2
    set moduledir ${prefix}/lib/apache2/modules

    configure.args-append   --with-apxs2=${apxs}

    if {[vercmp ${branch} < 8.0]} {
        set bundle_major    ${major}
    } else {
        set bundle_major    {}
    }

    build.target            libs/libphp${bundle_major}.bundle

    if {[vercmp ${branch} < 5.3]} {
        patchfiles-append   patch-${php}-apache24.diff
    }

    destroot {
        xinstall -m 755 -d ${destroot}${moduledir} ${destroot}${confdir}/extra
        xinstall -m 644 ${worksrcpath}/libs/libphp${bundle_major}.so ${destroot}${moduledir}/mod_${php}.so
        xinstall -m 644 ${filespath}/mod_php.conf.in ${destroot}${confdir}/extra/mod_${php}.conf
        reinplace s/@MAJOR@/${bundle_major}/g ${destroot}${confdir}/extra/mod_${php}.conf
    }

    notes-append "

To enable ${subport}, run:

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

### CGI SAPI ###

subport ${php}-cgi {
    switch -- ${version} {
        5.2.17              {revision 1}
        5.3.29              {revision 1}
        5.4.45              {revision 1}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 3}
        7.3.33              {revision 2}
        7.4.33              {revision 1}
        8.0.30              {revision 1}
        8.1.30              {revision 1}
        8.2.24              {revision 1}
        8.3.12              {revision 1}
        8.4.0RC1            {revision 1}
    }

    description             ${php} CGI SAPI

    long_description        ${description}

    homepage                https://www.php.net/install.unix.commandline

    configure.args-delete   --disable-cgi
    if {[vercmp ${branch} >= 5.3]} {
        configure.args-append --enable-cgi
    } else {
        configure.args-append --enable-fastcgi --enable-force-cgi-redirect
    }

    if {[vercmp ${branch} >= 5.4]} {
        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 ###

if {[vercmp ${branch} >= 5.3]} {
subport ${php}-fpm {
    switch -- ${version} {
        5.3.29              {revision 2}
        5.4.45              {revision 2}
        5.5.38              {revision 2}
        5.6.40              {revision 2}
        7.0.33              {revision 2}
        7.1.33              {revision 2}
        7.2.34              {revision 3}
        7.3.33              {revision 2}
        7.4.33              {revision 1}
        8.0.30              {revision 1}
        8.1.30              {revision 1}
        8.2.24              {revision 1}
        8.3.12              {revision 1}
        8.4.0RC1            {revision 1}
    }

    description             ${php} FPM SAPI

    long_description        ${description}

    homepage                https://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-replace  --disable-fpm --enable-fpm
    configure.args-append   --datadir=${prefix}/share/examples/${php} \
                            --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 {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    description             a PHP extension for converting between different \
                            calendar formats

    long_description        ${description}
}

subport ${php}-curl {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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

    if {[vercmp ${branch} < 7.4]} {
        if {[vercmp ${branch} >= 7.0] && [vercmp ${branch} <= 7.1]} {
            patchfiles-append \
                                patch-${php}-ext-curl-config.m4.diff
        }
        configure.args-append   --with-curl=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-curl
    }
}

subport ${php}-dba {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

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

if {[vercmp ${branch} >= 5.3]} {
subport ${php}-enchant {
    switch -- ${version} {
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 1}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       textproc devel

    description             a PHP interface to enchant

    long_description        ${name} is ${description}, a common API for many spell libraries.

    if {[vercmp ${branch} >= 8.0]} {
        depends_lib-append  port:enchant2

        extract.post_args-append ${worksrcdir}/ext/spl
    } else {
        depends_lib-append  port:enchant
    }

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-enchant=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-enchant
    }

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 644 -W ${destroot.dir} CREDITS ${destroot}${docdir}

        if {[vercmp ${branch} < 7.3]} {
        set examplesdir ${prefix}/share/examples/${subport}
        xinstall -d ${destroot}${examplesdir}
        xinstall -m 644 ${destroot.dir}/docs/examples/example1.php \
            ${destroot}${examplesdir}
        }
    }
}
}

subport ${php}-exif {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       graphics

    description             a PHP interface to the EXIF image metadata functions

    long_description        ${description}
}

if {[vercmp ${branch} >= 7.4]} {
subport ${php}-ffi {
    switch -- ${version} {
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       devel

    description             a PHP interface to allow loading of shared libraries

    long_description        ${description}

    depends_build-append    path:bin/pkg-config:pkgconfig

    depends_lib-append      port:libffi

    configure.args-append   --with-ffi
}
}

subport ${php}-ftp {
    switch -- ${version} {
        5.2.17              {revision 3}
        5.3.29              {revision 3}
        5.4.45              {revision 3}
        5.5.38              {revision 3}
        5.6.40              {revision 3}
        7.0.33              {revision 2}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       net

    description             a PHP extension for accessing file servers using the \
                            File Transfer Protocol

    long_description        {*}${description}

    if {[vercmp ${branch} >= 7.4]} {
        depends_build-append \
                            path:bin/pkg-config:pkgconfig
    }

    if {[vercmp ${branch} < 7.0]} {
        patchfiles-append   patch-${php}-ext-ftp-ftp_ssl_connect.diff
    }

    openssl.branch          3
    configure.args-append   --with-openssl-dir=[openssl::install_area]
}

subport ${php}-gd {
    switch -- ${version} {
        5.2.17              {revision 1}
        5.3.29              {revision 1}
        5.4.45              {revision 1}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       graphics

    description             a PHP interface to the gd library

    long_description        ${description}

    depends_lib-append      port:freetype \
                            path:include/turbojpeg.h:libjpeg-turbo \
                            port:libpng \
                            port:zlib

    if {[vercmp ${branch} <= 5.2]} {
        patchfiles-append   patch-${php}-jpeg-9.diff
    }

    if {[vercmp ${branch} < 5.5]} {
        # This flag was removed in PHP 7.2.0 and does nothing in PHP >= 5.5.0.
        # https://github.com/php/php-src/commit/494c5dc77ae92d21db915abada2ecefaca620543
        configure.args-append   --enable-gd-native-ttf
    }

    if {[vercmp ${branch} >= 7.0]} {
        depends_lib-append  port:webp
    }

    if {[vercmp ${branch} == 8.1]} {
        patchfiles-append       patch-${php}-ext-gd.diff
    }

    if {[vercmp ${branch} < 7.4]} {
        patchfiles-append       patch-${php}-ext-gd-config.m4.diff

        configure.args-append   --with-freetype-dir=${prefix} \
                                --with-jpeg-dir=${prefix} \
                                --with-png-dir=${prefix} \
                                --with-zlib-dir=${prefix}

        if {[vercmp ${branch} >= 7.0]} {
            configure.args-append --with-webp-dir=${prefix}
        }
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-freetype \
                                --with-jpeg \
                                --with-webp
    }

    if {[vercmp ${branch} < 7.0]} {
    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 {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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 {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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

    if {[vercmp ${branch} <= 5.2]} {
        patchfiles-append   patch-${php}-ext-gmp-gmp.c.diff
    }

    configure.args-append   --with-gmp=${prefix}
}

subport ${php}-iconv {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

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

if {[vercmp ${branch} < 8.4]} {
subport ${php}-imap {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       mail

    description             a PHP interface to the IMAP protocol

    long_description        ${description}

    depends_build-append    port:cclient

    depends_lib-append      port:kerberos5 \
                            port:libcomerr

    configure.args-append   --with-imap=${prefix} \
                            --with-imap-ssl=${prefix} \
                            --with-kerberos=${prefix}

    if {[vercmp ${branch} >= 7.4]} {
        depends_build-append    path:bin/pkg-config:pkgconfig

        # https://bugs.php.net/bug.php?id=79112
        configure.env-append    PHP_OPENSSL=yes
    }
}
}

if {[vercmp ${branch} >= 5.3]} {
subport ${php}-intl {
    switch -- ${version} {
        5.3.29              {revision 10}
        5.4.45              {revision 8}
        5.5.38              {revision 8}
        5.6.40              {revision 7}
        7.0.33              {revision 7}
        7.1.33              {revision 6}
        7.2.34              {revision 5}
        7.3.33              {revision 5}
        7.4.33              {revision 3}
        8.0.30              {revision 2}
        8.1.30              {revision 1}
        8.2.24              {revision 1}
        8.3.12              {revision 1}
        8.4.0RC1            {revision 1}
    }

    categories-append       devel

    description             internationalization extension for PHP

    long_description        Internationalization extension implements ICU \
                            library functionality in PHP.

    depends_build-append    path:bin/pkg-config:pkgconfig

    depends_lib-append      path:lib/pkgconfig/icu-uc.pc:icu

    if {[vercmp ${branch} >= 5.3] && [vercmp ${branch} < 7.0]} {
        patchfiles-append   patch-${php}-ext-intl-icu-68.diff
    }

    if {[vercmp ${branch} >= 5.5] && [vercmp ${branch} < 7.4]} {
        patchfiles-append   patch-${php}-ext-intl-icu-71.diff
    }

    if {[vercmp ${branch} >= 7.0] && [vercmp ${branch} < 7.3]} {
        patchfiles-append   patch-${php}-ext-intl-icu-56.diff
    }

    if {[vercmp ${branch} >= 7.0] && [vercmp ${branch} < 8.0]} {
        patchfiles-append   patch-${php}-ext-intl-icu-68.diff
    }

    if {[vercmp ${branch} < 7.1]} {
        patchfiles-append   patch-${php}-ext-intl-config.m4.diff
    }

    # icu >= 75 requires C++17
    compiler.cxx_standard   2017

    if {[vercmp ${branch} < 8.2]} {
    post-patch {
        reinplace "s|PHP_CXX_COMPILE_STDCXX(11,|PHP_CXX_COMPILE_STDCXX(17,|" \
            ${worksrcpath}/ext/intl/config.m4
    }
    }

    platform darwin {
        if {(${os.major} == 10 || ${os.major} == 11) && [vercmp ${branch} >= 7.1] && [vercmp ${branch} < 7.4]} {
            # Need to investigate how this was fixed for php 7.4 and
            # possibly backport the fix.
            # https://bugs.php.net/bug.php?id=76826
            known_fail          yes
        }
    }
}
}

subport ${php}-ipc {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    php.extensions          shmop sysvmsg sysvsem sysvshm

    description             interprocess communication extensions for PHP

    long_description        PHP extensions for interprocess communication (IPC), including the \
                            shmop, sysvmsg, sysvsem, and sysvshm extensions.
}

subport ${php}-ldap {
    switch -- ${version} {
        5.2.17              {revision 1}
        5.3.29              {revision 1}
        5.4.45              {revision 1}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 1}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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      path:lib/libldap.dylib:openldap \
                            port:cyrus-sasl2

    configure.args-append   --with-ldap=${prefix}

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-ldap-sasl=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-ldap-sasl
    }
}

subport ${php}-mbstring {
    switch -- ${version} {
        5.2.17              {revision 1}
        5.3.29              {revision 1}
        5.4.45              {revision 1}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 1}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       textproc

    description             a PHP extension for manipulating strings in multibyte \
                            encodings

    long_description        ${description}

    if {[vercmp ${branch} >= 7.4]} {
        depends_build-append    path:bin/pkg-config:pkgconfig

        depends_lib-append      port:oniguruma6
    } else {
        configure.cppflags-replace -I${prefix}/include -isystem${prefix}/include
    }
}

if {[vercmp ${branch} < 7.2]} {
# mcrypt was evicted from PHP core in version 7.2; php72-mcrypt and later
# subports are found in the separate php-mcrypt Portfile.
subport ${php}-mcrypt {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
    }

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

if {[vercmp ${branch} < 7.0]} {
subport ${php}-mssql {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
    }

    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 {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    php.extensions          mysqli pdo_mysql
    if {[vercmp ${branch} < 7.0]} {
        php.extensions-prepend mysql
    }

    categories-append       databases

    description             a PHP interface to MySQL databases, including the
    if {[vercmp ${branch} < 7.0]} {
        description-append  mysql,
    }
    description-append      mysqli and pdo_mysql extensions

    long_description        ${description}

    depends_lib-append      port:zlib

    configure.args-append   --with-zlib-dir=${prefix}

    if {[vercmp ${branch} >= 5.3]} {
    variant mysqlnd conflicts mysql51 mysql55 mysql56 mariadb percona description {Use MySQL Native Driver} {
        configure.args-append   --with-pdo-mysql=mysqlnd

        if {[vercmp ${branch} < 7.0]} {
            configure.args-append   --with-mysql=mysqlnd
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=mysqlnd
        } else {
            configure.args-append   --with-mysqli
        }

        configure.cppflags-append   -I${worksrcpath}

        set phpini ${prefix}/etc/${php}/php.ini
        notes "
To use mysqlnd with a local MySQL server, edit ${phpini} and set\
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket\
to the path to your MySQL server's socket file.

For mysql51, use ${prefix}/var/run/mysql51/mysqld.sock
For mysql55, use ${prefix}/var/run/mysql55/mysqld.sock
For mysql56, use ${prefix}/var/run/mysql56/mysqld.sock
For mysql57, use ${prefix}/var/run/mysql57/mysqld.sock
For mysql8, use ${prefix}/var/run/mysql8/mysqld.sock
For mariadb, use ${prefix}/var/run/mariadb/mysqld.sock
For percona, use ${prefix}/var/run/percona/mysqld.sock
"
    }
    }

    variant mysql51 conflicts mysqlnd mysql55 mysql56 mysql57 mysql8 mariadb percona description {Use MySQL 5.1 libraries} {
        depends_lib-append      port:mysql51

        configure.args-append   --with-mysql-sock=${prefix}/var/run/mysql51/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/mysql51/bin/mysql_config

        if {[vercmp ${branch} < 7.0]} {
            post-extract {
                file mkdir ${workpath}/mysql51
                file link -symbolic ${workpath}/mysql51/lib ${prefix}/lib/mysql51
                file link -symbolic ${workpath}/mysql51/include ${prefix}/include/mysql51
            }

            configure.args-append   --with-mysql=${workpath}/mysql51
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/mysql51/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }

    variant mysql55 conflicts mysqlnd mysql51 mysql56 mysql57 mysql8 mariadb percona description {Use MySQL 5.5 libraries} {
        depends_lib-append      port:mysql55

        configure.args-append   --with-mysql-sock=${prefix}/var/run/mysql55/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/mysql55/bin/mysql_config

        if {[vercmp ${branch} < 7.0]} {
            post-extract {
                file mkdir ${workpath}/mysql55
                file link -symbolic ${workpath}/mysql55/lib ${prefix}/lib/mysql55
                file link -symbolic ${workpath}/mysql55/include ${prefix}/include/mysql55
            }

            configure.args-append   --with-mysql=${workpath}/mysql55
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/mysql55/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }

    variant mysql56 conflicts mysqlnd mysql51 mysql55 mysql57 mysql8 mariadb percona description {Use MySQL 5.6 libraries} {
        depends_lib-append      port:mysql56

        configure.args-append   --with-mysql-sock=${prefix}/var/run/mysql56/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/mysql56/bin/mysql_config

        if {[vercmp ${branch} < 7.0]} {
            post-extract {
                file mkdir ${workpath}/mysql56
                file link -symbolic ${workpath}/mysql56/lib ${prefix}/lib/mysql56
                file link -symbolic ${workpath}/mysql56/include ${prefix}/include/mysql56
            }

            configure.args-append   --with-mysql=${workpath}/mysql56
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/mysql56/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }

    variant mysql57 conflicts mysqlnd mysql51 mysql55 mysql56 mysql8 mariadb percona description {Use MySQL 5.7 libraries} {
        depends_lib-append      port:mysql57

        configure.args-append   --with-mysql-sock=${prefix}/var/run/mysql57/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/mysql57/bin/mysql_config

        if {[vercmp ${branch} < 7.0]} {
            post-extract {
                file mkdir ${workpath}/mysql57
                file link -symbolic ${workpath}/mysql57/lib ${prefix}/lib/mysql57
                file link -symbolic ${workpath}/mysql57/include ${prefix}/include/mysql57
            }

            configure.args-append   --with-mysql=${workpath}/mysql57
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/mysql57/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }

    if {[vercmp ${branch} >= 7.3]} {
    variant mysql8 conflicts mysqlnd mysql51 mysql55 mysql56 mysql57 mariadb percona description {Use MySQL 8 libraries} {
        depends_lib-append      port:mysql8

        configure.args-append   --with-mysql-sock=${prefix}/var/run/mysql8/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/mysql8/bin/mysql_config

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/mysql8/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }
    }

    variant mariadb conflicts mysqlnd mysql51 mysql55 mysql56 mysql57 mysql8 percona description {Use MariaDB libraries} {
        depends_lib-append      port:mariadb

        configure.args-append   --with-mysql-sock=${prefix}/var/run/mariadb/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/mariadb/bin/mysql_config

        if {[vercmp ${branch} < 7.0]} {
            post-extract {
                file mkdir ${workpath}/mariadb
                file link -symbolic ${workpath}/mariadb/lib ${prefix}/lib/mariadb
                file link -symbolic ${workpath}/mariadb/include ${prefix}/include/mariadb
            }

            configure.args-append   --with-mysql=${workpath}/mariadb
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/mariadb/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }

    variant percona conflicts mysqlnd mysql51 mysql55 mysql56 mysql57 mysql8 mariadb description {Use Percona libraries} {
        depends_lib-append      port:percona

        configure.args-append   --with-mysql-sock=${prefix}/var/run/percona/mysqld.sock \
                                --with-pdo-mysql=${prefix}/lib/percona/bin/mysql_config

        if {[vercmp ${branch} < 7.0]} {
            post-extract {
                file mkdir ${workpath}/percona
                file link -symbolic ${workpath}/percona/lib ${prefix}/lib/percona
                file link -symbolic ${workpath}/percona/include ${prefix}/include/percona
            }

            configure.args-append   --with-mysql=${workpath}/percona
        }

        if {[vercmp ${branch} < 8.2]} {
            configure.args-append   --with-mysqli=${prefix}/lib/percona/bin/mysql_config
        } else {
            configure.args-append   --with-mysqli
        }
    }

    if {![variant_isset mysql51] && ![variant_isset mysql55] && ![variant_isset mysql56] && ![variant_isset mysql57] && ![variant_isset mysql8] && ![variant_isset mariadb] && ![variant_isset percona]} {
        if {[vercmp ${branch} < 5.3]} {
            default_variants +mariadb
        } else {
            default_variants +mysqlnd
        }
    }
}

subport ${php}-odbc {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    php.extensions          odbc pdo_odbc

    categories-append       databases

    description             a PHP interface for accessing databases via Open \
                            DataBase Connectivity (ODBC)

    long_description        ${description}

    if {[vercmp ${branch} >= 5.3]} {
    variant iodbc conflicts unixodbc description {Use iODBC} {
        depends_lib-append      port:libiodbc

        patchfiles-append       patch-${php}-iODBC.diff

        configure.args-append   --with-pdo-odbc=iODBC,${prefix}
        if {[vercmp ${branch} < 7.4]} {
            configure.args-append   --with-iODBC=${prefix}
        } else {
            depends_build-append    path:bin/pkg-config:pkgconfig

            configure.args-append   --with-iODBC
        }
    }

    variant unixodbc conflicts iodbc description {Use unixODBC} {}

    if {![variant_isset iodbc] && ![variant_isset unixodbc]} {
        default_variants +unixodbc
    }
    }

    if {[variant_isset unixodbc] || [vercmp ${branch} < 5.3]} {
        depends_lib-append      port:unixODBC

        patchfiles-append       patch-${php}-unixODBC.diff

        configure.args-append   --with-pdo-odbc=unixODBC,${prefix}
        if {[vercmp ${branch} < 7.4]} {
            configure.args-append   --with-unixODBC=${prefix}
        } else {
            depends_build-append    path:bin/pkg-config:pkgconfig

            configure.args-append   --with-unixODBC
        }
    }
}

if {[vercmp ${branch} >= 5.5]} {
    subport ${php}-opcache {
        switch -- ${version} {
            5.5.38              {revision 1}
            5.6.40              {revision 1}
            7.0.33              {revision 2}
            7.1.33              {revision 2}
            7.2.34              {revision 1}
            7.3.33              {revision 1}
            7.4.33              {revision 0}
            8.0.30              {revision 0}
            8.1.30              {revision 0}
            8.2.24              {revision 0}
            8.3.12              {revision 0}
            8.4.0RC1            {revision 0}
        }

        php.extensions.zend opcache

        description         OPcache improves PHP performance by storing precompiled \
                            script bytecode in shared memory, thereby removing the \
                            need for PHP to load and parse scripts on each request.

        long_description    ${description}

        configure.args-append   --enable-opcache

        # File-based opcode cache was added in 7.0 (3abde432) and can no longer
        # be disabled as of 7.4 (c32da66e).
        if {[vercmp ${branch} >= 7.0] && [vercmp ${branch} < 7.4]} {
            # Chained fixups cause this error at runtime on Ventura:
            # symbol not found in flat namespace '_zend_file_cache_invalidate'
            if {[vercmp ${macosx_deployment_target} >= 11]} {
                configure.ldflags-append -Wl,-no_fixup_chains
            }

            configure.args-append   --enable-opcache-file
        }

        if {[vercmp ${branch} >= 8.0]} {
            PortGroup       legacysupport 1.1
            # clock_gettime
            legacysupport.newest_darwin_requires_legacy 15
        }

        if {[vercmp ${branch} == 8.1]} {
            patchfiles-append patch-${php}-opcache.diff
        }

        post-destroot {
            set docdir ${destroot}${prefix}/share/doc/${subport}
            xinstall -d ${docdir}
            if {[vercmp ${branch} < 7.4]} {
                xinstall -W ${destroot.dir} -m 644 README ${docdir}
            }
        }
    }
}

subport ${php}-openssl {
    switch -- ${version} {
        5.2.17              {revision 3}
        5.3.29              {revision 3}
        5.4.45              {revision 3}
        5.5.38              {revision 3}
        5.6.40              {revision 3}
        7.0.33              {revision 2}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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:kerberos5 \
                            port:libcomerr

    post-extract {
        move ${php.build_dirs}/config0.m4 ${php.build_dirs}/config.m4
    }

    configure.args-append   --with-kerberos=${prefix}

    # Look in OpenSSL directories before the main include directory.
    configure.cppflags-replace -I${prefix}/include -isystem${prefix}/include

    if {[vercmp ${branch} <= 5.6]} {
        openssl.branch          1.0
    } elseif {[vercmp ${branch} <= 8.0]} {
        openssl.branch          1.1
    } else {
        openssl.branch          3
    }

    if {[vercmp ${branch} <= 5.6]} {
        configure.args-append   --with-openssl=shared
    } elseif {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-openssl=[openssl::install_area]
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-openssl
    }
}

if {[vercmp ${branch} < 8.4]} {
subport ${php}-oracle {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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

    if {[vercmp ${branch} <= 5.2]} {
        patchfiles-append   patch-${php}-ext-pdo_oci-config.m4.diff
    }

    set lib_dir             ${prefix}/lib/oracle
    pre-configure {
        regexp {\.dylib\.(.+)$} [glob -directory ${lib_dir} libclntsh.dylib.*] -> library_version
        configure.args-append \
                            --with-oci8=instantclient,${lib_dir} \
                            --with-pdo-oci=instantclient,${lib_dir},${library_version}
    }
}
}

subport ${php}-pcntl {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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 {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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 {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    php.extensions          pgsql pdo_pgsql

    categories-append       databases

    homepage                https://www.php.net/pgsql

    description             a PHP interface to PostgreSQL, including \
                            the pgsql and pdo_pgsql extensions

    long_description        ${description}

    variant postgresql13 conflicts postgresql14 postgresql15 postgresql16 description {Use PostgreSQL 13 libraries} {
        depends_lib-append      port:postgresql13

        configure.args-append   --with-pgsql=${prefix}/lib/postgresql13/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql13/bin
    }

    variant postgresql14 conflicts postgresql13 postgresql15 postgresql16 description {Use PostgreSQL 14 libraries} {
        depends_lib-append      port:postgresql14

        configure.args-append   --with-pgsql=${prefix}/lib/postgresql14/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql14/bin
    }

    variant postgresql15 conflicts postgresql13 postgresql14 postgresql16 description {Use PostgreSQL 15 libraries} {
        depends_lib-append      port:postgresql15

        configure.args-append   --with-pgsql=${prefix}/lib/postgresql15/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql15/bin
    }

    variant postgresql16 conflicts postgresql13 postgresql14 postgresql15 description {Use PostgreSQL 16 libraries} {
        depends_lib-append      port:postgresql16

        configure.args-append   --with-pgsql=${prefix}/lib/postgresql16/bin \
                                --with-pdo-pgsql=${prefix}/lib/postgresql16/bin
    }

    if {![variant_isset postgresql13] && ![variant_isset postgresql14] && ![variant_isset postgresql15] && ![variant_isset postgresql16]} {
        default_variants +postgresql16
    }
}

if {[vercmp ${branch} < 8.4]} {
subport ${php}-pspell {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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 {
    switch -- ${version} {
        5.2.17              {revision 2}
        5.3.29              {revision 2}
        5.4.45              {revision 2}
        5.5.38              {revision 2}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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 {
    switch -- ${version} {
        5.2.17              {revision 1}
        5.3.29              {revision 1}
        5.4.45              {revision 1}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 1}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       net

    description             a PHP extension for writing SOAP clients and servers

    long_description        ${description}

    depends_lib-append      port:libxml2

    if {[vercmp ${branch} < 8.2]} {
        patchfiles-append \
                        patch-${php}-ext-soap.diff
    }

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-libxml-dir=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig
    }
}

subport ${php}-sockets {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       net

    description             a PHP interface to BSD socket communication \
                            functions

    long_description        ${description}
}

if {[vercmp ${branch} >= 7.2]} {
subport ${php}-sodium {
    switch -- ${version} {
        7.2.34              {revision 1}
        7.3.33              {revision 1}
        7.4.33              {revision 1}
        8.0.30              {revision 1}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    php.extensions          sodium

    categories-append       security

    description             a PHP interface to libsodium, a modern and \
                            easy-to-use crypto library

    long_description        ${description}

    depends_lib-append      port:libsodium

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-sodium=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-sodium
    }
}
}

if {[vercmp ${branch} >= 5.3]} {
subport ${php}-sqlite {
    switch -- ${version} {
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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]} {
        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   --enable-sqlite-utf8

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-sqlite3=${prefix} \
                                --with-pdo-sqlite=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-sqlite3 \
                                --with-pdo-sqlite
    }
}
}

subport ${php}-tidy {
    switch -- ${version} {
        5.2.17              {revision 3}
        5.3.29              {revision 3}
        5.4.45              {revision 2}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    categories-append       www

    description             a PHP interface to tidy, the HTML cleaning and \
                            repair utility

    long_description        ${description}

    depends_lib-append      port:tidy

    if {[vercmp ${branch} <= 7.0]} {
        patchfiles-append   patch-${php}-ext-tidy-tidy.c.diff
    }

    configure.args-append   --with-tidy=${prefix}
}

if {[vercmp ${branch} < 7.4]} {
subport ${php}-wddx {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
    }

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

if {[vercmp ${branch} < 8.0]} {
subport ${php}-xmlrpc {
    switch -- ${version} {
        5.2.17              {revision 0}
        5.3.29              {revision 0}
        5.4.45              {revision 0}
        5.5.38              {revision 0}
        5.6.40              {revision 0}
        7.0.33              {revision 0}
        7.1.33              {revision 0}
        7.2.34              {revision 0}
        7.3.33              {revision 0}
        7.4.33              {revision 0}
    }

    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}

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-libexpat-dir=${prefix} \
                                --with-libxml-dir=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-expat
    }

    pre-configure {
        configure.cppflags-append [exec ${prefix}/bin/xml2-config --cflags]
    }
}
}

subport ${php}-xsl {
    switch -- ${version} {
        5.2.17              {revision 1}
        5.3.29              {revision 1}
        5.4.45              {revision 1}
        5.5.38              {revision 1}
        5.6.40              {revision 1}
        7.0.33              {revision 1}
        7.1.33              {revision 1}
        7.2.34              {revision 1}
        7.3.33              {revision 1}
        7.4.33              {revision 0}
        8.0.30              {revision 0}
        8.1.30              {revision 0}
        8.2.24              {revision 0}
        8.3.12              {revision 0}
        8.4.0RC1            {revision 0}
    }

    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

    if {[vercmp ${branch} < 7.4]} {
        configure.args-append   --with-xsl=${prefix}
    } else {
        depends_build-append    path:bin/pkg-config:pkgconfig

        configure.args-append   --with-xsl
    }

    configure.cppflags-append   -I${prefix}/include/${php}/php/ext/dom
}

}

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

if {${name} eq ${subport}} {
    PortGroup           stub 1.0

    version             ${branch}
    revision            0
    supported_archs     noarch
    platforms           any
    depends_run         port:${php}
} else {
    # Set an explicit distname so the default from the php portgroup doesn't get used.
    distname            ${name}-${version}
}

proc get_default_php_extensions {} {
    global php.extensions.zend php.rootname
    if {0 < [llength ${php.extensions.zend}]} {
        return
    }
    return ${php.rootname}
}

# Set up the php portgroup, for extension subports.
if {[is_extension_subport]} {
    default php.extensions {[get_default_php_extensions]}
    default homepage    https://www.php.net/${php.rootname}

    php.build_dirs
    set pdo no
    foreach extension [concat ${php.extensions} ${php.extensions.zend}] {
        if {[regexp {^pdo_} ${extension}]} {
            # The PDO extensions need the PDO headers.
            set pdo yes
            post-extract {
                file mkdir ${worksrcpath}/ext/${extension}/ext
                ln -s ${worksrcpath}/ext/pdo ${worksrcpath}/ext/${extension}/ext
            }
        }

        # Speed up extraction by extracting only the modules we're going to be building.
        extract.post_args-append ${worksrcdir}/ext/${extension}

        # Run phpize, configure, build and destroot in each extension's directory.
        php.build_dirs-append ${worksrcpath}/ext/${extension}
    }

    if {${pdo}} {
        # The PDO extensions need the PDO headers.
        extract.post_args-append ${worksrcdir}/ext/pdo
    }

    pre-configure {
        set php_version [exec ${php.config} --version 2>/dev/null]
        if {${version} ne ${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

    php.add_port_code
}
