# -*- 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
PortGroup           perl5 1.0

# Need O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10

github.setup        h2o picotls 4e443c11eb48949e597911b1b772a9d2588b4769
version             2025.09.12
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.

set with_fusion     OFF
if {${configure.build_arch} in [list i386 x86_64]} {
    set with_fusion ON
}

github.tarball_from archive

set picotest_hash   a99858e0c33b97b24cd09ceae729f2be33ec01e1

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  b9c4f9603c5fceb839b841fa5c6e2f81f9739ac9 \
                    sha256  b9e0c88d03ec93de9b7395f7796e5294e45b92bcc516db441d574bf1abaa839c \
                    size    655335 \
                    picotest-${picotest_hash}.tar.gz \
                    rmd160  d0305fe488de16cd68e2919643f4fc9cf60c9025 \
                    sha256  f3c42d988c8cd1af24dee2e66ce832f3e257bb7766e34167499954c1604c82c0 \
                    size    1828

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
}

perl5.branches      5.34

depends_lib-append  port:brotli

depends_test-append port:p${perl5.major}-scope-guard \
                    port:p${perl5.major}-test-tcp

patchfiles-append   patch-aligned_alloc.diff

# MbedTLS is still WIP as previous PRs have been abandoned
configure.args-append \
                    -DWITH_AEGIS=OFF \
                    -DWITH_DTRACE=OFF \
                    -DWITH_FUSION=${with_fusion} \
                    -DWITH_MBEDTLS=OFF

# See net/nss/Portfile for architecture-specific compiler problems
compiler.blacklist-append \
                    {*gcc-[34].*} {clang < 800}

destroot {
    move ${cmake.build_dir}/cli ${destroot}${prefix}/bin/picotls_cli
    foreach lib {libpicotls-core.a libpicotls-minicrypto.a libpicotls-openssl.a} {
        copy ${cmake.build_dir}/${lib} ${destroot}${prefix}/lib
    }
    if {${with_fusion} eq "ON"} {
        copy ${cmake.build_dir}/libpicotls-fusion.a ${destroot}${prefix}/lib
    } else {
        delete ${worksrcpath}/include/picotls/fusion.h
    }
    delete ${worksrcpath}/include/picotls/mbedtls.h
    copy ${worksrcpath}/include/picotls ${destroot}${prefix}/include
    copy ${worksrcpath}/include/picotls.h ${destroot}${prefix}/include
}

test.run            yes
test.target         check
