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

# clock_gettime, through the statically linked Skarnet libraries.
legacysupport.newest_darwin_requires_legacy 15

name                s6-networking
version             2.8.0.1
revision            0
categories          net
license             ISC
maintainers         @bjornpagen openmaintainer
description         small networking utilities for s6

long_description    s6-networking is a suite of small networking utilities \
                    for Unix systems: TCP clients and servers, TCP access \
                    control, privilege gain across Unix domain sockets, \
                    IDENT, and clock synchronization. The openssl variant \
                    adds its TLS tunnel tools.

homepage            https://skarnet.org/software/s6-networking/
master_sites        ${homepage}

checksums           rmd160  f6cdd3f791cb74f7a302b561fb9eea93ec676e7a \
                    sha256  6f011c33ba0586ce58feee0cf854a0b087e9082fdbd24abb786148463830f341 \
                    size    127160

depends_build-append \
                    port:execline \
                    port:pkgconfig \
                    port:s6 \
                    port:s6-dns \
                    port:skalibs

# Its programs run execlineb and s6-applyuidgid.
depends_run         port:execline port:s6

# The clock clients send on their connected UDP socket without an address:
# Darwin's sendto() refuses one on a connected socket (EISCONN). See the patch.
patchfiles          patch-clock-connected-send.diff

# Match the normalized target recorded by skalibs.
# https://trac.macports.org/ticket/74350
configure.args-append \
                    --enable-pkgconfig \
                    --with-pkgconfig \
                    --build=${build_arch}-apple-darwin${os.major} \
                    --target=${build_arch}-apple-darwin${os.major}

# The TLS tools use the libtls API: LibreTLS provides it on OpenSSL.
variant openssl description {Build the TLS tools with OpenSSL, through LibreTLS} {
    depends_lib-append  port:libretls \
                        port:openssl
    configure.args-append \
                        --enable-ssl=libtls \
                        --with-ssl-path=${prefix}
}

default_variants    +openssl

if {![variant_isset openssl]} {
    configure.args-append \
                        --disable-ssl
}

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        AUTHORS \
        COPYING \
        INSTALL \
        NEWS \
        README \
        ${destroot}${docdir}
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/*.html] \
        ${destroot}${docdir}
    # The libraries built: libstls only with the TLS tools.
    set libs {libs6net}
    if {[variant_isset openssl]} {
        lappend libs libstls
    }
    foreach sub ${libs} {
        xinstall -d ${destroot}${docdir}/${sub}
        xinstall -m 0644 {*}[glob ${worksrcpath}/doc/${sub}/*.html] \
            ${destroot}${docdir}/${sub}
    }
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "${name}-(\[0-9.\]+)\\.tar\\.gz"
