# Maintainer: Felix Yan <felixonmars@archlinux.org>
# 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=tbb
pkgver=2021.5.0
pkgrel=2
pkgdesc='High level abstract threading library'
arch=('x86_64')
url='https://www.threadingbuildingblocks.org/'
license=('Apache')
depends=('gcc-libs' 'hwloc')
makedepends=('cmake' 'inetutils' 'ninja' 'python' 'swig')
conflicts=('intel-tbb')
provides=("intel-tbb=$pkgver")
replaces=('intel-tbb')
source=(https://github.com/oneapi-src/oneTBB/archive/v$pkgver/$pkgname-$pkgver.tar.gz
        retry-pthread_create.patch::https://github.com/oneapi-src/oneTBB/pull/824.patch)
sha512sums=('0e7b71022e397a6d7abb0cea106847935ae79a1e12a6976f8d038668c6eca8775ed971202c5bd518f7e517092b67af805cc5feb04b5c3a40e9fbf972cc703a46'
            '62c1535a3888f27f1af5f472c57b8e22dc6977a0a64edb84d9ea84e4a967169d2c79a2b20654c4aa3da2891fec9538c22c6e5d8a5f296947b8760c6f97e02d98')

prepare() {
  # Patch for mold:
  patch -d oneTBB-$pkgver -p1 -i ../retry-pthread_create.patch
}

build() {
  cd oneTBB-$pkgver
  # TBB_STRICT is ON by default and turns on -Werror, but `-DTBB_STRICT=OFF` is currently broken:
  # https://github.com/oneapi-src/oneTBB/issues/847
  # Upstream doesn't support GCC 12 yet:
  # https://github.com/oneapi-src/oneTBB/issues/823#issuecomment-1128997690
  # So we turn off the problematic new warnings in GCC 12 manually.
  export CXXFLAGS="$CXXFLAGS -Wno-error=uninitialized -Wno-error=address"
  cmake -GNinja -DCMAKE_INSTALL_PREFIX=/usr -DTBB4PY_BUILD=ON .
  ninja all python_build
}

check() {
  cd oneTBB-$pkgver
  ninja test
}

package() {
  cd oneTBB-$pkgver
  DESTDIR="$pkgdir" ninja install
}
