# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=vulkan-tools
pkgver=%version%
pkgrel=%release%
arch=(x86_64)
url="https://www.khronos.org/vulkan/"
pkgdesc="Vulkan Utilities and Tools"
license=('custom')
depends=('libx11' 'wayland' 'libvulkan.so')
makedepends=('cmake' 'python' 'vulkan-headers' 'vulkan-icd-loader' 'wayland-protocols' 'glslang' 'spirv-tools')
groups=('vulkan-devel')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/KhronosGroup/Vulkan-Tools/archive/v${pkgver}.tar.gz")
sha256sums=('029784dcc16154258499d97418142fb43d07a136bcefcaf0575bb7194068e381')

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

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

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

  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

  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-wayland "${pkgdir}"/usr/bin/

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