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

epoch                   1
name                    php-swoole
categories-append       net devel
maintainers             {ryandesign @ryandesign} openmaintainer
license                 Apache-2

php.branches            5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2
php.pecl                yes

if {[vercmp ${php.branch} >= 8.0]} {
    version             5.0.3
    revision            0
    checksums           rmd160  c8d3b6e892b2c2bc919ac0da36c6837b4315bfa6 \
                        sha256  6c51e11199214921e07ab1b9f0e67781c96f7b8e06afb4225f05d1dc79832ead \
                        size    2066852
} elseif {[vercmp ${php.branch} >= 7.2]} {
    version             4.8.13
    revision            0
    checksums           rmd160  0725d0bc7feb986ca41180d015e48445c8f70d6d \
                        sha256  f4b7b856c112b1058985e0b1fca320ec1211299607b363073de9a709628ad32a \
                        size    2106874
    patchfiles-append   arm.patch
    patchfiles-append   timer.patch
} elseif {[vercmp ${php.branch} >= 7.1]} {
    version             4.5.11
    revision            2
    checksums           rmd160  787880685a821869f19c1b6f4645857b75a048fe \
                        sha256  2d85752ee2b0944399c2901bb22832f196ba3f7ba4262c239d12ed494e2460dd \
                        size    1554142
} elseif {[vercmp ${php.branch} >= 7.0]} {
    version             4.3.6
    revision            2
    checksums           rmd160  e77d9a43dbbc6c133e42bf564af9d975e8874838 \
                        sha256  9253d1cb3ae109e18473efc51d14a99067417c28f4c66b1b0a0cdae5141253f9 \
                        size    1349407
} elseif {[vercmp ${php.branch} >= 5.5]} {
    # https://github.com/swoole/swoole-src/issues/1783
    version             2.0.11
    revision            5
    checksums           rmd160  7238015b141faf59d9662d4ab21c73bb66b58e35 \
                        sha256  07df75ede4bf0833d2c2443b666a5c3054bc498a78f5251babc1b0e7cc8cd573 \
                        size    769029
} else {
    version             1.10.5
    revision            5
    checksums           rmd160  48b8c3bf5999e5365b3e804440464114500120ed \
                        sha256  5c1dc0b82772ca1c352de4ddf20deeb35f06e4c5a01beba5a446d78a1f747bd2 \
                        size    730797
}

description             an event-driven asynchronous & concurrent & coroutine networking engine with high performance for PHP

long_description        ${name} is ${description}.

if {${name} ne ${subport}} {
    conflicts           ${php}-openswoole

    # Not sure what version
    if {[vercmp ${version} >= 4.0.0]} {
        PortGroup       legacysupport 1.1
        # strndup
        legacysupport.newest_darwin_requires_legacy \
                        10

        if {[vercmp ${version} >= 4.0.4]} {
            compiler.cxx_standard 2011

            if {[vercmp ${version} >= 4.5.0]} {
                compiler.thread_local_storage yes
            }

            if {[vercmp ${version} < 4.6.2]} {
                patchfiles-append \
                        arm64.patch
            }
        }
    }

    depends_lib-append  port:hiredis \
                        port:nghttp2 \
                        path:lib/libssl.dylib:openssl \
                        port:zlib


    compiler.blacklist-append \
                        *gcc-4.0 *gcc-4.2

    configure.args      --enable-async-redis \
                        --enable-http2 \
                        --enable-openssl \
                        --enable-swoole \
                        --with-openssl-dir=${prefix}

    if {[vercmp ${version} >= 4.1]} {
        depends_lib-append \
                        port:brotli
    }

    use_parallel_build  yes
}
