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

# Need O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10

github.setup        h2o picotls 703553c94048ba22987e8529590f4c060c0407f8
version             2024.03.05
revision            0
categories          net security
license             MIT
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         ${name} is a TLS 1.3 (RFC 8446) protocol stack written in C
long_description    {*}${description}. &{name} is designed to be fast, tiny and low-latency, \
                    with the primary user being the H2O HTTP/2 server for serving \
                    HTTP/1, HTTP/2 and HTTP/3 over QUIC.

github.tarball_from archive

set picotest_hash   6906d90b39684b8b2c18db5b0c7412128140655d

master_sites-append https://github.com/h2o/picotest/archive/${picotest_hash}/:picotest
distfiles-append    picotest-${picotest_hash}.tar.gz:picotest

checksums           ${distname}${extract.suffix} \
                    rmd160  a0461de42f2e24063ce2ab3719782860ad0ec2eb \
                    sha256  01debc1ebd6dabe301cdf82d7f0d8bf7107f915d3ab48ee26d82f288c66d9d8b \
                    size    641429 \
                    picotest-${picotest_hash}.tar.gz \
                    rmd160  934cb89c1683095b5950ece003c5a307c773b058 \
                    sha256  a297cfd0db85186813622ebffcd8d86d73cd0e590f5fb7fe82ec7d40c88d3677 \
                    size    1748

extract.only        ${distname}${extract.suffix}

post-extract {
    set tar [findBinary tar ${portutil::autoconf::tar_command}]
    system -W ${workpath} "${tar} -zxf ${distpath}/picotest-${picotest_hash}.tar.gz"
    delete ${worksrcpath}/deps/picotest
    move ${workpath}/picotest-${picotest_hash} ${worksrcpath}/deps/picotest
}

depends_lib-append  port:brotli \
                    port:mbedtls3

configure.args-append \
                    -DWITH_AEGIS=OFF \
                    -DWITH_DTRACE=OFF \
                    -DWITH_MBEDTLS=ON

# https://github.com/h2o/picotls/issues/505
compiler.blacklist-append \
                    *gcc-4.* {clang < 500}

# FIXME: fails to build with clang on 10.6–10.7:
# error: call to undeclared library function 'aligned_alloc'
# https://github.com/h2o/picotls/issues/514

destroot {
    move ${cmake.build_dir}/cli ${destroot}${prefix}/bin/picotls_cli
    copy ${worksrcpath}/include/picotls ${destroot}${prefix}/include
    copy ${worksrcpath}/include/picotls.h ${destroot}${prefix}/include
    foreach lib {libpicotls-core.a libpicotls-mbedtls.a libpicotls-minicrypto.a libpicotls-openssl.a} {
        copy ${cmake.build_dir}/${lib} ${destroot}${prefix}/lib
    }
}

test.run            yes
test.target         check
