# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8::et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0

# strnlen
legacysupport.newest_darwin_requires_legacy 10

github.setup        draios sysdig 0.41.4
revision            3
maintainers         nomaintainer
categories          sysutils
description         ${name} is an open source system-level exploration and troubleshooting tool.
long_description    Sysdig captures system calls and other system level events \
                    using a linux kernel facility called tracepoints, which \
                    means much less overhead than strace. It then "packetizes" \
                    this information, so that you can save it into trace files \
                    and filter it, a bit like you would do with tcpdump. This \
                    makes it very flexible to explore what processes are doing. \
                    Sysdig is also packed with a set of scripts that make it \
                    easier to extract useful information and do troubleshooting. \
                    \n\nNOTE: currently only the Linux version of sysdig is capable \
                    of capturing events and doing live analysis. On the other \
                    platforms, you will be limited to working with the trace \
                    files generated by a Linux installation of sysdig.
license             GPL-2
homepage            http://www.sysdig.org

github.tarball_from tarball

# Fails to build against the latest release. Follow Void Linux:
# https://github.com/void-linux/void-packages/blob/4203bc8fe4f703eb1de73dc66b818c72e06593c7/srcpkgs/sysdig/template
set falco_libver    21
set falco_ver       0.${falco_libver}.0

master_sites-append https://github.com/falcosecurity/libs/archive/refs/tags/:falco
distfiles-append    ${falco_ver}${extract.suffix}:falco

checksums           ${distname}${extract.suffix} \
                    rmd160  443b3ce21a2ca67f1135ab7c2916aaf31d73d6d5 \
                    sha256  d49446534644d058761c10fe93b0fd6bd796f09fa7cc0c3203a9208f419d730f \
                    size    43442977 \
                    ${falco_ver}${extract.suffix} \
                    rmd160  745e4a5c4fc86840f39250dbd18dcbefef8ba73c \
                    sha256  9e977001dd42586df42a5dc7e7a948c297124865a233402e44bdec68839d322a \
                    size    4511266

extract.only        ${distname}${extract.suffix}
extract.rename      yes

patch.dir           ${workpath}

patchfiles-append   CMakeLists.patch \
                    falcosecurity-libs-inttypes.patch \
                    falcosecurity-libs-powerpc.patch \
                    falcosecurity-libs-stdint.patch

post-extract {
    set tar [findBinary tar ${portutil::autoconf::tar_command}]
    system -W ${workpath} "${tar} -zxf ${distpath}/${falco_ver}${extract.suffix}"
}

depends_build-append \
                    port:nlohmann-json \
                    path:bin/pkg-config:pkgconfig \
                    port:uthash \
                    port:valijson
depends_lib-append  port:c-ares \
                    port:curl \
                    port:grpc \
                    port:jq \
                    port:jsoncpp \
                    port:libb64 \
                    path:lib/libluajit-5.1.2.dylib:luajit \
                    port:ncurses \
                    port:onetbb \
                    port:protobuf \
                    port:re2 \
                    port:yaml-cpp \
                    port:zlib

compiler.cxx_standard   2017
# error: no viable constructor or deduction guide for deduction of template arguments of 'shared_ptr'
compiler.blacklist-append \
                    {clang < 1300}

configure.pkg_config_path-prepend \
                    ${prefix}/libexec/onetbb/lib/pkgconfig

configure.args-append \
                    -DBUILD_BPF=OFF \
                    -DBUILD_DRIVER=OFF \
                    -DBUILD_LIBSCAP_EXAMPLES=OFF \
                    -DBUILD_LIBSCAP_GVISOR=OFF \
                    -DBUILD_LIBSINSP_EXAMPLES=OFF \
                    -DBUILD_SHARED_LIBS=ON \
                    -DBUILD_SYSDIG_MODERN_BPF=OFF \
                    -DCREATE_TEST_TARGETS=OFF \
                    -DFALCOSECURITY_LIBS_VERSION=${falco_ver} \
                    -DFALCOSECURITY_LIBS_SOURCE_DIR=${workpath}/libs-${falco_ver} \
                    -DFALCOSECURITY_SHARED_LIBS_VERSION=${falco_ver} \
                    -DFALCOSECURITY_SHARED_LIBS_SOVERSION=${falco_libver} \
                    -DTBB_INCLUDE_DIR=${prefix}/libexec/onetbb/include \
                    -DTBB_LIB=${prefix}/libexec/onetbb/lib/libtbb.dylib \
                    -DUSE_BUNDLED_B64=OFF \
                    -DUSE_BUNDLED_DEPS=OFF \
                    -DUSE_BUNDLED_DRIVER=OFF \
                    -DUSE_BUNDLED_FALCOSECURITY_LIBS=ON \
                    -DUSE_BUNDLED_JSONCPP=OFF \
                    -DUSE_BUNDLED_RE2=OFF \
                    -DUSE_BUNDLED_TBB=OFF \
                    -DUSE_BUNDLED_VALIJSON=OFF \
                    -DUTHASH_INCLUDE=${prefix}/include/uthash

configure.cppflags-append \
                    -I${prefix}/include/uthash
# The build is handicapped:
# Undefined symbols for architecture x86_64:
#  "Json::FastWriter::write(Json::Value const&)"
configure.ldflags-append \
                    -ljsoncpp

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