# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Laurent Carlier <lordheavym@gmail.com>

pkgname=vulkan-validation-layers
pkgver=1.3.290
pkgrel=2
pkgdesc="Vulkan Validation Layers"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://www.khronos.org/vulkan/"
license=('custom')
groups=('vulkan-devel')
depends=('gcc-libs' 'vulkan-icd-loader' 'vulkan-headers' 'libx11')
makedepends=('cmake' 'python-lxml' 'libxrandr' 'wayland' 'ninja' 'git')
options=('!lto') # disable LTO (https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5994)
source=("https://github.com/KhronosGroup/Vulkan-ValidationLayers/archive/vulkan-sdk-${pkgver}.tar.gz")
#source=("git+https://github.com/KhronosGroup/Vulkan-ValidationLayers.git#commit=35d091dad71304dab79758fdae4bda12f692d735")
sha256sums=('c5ea27590207423bcb0686004f2814e136c44fa749e1fb9894d0d5cb713a8948')

#pkgver() {
#  cd "${srcdir}/Vulkan-ValidationLayers"
#
#  echo 1.1.97.0+$(git rev-list --count HEAD)+$(git rev-parse --short HEAD)
#}

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

  rm -rf build && mkdir build
}

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

  ../scripts/update_deps.py --config release --generator Ninja
  cmake -C helper.cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc \
    -DCMAKE_INSTALL_DATADIR=/share \
    -DCMAKE_INSTALL_INCLUDEDIR="/usr/include/" \
    -DCMAKE_SKIP_RPATH=True \
    -DBUILD_TESTS=Off \
    -DBUILD_WSI_XCB_SUPPORT=On \
    -DBUILD_WSI_XLIB_SUPPORT=On \
    -DBUILD_WSI_WAYLAND_SUPPORT=On \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    ..
  make
}

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

  install -dm755 "${pkgdir}"/usr/share/{licenses/,doc/}${pkgname}/
  cp -r ../docs/* "${pkgdir}"/usr/share/doc/${pkgname}/
  install -m644 ../LICENSE.txt "${pkgdir}"/usr/share/licenses/${pkgname}/
}
