# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Daniel Bermond <dbermond@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgbase=level-zero
pkgname=(level-zero-headers level-zero-loader)
pkgver=1.17.42
pkgrel=1
pkgdesc="API for accessing low level interfaces in oneAPI platform devices"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://spec.oneapi.com/versions/latest/elements/l0/source/index.html"
license=(MIT)
makedepends=(git cmake fmt opencl-headers spdlog)
source=(https://github.com/oneapi-src/level-zero/archive/v${pkgver}/${pkgbase}-${pkgver}.tar.gz)
sha256sums=('16ba86e9fee6699c5300bb0ef09cb0852cd261e2ddd9960f88df93d4d04a4829')

prepare() {
  printf '%s\n' ${pkgver##*.} > ${pkgbase}-${pkgver}/VERSION_PATCH
}

build() {
  cmake -B build -S ${pkgbase}-${pkgver} \
    -G 'Unix Makefiles' \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DSYSTEM_SPDLOG:BOOL=ON \
    -Wno-dev
  cmake --build build
}

package_level-zero-headers() {
  pkgdesc+=" (headers)"
  #arch=(any) # Not supported for now, maybe later
  
  DESTDIR="${pkgdir}" cmake --install build
  install -Dm644 ${pkgbase}-${pkgver}/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
  
  # remove loader files
  [ -d 'loader' ] && rm -rf loader
  install -d loader/lib
  mv "${pkgdir}"/usr/lib/*so* loader/lib
}

package_level-zero-loader() {
  pkgdesc+=" (loader)"
  depends=(fmt spdlog)
  
  mv loader "${pkgdir}"/usr
  install -Dm644 ${pkgbase}-${pkgver}/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
