# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Lukas Jirkovsky <l.jirkovsky@gmail.com>

pkgname=embree
pkgver=4.4.1
pkgrel=1
pkgdesc="Collection of high-performance ray tracing kernels"
arch=(aarch64 x86_64)
url="https://embree.github.io/"
license=('Apache-2.0')
depends=('glibc' 'libgcc' 'libstdc++' 'intel-tbb')
makedepends=('cmake' 'ispc' 'freeglut' 'libxmu' 'ninja')
source=(https://github.com/embree/embree/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('dcf338cc61b636c871ccf370e673bfd380c5ecb71ce49ad50f28e1d4ec9995dc')

# Embree detects actual ISA at runtime but we have to set a high maximum
# buildtime version as it would otherwise default to the builder processor.
case "$CARCH" in
  i*86|x86_64*)
      _MAX_ISA=NEON2X
      ;;
  arm*|aarch64)
      _MAX_ISA=NEON2X
      ;;
  *)
      # Upstream currently doesn't have any support for non-arm/x86
      _MAX_ISA=NONE
      ;;
esac

build() {
    cmake \
      -B build \
      -G Ninja \
      -S ${pkgname}-${pkgver} \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_BUILD_TYPE=Release \
      -DEMBREE_ISPC_SUPPORT=ON \
      -DEMBREE_TUTORIALS=OFF \
      -DEMBREE_MAX_ISA="${_MAX_ISA}" \
      -DEMBREE_BACKFACE_CULLING=OFF
    ninja -C build
    # Maybe enable these later once they are out of beta:
      # -DEMBREE_SYCL_SUPPORT=ON \
      # -DEMBREE_SYCL_LARGEGRF=ON
}

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

    mkdir "${pkgdir}"/usr/bin/
    mv "${pkgdir}"/usr/embree-vars.* "${pkgdir}"/usr/bin/
}
