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

legacysupport.newest_darwin_requires_legacy     13

name                skalibs
version             2.16.0.0
revision            0
categories          devel
license             ISC
maintainers         @bjornpagen openmaintainer
description         general-purpose libraries for C system programming

long_description \
    skalibs is a package centralizing the free software / open source \
    C development files used for building all software at skarnet.org: \
    it contains essentially general-purpose libraries. skalibs can \
    also be used as a sound basic start for C development. There are a \
    lot of general-purpose libraries out there\; but if your main goal \
    is to produce small and secure C code with a focus on system \
    programming, skalibs might be for you.

homepage            https://skarnet.org/software/skalibs/
master_sites        ${homepage}

checksums           rmd160  c594960d6596f92599c30b8593a04a765c369d9b \
                    sha256  90a3deda94a40d7d6a4495fe6feaf91c0185e0428d59cbd150a1a468741269aa \
                    size    269049

depends_build-append \
                    port:pkgconfig

patchfiles          patch-iopause-select-read-event.diff \
                    patch-timeval-rounding.diff

# posix_spawn_file_actions_addchdir needs macOS 26; newer SDKs let the probe pass anyway
if {${os.platform} eq "darwin" && ${os.major} < 25} {
    configure.args-append \
                    --with-sysdep-posixspawnchdir=no
}

# Keep the kernel point release out of the recorded target; --build must match
# --target or configure cross-compiles. https://trac.macports.org/ticket/74350
configure.args-append \
                    --enable-pkgconfig \
                    --build=${build_arch}-apple-darwin${os.major} \
                    --target=${build_arch}-apple-darwin${os.major}

post-destroot {
    # The upstream install script sets umask 077 before creating
    # symlinks, producing lrwx------ permissions that cause other
    # build systems (e.g. CMake's file(READ_SYMLINK)) to fail.
    # Recreate all library symlinks with correct permissions.
    foreach f [glob -nocomplain -type l ${destroot}${prefix}/lib/lib*.dylib] {
        set target [file readlink ${f}]
        file delete ${f}
        file link -symbolic ${f} ${target}
    }

    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        AUTHORS \
        COPYING \
        NEWS \
        README \
        ${destroot}${docdir}
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/*.html] \
        ${destroot}${docdir}
    xinstall -d ${destroot}${docdir}/libdatastruct
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/libdatastruct/*.html] \
        ${destroot}${docdir}/libdatastruct
    xinstall -d ${destroot}${docdir}/libposixplz
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/libposixplz/*.html] \
        ${destroot}${docdir}/libposixplz
    xinstall -d ${destroot}${docdir}/librandom
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/librandom/*.html] \
        ${destroot}${docdir}/librandom
    xinstall -d ${destroot}${docdir}/libstdcrypto
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/libstdcrypto/*.html] \
        ${destroot}${docdir}/libstdcrypto
    xinstall -d ${destroot}${docdir}/libstddjb
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/libstddjb/*.html] \
        ${destroot}${docdir}/libstddjb
    xinstall -d ${destroot}${docdir}/libunixonacid
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/libunixonacid/*.html] \
        ${destroot}${docdir}/libunixonacid
}
