# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
pkgname=hipify-clang
pkgver=6.3.2
pkgrel=1
pkgdesc='Convert code to Portable C++ Code'
arch=(x86_64 powerpc64le powerpc64 riscv64)
url='https://rocm.docs.amd.com/projects/HIPIFY/en/latest'
license=('MIT')
depends=('glibc' 'gcc-libs' 'ncurses' 'bash' 'perl' 'zstd' 'zlib'
         'rocm-llvm')
makedepends=('cmake')
makedepends_x86_64=('cuda')
_git='https://github.com/ROCm-Developer-Tools/HIPIFY'
source=("${pkgname}-${pkgver}.tar.gz::$_git/archive/rocm-$pkgver.tar.gz")
sha256sums=('c0da5118be8207fab6d19803417c0b8d2db5bc766279038527cbd6fa92b25c67')
options=(!lto)
_dirname="$(basename "$_git")-$(basename "${source[0]}" .tar.gz)"

build() {
  local cmake_args=(
                    -B build
                    -S "$_dirname"
                    -Wno-dev
                    -DCMAKE_BUILD_TYPE=None
                    -DCMAKE_INSTALL_PREFIX=/opt/rocm
                    -DCMAKE_PREFIX_PATH=/opt/rocm/lib/llvm/lib/cmake
                   )
  cmake "${cmake_args[@]}"
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  # The script hipify-perl is generated read-only
  chmod a+x "$pkgdir/opt/rocm/bin/hipify-perl"

  install -Dm644 "$_dirname/LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
