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

github.setup    libuv libuv 1.44.2 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision        0
checksums       rmd160  3802316d7f5dcfe3906ba371d4a738ab60d77339 \
                sha256  8ff28f6ac0d6d2a31d2eeca36aff3d7806706c7d3f5971f5ee013ddb0bdd2e9e \
                size    3594484

subport libuv-devel {

    # need clock_gettime
    legacysupport.newest_darwin_requires_legacy 15

    github.setup \
                libuv libuv 1.47.0 v
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    revision    0

    checksums   rmd160  6510cd246bb2062874a5cb37e92a1c727a7d2655 \
                sha256  72a187104662b47f2a2b204da39d2acb05cf22a4fcb13ceaebe3b0ed0c0e2e43 \
                size    1654769
}

set domain      libuv.org
homepage        https://${domain}/
master_sites    https://dist.${domain}/dist/v${version}
distfiles       ${name}-v${version}-dist${extract.suffix}

categories      devel
license         {MIT BSD}
maintainers     {michaelld @michaelld} \
                {gmail.com:herby.gillot @herbygillot} \
                openmaintainer

description     Cross-platform asychronous I/O

long_description \
    ${name} is a multi-platform support library with a focus on \
    cross-platform asynchronous I/O.

patchfiles-append \
                patch-libuv-unix-core-close-nocancel.diff

if {${subport} eq ${name}} {
    # RELEASE
    patchfiles-append patch-libuv-legacy.diff

    conflicts   libuv-devel
} else {
    # DEVEL
    patchfiles-append patch-libuv-legacy-devel.diff

    conflicts   libuv

    compiler.c_standard 2011

    # stdatomic.h
    compiler.blacklist-append {clang < 700}
}

# strnlen, lutimes
legacysupport.newest_darwin_requires_legacy 10

configure.args  --disable-silent-rules

platform darwin {
    if { ${os.major} == 8 } {
        # Tiger has no libutil
        patchfiles-append patch-no-libutil-on-Tiger.diff

        configure.cppflags-append -D__DARWIN_UNIX03
        # prevent conflicting opentransport header from being pulled in
        configure.cppflags-append -D__OPENTRANSPORTPROVIDERS__
    } elseif { ${os.major} == 9 || ${os.major} == 10 } {
        # needed for the tests to compile correctly on Leopard
        configure.cppflags-append -D__DARWIN_64_BIT_INO_T
    }
}

test.run        yes
test.target     check
