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

github.setup        intel tbb 2020.3 v
revision            1

categories          devel
maintainers         nomaintainer
license             Apache-2

description         Intel Threading Building Blocks offers a rich and complete approach \
                    to parallelism in C++

long_description    {*}${description} \
                    It represents a higher-level, task-based parallelism that abstracts \
                    platform details and threading mechanisms for scalability and performance

homepage            https://www.threadingbuildingblocks.org/

github.tarball_from tarball
# avoid stealth update due to using legacy tarball
master_sites        macports_distfiles
checksums           rmd160  64fd69e42540ef8968d9a3e36cb23816ca9de647 \
                    sha256  131d249f3132f643738d71e37162e4ac73f96bdb5064ccd35f03967fdf9b477e \
                    size    2640358

use_configure       no

# Force a compatible compiler
compiler.blacklist-append \
                    {clang < 602} {macports-clang-3.[0-7]}

# install it into libexec to avoid conflict with onetbb port
prefix              ${prefix}/libexec/${name}

set tbb_arch(arm64)     arm64
set tbb_arch(i386)      ia32
set tbb_arch(ppc)       ppc32
set tbb_arch(ppc64)     ppc64
set tbb_arch(x86_64)    intel64
if {![info exists tbb_arch(${configure.build_arch})]} {
    set tbb_arch(${configure.build_arch}) ${configure.build_arch}
}

if {[string match *clang* ${configure.compiler}]} {
    set tbb_compiler clang
} else {
    set tbb_compiler gcc
}

set tbb_build_prefix macports

patchfiles        patch-tbb-older-malloc.diff

build.env-append \
    CONLY=${configure.cc} \
    CPLUS=${configure.cxx}

post-patch {
    # http://software.intel.com/en-us/forums/topic/505370
    reinplace "/ -dynamiclib/s|$| -install_name ${prefix}/lib/\$@|g" ${worksrcpath}/build/macos.${tbb_compiler}.inc
}

build.target        tbb tbbmalloc tbbproxy
build.args-append   compiler=${tbb_compiler} \
                    stdlib=${configure.cxx_stdlib} \
                    tbb_build_prefix=${tbb_build_prefix} \
                    use_proxy=1

test.run            yes
test.target         test
test.args-append    ${build.args}

if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        set merger_build_args(${arch}) arch=$tbb_arch(${arch})
        set merger_test_args(${arch}) arch=$tbb_arch(${arch})
    }
} else {
    build.args-append arch=$tbb_arch(${configure.build_arch})
    test.args-append arch=$tbb_arch(${configure.build_arch})
}

# The Makefile does not have an install target.
# http://software.intel.com/en-us/forums/topic/347428
destroot.dir    ${worksrcpath}/build/${tbb_build_prefix}_release
destroot {
    # fix paths
    reinplace -W ${destroot.dir} "s|\\(TBBROOT.\\)\".*\"|\\1\"${prefix}\"|g" tbbvars.sh tbbvars.csh
    reinplace -W ${destroot.dir} "s|\\(tbb_bin.\\)\".*\"|\\1\"${prefix}/lib\"|g" tbbvars.sh tbbvars.csh

    # copy lib, include & bin
    copy {*}[glob ${destroot.dir}/lib*.dylib] ${destroot}${prefix}/lib
    copy {*}[glob ${destroot.dir}/tbbvars.*sh] ${destroot}${prefix}/bin
    copy ${worksrcpath}/include/tbb ${destroot}${prefix}/include/tbb

    # copy examples & docs
    xinstall -d ${destroot}${prefix}/share/
    copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc
    copy ${worksrcpath}/examples ${destroot}${prefix}/share/examples
}

livecheck.type      none

notes "
More recent versions are released as oneTBB and are packaged in the new 'onetbb' port
This version is installed into ${prefix}/libexec/${name}
"
