# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=volk
pkgbase=mingw-w64-vulkan-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-vulkan-${_realname}")
pkgver=1.4.335.0
pkgrel=1
pkgdesc="Meta loader for Vulkan API (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/zeux/volk'
msys2_references=(
  'archlinux: volk'
)
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-vulkan-headers"
  "${MINGW_PACKAGE_PREFIX}-vulkan-loader"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
)
source=("https://github.com/zeux/volk/archive/refs/tags/vulkan-sdk-${pkgver}.tar.gz")
sha256sums=('ca2beb1ab9bf272895bc0152ef29b437d178d837bae4a76d0022b7bbafb3c483')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DVOLK_INSTALL=ON \
      -S "${_realname}-vulkan-sdk-${pkgver}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}"/${_realname}-vulkan-sdk-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md
}
