# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=vulkan-tools
pkgver=1.4.303
pkgrel=2
arch=(x86_64)
url="https://www.khronos.org/vulkan/"
pkgdesc="Vulkan Utilities and Tools"
license=('custom')
depends=('libx11' 'wayland')
makedepends=('cmake' 'python' 'wayland-protocols' 'vulkan-headers' 'glslang' 'spirv-tools')
makedepends+=('libx11' 'libxrandr' 'ninja' 'git') # for update_deps.py -- volk dependency
groups=('vulkan-devel')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/KhronosGroup/Vulkan-Tools/archive/v${pkgver}.tar.gz")
sha256sums=('958b646bbc5ac0a54908342df30da8c183690f579dce7f7130ac93d433d9d3a8')

prepare() {
  cd "${srcdir}"/Vulkan-Tools*

  rm -rf build{,-wayland} && mkdir build{,-wayland}
}

build() {
  cd "${srcdir}"/Vulkan-Tools*/build

  ../scripts/update_deps.py --config release --generator Ninja
  cmake -C helper.cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc \
    -DCMAKE_INSTALL_DATADIR=/usr/share \
    -DCMAKE_SKIP_RPATH=True \
    -DBUILD_WSI_XCB_SUPPORT=On \
    -DBUILD_WSI_XLIB_SUPPORT=On \
    -DBUILD_WSI_WAYLAND_SUPPORT=On \
    -DBUILD_CUBE=ON \
    -DBUILD_VULKANINFO=ON \
    -DBUILD_ICD=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    ..
  make

  cd "${srcdir}"/Vulkan-Tools*/build-wayland

  ../scripts/update_deps.py --config release --generator Ninja
  cmake -C helper.cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc \
    -DCMAKE_INSTALL_DATADIR=/usr/share \
    -DCMAKE_SKIP_RPATH=True \
    -DBUILD_WSI_XCB_SUPPORT=OFF \
    -DBUILD_WSI_XLIB_SUPPORT=OFF \
    -DBUILD_WSI_WAYLAND_SUPPORT=On \
    -DBUILD_CUBE=ON \
    -DCUBE_WSI_SELECTION=WAYLAND \
    -DBUILD_VULKANINFO=OFF \
    -DBUILD_ICD=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    ..
  make
}

package() {
  cd "${srcdir}"/Vulkan-Tools*/build
  
  make DESTDIR="${pkgdir}" install

  install -m755 ../build-wayland/cube/vkcube "${pkgdir}"/usr/bin/vkcube-wayland

  install -dm755 "${pkgdir}"/usr/share/licenses/${pkgname}
  install -m644 ../LICENSE.txt "${pkgdir}"/usr/share/licenses/${pkgname}/
}
