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

# O_CLOEXEC, clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup        jiixyj epoll-shim 0.0.20240608 v
revision            2
categories          devel
license             MIT
# Currently requires libdispatch.
platforms           {darwin > 9}
maintainers         nomaintainer
description         Small epoll implementation using kqueue
long_description    ${description}. Includes all features \
                    needed for libinput/libevdev.

checksums           rmd160  3cead7960ad43d9e03355753527024da0ceab0b5 \
                    sha256  8f5125217e4a0eeb96ab01f9dfd56c38f85ac3e8f26ef2578e538e72e87862cb \
                    size    104137
github.tarball_from archive

patch.pre_args-replace  -p0 -p1

# https://github.com/jiixyj/epoll-shim/pull/57
patchfiles-append   0001-Use-EV_TRIGGER-as-a-fallback-for-NOTE_TRIGGER.patch \
                    0002-Define-MSG_NOSIGNAL-when-undefined.patch \
                    0003-timerfd-root-test-skip-on-macOS-10.12.patch \
                    0004-timerfd.h-expose-struct-itimerspec-to-consumers-on-A.patch \
                    0005-src-link-compat_enable_pipe2-into-the-main-epoll-shi.patch \
                    0006-fix-struct-itimerspec-redefinition-in-epoll-shim-s-o.patch \
                    0007-src-treat-zero-O_CLOEXEC-as-always-requested-in-pipe.patch \
                    0008-epollfd_ctx-engage-poll-fallback-when-Darwin-kevent-.patch \
                    0009-src-probe-poll-only-fds-via-select-on-Darwin.patch

# * set the sin_len argument in sockaddr_in
# * set appropriate timeouts on epoll_wait() calls that can actually timeout (after 5 minutes!)
#   and that will cause the test app to bail which leads to port 1337 remaining open and thus
#   failures in subsequent tests
# * print errno when a test fails
patchfiles-append   patch-testing.diff

compiler.c_standard 2011

# error: use of unknown builtin '__builtin_mul_overflow' on macOS < 10.11
# this feature was implemented after the release of LLVM 3.8
compiler.blacklist-append \
                    {clang < 800} {macports-clang-[3-9].[0-9]} {macports-clang-1[0-2]}

# Build tries to run test binaries during the build, which fails otherwise.
configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

configure.args-append \
                    -DCMAKE_INSTALL_PKGCONFIGDIR="${prefix}/lib/pkgconfig" \
                    -DCMAKE_CTEST_ARGUMENTS="--output-on-failure"

test.run            yes
