pkgname=rocm-smi-lib
pkgver=7.1.0
pkgdesc='ROCm System Management Interface Library'
arch=('x86_64')
url='https://rocm.docs.amd.com/projects/rocm_smi_lib/en/latest'
license=('NCSA')
depends=('glibc' 'gcc' 'python')
makedepends=('cmake')
_patchs=("rocm-smi-5.7.1-remove-example.patch")
_patchsums=("7ba065a74fbf7ac0529473e419084558")
sources=("rocm-${pkgver}.tar.gz"
  ${_patchs[@]}
)
urls=("https://github.com/ROCm/rocm-systems/archive/${sources[0]}"
  ${_patchs[@]}
)
md5sums=("7b63ca177ae122118dc215249db5adc3"
  ${_patchsums[@]}
)

_dirname="projects/rocm-smi-lib"

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  pushd -- ${_dirname}
  for _patch in ${_patchs[@]}; do
    patch -p1 -i ${filedir}/${_patch}
  done

  # Disable code that relies on missing .git directory.
  # Just silences potential "git: command not found" QA warnings.
  sed -e "/find_program (GIT NAMES git)/d" -i CMakeLists.txt
  sed -e "/num_change_since_prev_pkg(\${VERSION_PREFIX})/d" -i cmake_modules/utils.cmake

  local rocm_lib="/usr/lib/librocm_smi64.so.@VERSION_MAJOR@"
  sed -E "s|path_librocm =.+__file__.+|path_librocm = '${rocm_lib}'|" \
      -i python_smi_tools/rsmiBindingsInit.py.in
  popd
}

src_build() {
  local cmake_args=(
    -Wno-dev
    -S "$_dirname"
    -B build
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_BUILD_TYPE=None
  )
  cmake "${cmake_args[@]}"
  cmake --build build
}

src_install() {
  DESTDIR="$pkgdir" cmake --install build

  py=python3
  _site="$("$py" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')"
  #install -Dm755 python_smi_tools/rocm_smi.py  "${pkgdir}/usr/bin/rocm-smi"
  #install -Dm644 python_smi_tools/rsmiBindings.py      "${pkgdir}/$site/rsmiBindings.py"
  #install -Dm644 python_smi_tools/rsmiBindingsInit.py  "${pkgdir}/$site/rsmiBindingsInit.py"
  #ln -svf "../libexec/rocm_smi/rocm_smi.py" "${pkgdir}/usr/bin/rocm-smi"
  install -Dm644 "$srcdir/$_dirname/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}





# vim:ft=sh syn=sh et sw=2:
