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

github.setup            ngtcp2 ngtcp2 1.25.0 v
revision                0
categories              net devel
maintainers             {gmail.com:herby.gillot @herbygillot} \
                        openmaintainer
license                 MIT
description             ${name} project is an effort to implement RFC9000 QUIC protocol
long_description        {*}${description}
homepage                https://nghttp2.org/ngtcp2
checksums               rmd160  03b9231080b28bf2c3f77b3b550fe01d1bbd0be0 \
                        sha256  2a34d2484ba17847a5d11965704e9dd0fac4c6d8efc75ffe1ec7de66d8c6b6fb \
                        size    709136
github.tarball_from     releases

use_xz                  yes

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

# Other dependencies are only used for examples:
# https://github.com/ngtcp2/ngtcp2/issues/1129
depends_lib-append      path:lib/pkgconfig/gnutls.pc:gnutls

compiler.cxx_standard   2017

configure.args-append   --disable-silent-rules \
                        --enable-lib-only=yes \
                        --enable-werror=no \
                        --with-gnutls=yes \
                        --with-openssl=no

variant openssl description {Build the OpenSSL QUIC crypto backend} {
    # The backend needs SSL_set_quic_tls_cbs, added in OpenSSL 3.5. configure
    # fails outright when the selected OpenSSL lacks it, rather than quietly
    # dropping the library.
    depends_lib-append  path:lib/libssl.dylib:openssl

    configure.args-replace \
                        --with-openssl=no --with-openssl=yes
}

variant picotls description "Enable PicoTLS" {
    # configure probes picotls through its OpenSSL backend, using the OpenSSL
    # pkg-config flags, so OpenSSL is needed here too.
    depends_lib-append  path:lib/libssl.dylib:openssl \
                        port:picotls
    configure.args-append \
                        --with-picotls=yes
    configure.cppflags-append \
                        -I${prefix}/include/picotls
    configure.ldflags-append \
                        -lpicotls-core -lpicotls-minicrypto -lpicotls-openssl
}

# Do not force build examples:
# https://github.com/ngtcp2/ngtcp2/issues/804
variant examples description "Build examples" {
    depends_lib-append  port:brotli \
                        port:libev \
                        port:nghttp3
    if {(${os.platform} eq "darwin" && ${os.major} > 9) || \
        ${os.platform} ne "darwin"} {
        # https://trac.macports.org/ticket/65945
        depends_lib-append \
                        path:lib/pkgconfig/jemalloc.pc:jemalloc
    }

    compiler.cxx_standard \
                        2020
    configure.args-append \
                        --with-libbrotlidec=yes \
                        --with-libbrotlienc=yes
    configure.args-delete \
                        --enable-lib-only=yes
}

test.run                yes
test.target             check
