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

# strnlen
# https://trac.macports.org/ticket/67110
legacysupport.newest_darwin_requires_legacy 14

R.setup             cran rstudio httpuv 1.6.15
revision            1
categories-append   devel net
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL-2+
description         HTTP and web-socket server library
long_description    Provides low-level socket and protocol support for handling HTTP \
                    and web-socket requests directly from within R.
homepage            https://rstudio.github.io/httpuv
checksums           rmd160  97d3e87962099a0a36e713d204cc65c5e70e6025 \
                    sha256  5e6ded3623a39df3e1db6cb7e7292b4c03c80b3c6c5faaac3b78b711cb205ed0 \
                    size    1879369

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    port:pkgconfig

depends_lib-append  port:R-later \
                    port:R-R6 \
                    port:R-Rcpp \
                    port:R-promises \
                    port:zlib

patch.pre_args-replace  -p0 -p1
patchfiles          0001-libuv-fix-for-older-macOS.patch \
                    0002-core.c-patch-close_nocancel.patch

if {${os.platform} eq "darwin" && ${os.major} < 15} {
    patchfiles-append \
                    0003-Link-to-LegacySupport.patch
    post-patch {
        # https://trac.macports.org/ticket/69853
        if {[string match *clang* ${configure.compiler}]} {
            reinplace "s|@MP_FLAGS@|-I${prefix}/include/LegacySupport -Wno-error=incompatible-function-pointer-types|" ${worksrcpath}/src/Makevars.in
        } else {
            reinplace "s|@MP_FLAGS@|-I${prefix}/include/LegacySupport|" ${worksrcpath}/src/Makevars.in
        }
    }
}

depends_test-append port:R-callr \
                    port:R-curl \
                    port:R-testthat \
                    port:R-websocket

test.run            yes
