# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
# Contributor: acxz <akashpatel2008 at yahoo dot com>
# Contributor: Olaf Leidinger <oleid@mescharet.de>
# Contributor: Bruno Filipe <bmilreu@gmail.com>
# Contributor: Jakub Okoński <jakub@okonski.org>
# Contributor: Ranieri Althoff <ranisalt+aur at gmail.com>

pkgname=hsa-rocr
pkgver=6.2.2
pkgrel=1
pkgdesc='HSA Runtime API and runtime for ROCm'
arch=(x86_64 powerpc64le powerpc64 riscv64)
url='https://github.com/ROCm/ROCR-Runtime'
license=('NCSA')
depends=('rocm-core' 'glibc' 'gcc-libs' 'libelf' 'libdrm'
         'hsakmt-roct' 'rocm-device-libs')
makedepends=('cmake' 'rocm-llvm' 'xxd')
source=("${pkgname}-${pkgver}.tar.gz::$url/archive/rocm-$pkgver.tar.gz"
        https://raw.githubusercontent.com/loongarch-moe/rocm-loongarch/refs/heads/rocm-6.2.x/stage2/3.rocm-rocr-runtime/rocr-unsupport.patch)
sha256sums=('5e3833de2a8461b2df9a4b1cdf5549ee2cd84e09d507b1be346cb08fdfdfe373'
            '523d7f93daca6e7272578ff0fced94a79421fef0ccd7f202425881543d4bcb56')
_dirname="$(basename "$url")-$(basename "${source[0]}" .tar.gz)"
options=(!debug !lto)

prepare() {
  cd "$_dirname"
  patch -Np1 -i ../rocr-unsupport.patch
}

build() {
  # Silence warnings on optional libraries with -DNDEBUG,
  # https://github.com/RadeonOpenCompute/ROCR-Runtime/issues/89#issuecomment-613788944
  local cmake_args=(
    -Wno-dev
    -S "$_dirname/src"
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/opt/rocm
    -D CMAKE_PREFIX_PATH=/opt/rocm
    -D CMAKE_CXX_FLAGS="$CXXFLAGS -DNDEBUG")
  cmake "${cmake_args[@]}"
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm644 "$_dirname/LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
