# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=shaderc
pkgver=2024.1
pkgrel=1
pkgdesc='Collection of tools, libraries and tests for shader compilation'
url='https://github.com/google/shaderc'
arch=('x86_64')
license=('Apache-2.0')
depends=('glibc' 'gcc-libs' 'glslang' 'spirv-tools')
makedepends=('asciidoctor' 'cmake' 'ninja' 'python' 'spirv-headers')
provides=('libshaderc_shared.so')
source=(https://github.com/google/shaderc/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('017d8625c66da7eb5b431f595b27a4ddf146aaa12ef56777cb8c3f7f0f15eb01c3286e5905c5268de55d07cc19d5ffae4d4c08987d105b0a6be74616a467b736')
b2sums=('a4c9790cb117e4cf2d528ed294ef0599dc3c17ac367a4f658254ff9e161f82b3338a2d70a033fabcdb7a2925c2f4668ee89cfff0d4b88cd2b22fcfb3f2786ea9')

prepare() {
  cd ${pkgname}-${pkgver}

  # de-vendor libs and disable git versioning
  sed '/examples/d;/third_party/d' -i CMakeLists.txt
  sed '/build-version/d' -i glslc/CMakeLists.txt
  cat <<- EOF > glslc/src/build-version.inc
"${pkgver}\\n"
"$(pacman -Q spirv-tools|cut -d \  -f 2|sed 's/-.*//')\\n"
"$(pacman -Q glslang|cut -d \  -f 2|sed 's/-.*//')\\n"
EOF
}

build() {
  cd ${pkgname}-${pkgver}
  cmake \
    -B build \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS -ffat-lto-objects" \
    -DSHADERC_SKIP_TESTS=ON \
    -DPYTHON_EXECUTABLE=python \
    -Dglslang_SOURCE_DIR=/usr/include/glslang
  ninja -C build

  cd glslc
  asciidoctor -b manpage README.asciidoc -o glslc.1
}

check() {
  cd ${pkgname}-${pkgver}
  ninja -C build test
}

package() {
  cd ${pkgname}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build install
  install -Dm 644 glslc/glslc.1 -t "${pkgdir}/usr/share/man/man1"

  # Remove unused shaderc_static.pc
  rm "${pkgdir}/usr/lib/pkgconfig/shaderc_static.pc"
}

# vim: ts=2 sw=2 et:
