# -*- 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           boost 1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0

boost.version       1.81
# fstatat
legacysupport.newest_darwin_requires_legacy 13
legacysupport.redirect_bins watchman

github.setup        facebook watchman 2026.07.27.00 v
revision            0
categories          sysutils
maintainers         {danchr @danchr} openmaintainer
license             Apache-2
description         watches files and takes action when they change
long_description    ${name} {*}${description}.
checksums           rmd160  cf547e3744b32592fc5c6b93e11a3e94ee6fee0d \
                    sha256  4bab0e96e251a477148d5267aa293065f9cc8585b46485da569a729ced654de4 \
                    size    4086964
github.tarball_from archive

cmake.generator     Ninja

set port_libfmt     libfmt12
cmake.prefix_path-append \
                    ${prefix}/lib/${port_libfmt}/cmake

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]
configure.python    ${prefix}/bin/python${py_ver}

post-patch {
    reinplace -W ${worksrcpath}/watchman/python/bin "s|/usr/bin/env python3|${configure.python}|" \
        watchman-diag watchman-make watchman-replicate-subscription watchman-wait watchman-wait-aio

    reinplace -W ${worksrcpath}/watchman/python "s|/usr/bin/env python|${configure.python}|" setup.py
}

depends_build-append \
                    port:gtest \
                    path:bin/pkg-config:pkgconfig \
                    port:py${py_ver_nodot}-setuptools \
                    port:python${py_ver_nodot}

depends_lib-append  port:edencommon \
                    port:folly \
                    port:google-glog \
                    port:libevent \
                    port:${port_libfmt} \
                    port:libsodium \
                    port:pcre2 \
                    port:xxhashlib \
                    port:zlib

depends_run-append  port:python${py_ver_nodot}

configure.args-append \
                    -DBUILD_TESTS=OFF \
                    -DENABLE_EDEN_SUPPORT=NO \
                    -DINSTALL_WATCHMAN_STATE_DIR=NO \
                    -DPython3_Development_FOUND=NO \
                    -DWATCHMAN_STATE_DIR= \
                    -DWATCHMAN_VERSION_OVERRIDE=${version}

configure.env-append \
                    DESTDIR=${destroot}

patch.pre_args-replace  -p0 -p1
patchfiles          0001-Support-FSEvents-on-macOS-10.5-and-10.6.patch \
                    0002-Use-OpenSSL-for-content-hashing-on-macOS-make-Rust-a.patch \
                    0003-Find-wangle-unconditionally-FBThrift-async-s-link-in.patch \
                    0004-Suppress-unprefixed-AssertMacros-names-on-old-macOS-.patch \
                    0005-Support-32-bit-platforms-in-w_string.patch \
                    0006-Include-fmt-format.h-instead-of-the-deprecated-fmt-c.patch \
                    0007-Use-std-isfinite-in-bser.cpp.patch \
                    0008-Handle-pre-10.8-macOS-in-UnixStream-peer-credentials.patch \
                    0009-Build-the-pywatchman-C-extension-with-the-configured.patch \
                    0010-Don-t-FSEventStreamFlushSync-cross-thread-on-pre-10.patch

post-patch {
    reinplace "s,/usr/bin,${prefix}," CMakeLists.txt
}

# Fix error: invalid output constraint '=@ccc' in asm
compiler.blacklist-append \
                    {clang < 1200}

compiler.cxx_standard \
                    2020

if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append  -latomic
}

test.run            yes
test.target         check

github.livecheck.regex  {([^"rb-]+)}
