# -*- 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           clang_dependency 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

github.setup        nghttp2 nghttp2 1.66.0 v
revision            0
categories          www
maintainers         {mps @Schamschula} openmaintainer
license             MIT

description         An implementation of HTTP/2 in C.
long_description    {*}${description}

homepage            https://${name}.org

github.tarball_from releases
use_xz              yes

checksums           rmd160  25d8100e5fc944cfeaca2a1775a32d565208ba3f \
                    sha256  00ba1bdf0ba2c74b2a4fe6c8b1069dc9d82f82608af24442d430df97c6f9e631 \
                    size    1743992

depends_build       path:bin/pkg-config:pkgconfig

# See: https://trac.macports.org/ticket/57960
# See: https://github.com/nghttp2/nghttp2/issues/1309
# See: https://github.com/nghttp2/nghttp2/pull/1319
# See: https://github.com/nghttp2/nghttp2/pull/2086
patchfiles-append   patch-src-shrpx_client_handler.cc.diff \
                    patch-src-shrpx_downstream_connection_pool.cc.diff \
                    src-shrpx_config.diff

# https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
configure.checks.implicit_function_declaration.whitelist-append strchr

# nghttp2 is a dependency of Clang, so we must avoid circular dependencies.
# If building the library only, C++ is not used.
compiler.cxx_standard
compiler.c_standard         1999

configure.args      --disable-silent-rules \
                    --disable-threads \
                    --enable-lib-only \
                    ac_cv_prog_AWK=/usr/bin/awk

if {${subport} eq ${name}} {
    build.dir       ${worksrcpath}/lib
    destroot.dir    ${worksrcpath}/lib
}

subport nghttp2-tools {
    revision            0
    description         Tools for nghttp2, an implementation of HTTP/2 in C.
    long_description    HTTP/2 client, server and proxy tools, as well as a \
                        load test and benchmarking tool for HTTP/2.

    compiler.cxx_standard \
                        2020

    configure.args-replace \
                        --enable-lib-only --enable-app
    configure.args-append \
                        --disable-examples

    depends_lib         port:c-ares \
                        port:jansson \
                        port:libev \
                        port:libevent \
                        port:libxml2 \
                        port:ngtcp2 \
                        path:lib/libssl.dylib:openssl \
                        port:zlib

    depends_run         port:nghttp2

    configure.env       JANSSON_CFLAGS=-I${prefix}/include \
                        LIBEVENT_OPENSSL_CFLAGS=-I${prefix}/include/event2 \
                        OPENSSL_CFLAGS=-I${prefix}/include/openssl

    configure.env-append \
                        "JANSSON_LIBS=-L${prefix}/lib -ljansson" \
                        "LIBEVENT_OPENSSL_LIBS=-L${prefix}/lib -levent -levent_openssl" \
                        "OPENSSL_LIBS=-L${prefix}/lib -lcrypto -lssl"

    post-destroot {
        # remove files contained in the main port
        delete ${destroot}${prefix}/lib
        delete ${destroot}${prefix}/include
    }
}
