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

github.setup        uxlfoundation oneTBB 2023.0.0 v
github.tarball_from archive

name                onetbb
revision            0
categories          devel parallel
license             Apache-2
maintainers         {makr @mohd-akram} openmaintainer

description         oneAPI Threading Building Blocks

long_description    oneTBB is a flexible C++ library that simplifies the work \
                    of adding parallelism to complex applications, even if you \
                    are not a threading expert.

checksums           rmd160  45fa39702c4f0deec5d6ce183719a53ab6e35acf \
                    sha256  f8767b971ec6aea25dde58ae0f593e94e7aa75a739a86f67967012f69e2199b1 \
                    size    7554268

patchfiles          patch-onetbb-older-platforms.diff \
                    patch-onetbb-dispatch-fallback.diff

# https://trac.macports.org/ticket/69657 (clang < 900)
# https://trac.macports.org/ticket/72724
compiler.blacklist-append   {clang < 1200}

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      port:hwloc

compiler.cxx_standard   2011

# OneTBB's build uses CMAKE_OSX_ARCHITECTURES to add -arch flags which may lead
# to missed symbols from exported symbol list on universal build like:
# Undefined symbols for architecture i386:
#  "tbb::detail::r1::wait_bounded_queue_monitor(tbb::detail::r1::concurrent_monitor*, unsigned long, long, tbb::detail::d1::delegate_base&)", referenced from:
#     -exported_symbol[s_list] command line option
if {${os.arch} ne "powerpc"} {
    # In Rosetta this setting breaks the build; restrict it to non-PPC:
    cmake.set_osx_architectures no
}

configure.args-append  -DTBB_TEST=OFF

platform powerpc {
    # Rather than disabling -Werror altogether, just disable these:
    configure.cxxflags-append \
                    -Wno-parentheses \
                    -Wno-unused-function
}

# ___atomic_fetch_add_8, ___atomic_load_8, ___atomic_fetch_sub_8
# Drop once this is merged: https://github.com/oneapi-src/oneTBB/pull/987
if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list i386 ppc]} {
    configure.ldflags-append \
                    -latomic
}

variant tests description {Enable tests} {
    # Ensure test binaries can find dylibs:
    configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

    configure.args-delete   -DTBB_TEST=OFF

    if {${configure.cxx_stdlib} ne "libc++"} {
        # To mitigate malloc errors with libstdc++:
        test.env-append     DYLD_LIBRARY_PATH=${prefix}/lib/libgcc
    }
    test.run                yes
}

# This variant is aimed at supported legacy powerpc systems.
# It works on some at the moment, but is not ready to be the default.
# Old Intel systems can be added later upon testing.
if {${os.platform} eq "darwin" && ${configure.build_arch} in [list ppc ppc64]} {
    variant legacy_dispatch description "Enable dispatch via libdispatch-legacy port" {
        # Drop fallback code:
        patchfiles-delete   patch-onetbb-dispatch-fallback.diff

        depends_lib-append \
                    port:libdispatch-legacy
        configure.cppflags-append \
                    -I${prefix}/libexec/dispatch/usr/include
        configure.ldflags-append \
                    ${prefix}/libexec/dispatch/usr/lib/libdispatch.a
    }
}

github.livecheck.regex  {([0-9.]+)}
