# Maintainer : Daniel Bermond <dbermond@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Caleb Maclennan <caleb@alerque.com>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: Denis Martinez <deuns.martinez AT gmail.com>
# Contributor: Bogdan Burlacu <bogdan.burlacu AT pm.me>

pkgname=onetbb
pkgver=2022.3.0
pkgrel=2
pkgdesc='oneAPI Threading Building Blocks - a high level abstract threading library'
arch=('x86_64' 'aarch64')
url='https://uxlfoundation.github.io/oneTBB/'
license=('Apache-2.0')
depends=(
    'gcc-libs'
    'glibc'
    'hwloc')
optdepends=(
    'python: for Python module')
makedepends=(
    'cmake'
    'python'
    'python-setuptools'
    'swig')
conflicts=('intel-tbb' 'tbb')
provides=("intel-tbb=${pkgver}" "tbb=${pkgver}")
replaces=('intel-tbb' 'tbb')
source=("https://github.com/uxlfoundation/oneTBB/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz"
        '010-onetbb-fix-linkage-of-test-malloc-pure-c.patch')
sha512sums=('fdc50589785b1949ca1dd4429bbcedb180be4b8966da5243ddd1f8e9f97310dd603681e0bb83c1d6c2d3e27932f577ef6739e4e82f3c54af147f4d6d906b39f1'
            '155dca8391571f8790e77de4f6b76491e07c982b87826fbca8ab084a3f8786e55bf1fb64331fa3e9704dbf8c9c6f94547533b47845bdb50bf7f33a0294a3cd2b')

prepare() {
    # https://github.com/uxlfoundation/oneTBB/issues/1735
    # https://gitlab.archlinux.org/archlinux/packaging/packages/onetbb/-/merge_requests/2
    patch -d "oneTBB-${pkgver}" -Np1 -i "${srcdir}/010-onetbb-fix-linkage-of-test-malloc-pure-c.patch"
}

build() {
    cmake -B build -S "oneTBB-${pkgver}" \
        -G 'Unix Makefiles' \
        -DCMAKE_BUILD_TYPE:STRING='None' \
        -DCMAKE_INSTALL_PREFIX:PATH='/usr' \
        -DTBB_STRICT:BOOL='OFF' \
        -DTBB4PY_BUILD:BOOL='ON' \
        -Wno-dev
    cmake --build build
}

check() {
    ctest --test-dir build --output-on-failure -E test_partitioner # hangs on build server
}

package() {
    DESTDIR="$pkgdir" cmake --install build
}
