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

name                    php-mysql_xdevapi
categories-append       databases
platforms               darwin freebsd openbsd
maintainers             {ryandesign @ryandesign} openmaintainer
license                 PHP-3.01

homepage                https://dev.mysql.com/doc/x-devapi-userguide/en/

php.branches            7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3
php.pecl                yes

if {[vercmp ${php.branch} >= 7.1]} {
    if {${os.platform} ne "darwin" || ${os.major} >= 17} {
        version         8.0.30
        revision        2
        checksums       rmd160  a227c5fe61cb4c40542fad86eb80844503c7ab8f \
                        sha256  4a1f7ac8fc59579194548365d3fcc380372749e9cc50895d8e065ea7f4717cfd \
                        size    587966
    } else {
        version         8.0.21
        revision        5
        checksums       rmd160  800b5659227a3cf5d2148d549a1c3de30fefa270 \
                        sha256  5415e11b20821a837807cdbeb7da198d714b229b5374f891821349788cc13e8d \
                        size    587301
    }
}

description             MySQL X DevAPI for PHP

long_description        The X DevAPI is the new common API for MySQL Connectors built on the X Protocol introduced in MySQL 5.7.12.

if {${name} ne ${subport}} {
    PortGroup           boost 1.0

    boost.depends_type  build

    depends_lib-append  port:lz4 \
                        port:protobuf3-cpp \
                        port:zlib \
                        port:zstd

    if {[vercmp ${version} >= 8.0.22]} {
        set cxxver      17
    } else {
        set cxxver      14
    }

    compiler.cxx_standard \
                        20${cxxver}

    # Blacklist old Clangs that implement a deprecated part of C++14 that this
    # code is not compatible with. See https://bugs.mysql.com/bug.php?id=98049
    # <= 800 doesn't work; >= 900 does; 802 untested
    compiler.blacklist-append {clang < 900}

    # Allow configure to verify the presence of the protobuf3-cpp headers.
    # (protobuf3-cpp requires C++11 or newer.)
    configure.env-append \
                        "CXXCPP=${configure.cxx} -E -std=c++${cxxver}"

    # Allow configure to verify the usability of the protobuf3-cpp headers.
    configure.cxxflags-append \
                        -std=c++${cxxver}

    configure.args      --with-boost=[boost::include_dir] \
                        --with-protobuf=${prefix}/include \
                        --with-lz4=${prefix}/include \
                        --with-zlib=${prefix}/include \
                        --with-zstd=${prefix}/include \
                        ac_cv_path_GIT_EXEC_PATH=

    platform darwin {
        if {(${os.major} == 10 || ${os.major} == 11) && [vercmp ${php.branch} >= 7.1] && [vercmp ${php.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
        }
    }

    platform darwin 17 {
        # fatal error: 'optional' file not found
        compiler.blacklist-append clang
    }
}
