# Packager = Tuxcore <dev@tuxcore.org> 
# Careful when upgrading this package! It usually breaks ABI without bumping
# soname. Also, be very mindful of the version of spirv-tools that this links
# to. Upstream actually expects the use of the particular commits of
# spirv-tools and spirv-headers that are provided in known_good.json. However,
# if we went that route, we'd have to vendor the resulting spirv-tools libs
# from this glslang build and they would be incompatible with system libs,
# resulting in us having to ship both. Instead, I recommend just waiting until
# upstream releases a compatible version of spirv-tools, then updating the
# spriv-tools system package and only then building glslang against that.
pkgname=glslang
pkgver=14.2.0
pkgrel=1
pkgdesc='OpenGL and OpenGL ES shader front end and validator'
arch=('x86_64')
url='https://github.com/KhronosGroup/glslang'
license=('BSD-3-Clause')
depends=('gcc-libs' 'spirv-tools')
makedepends=('cmake' 'ninja' 'spirv-headers' 'python')
options=('staticlibs')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/KhronosGroup/glslang/archive/${pkgver}.tar.gz)
sha256sums=('14a2edbb509cb3e51a9a53e3f5e435dbf5971604b4b833e63e6076e8c0a997b5')

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

  # we need fat LTO objects to not break consumers during linking
  CXXFLAGS+=" -ffat-lto-objects"
  cmake \
    -Bbuild-static \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DALLOW_EXTERNAL_SPIRV_TOOLS=ON \
    -DBUILD_SHARED_LIBS=OFF
  cmake --build build-static
  cmake \
    -Bbuild-shared \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DALLOW_EXTERNAL_SPIRV_TOOLS=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DGLSLANG_TESTS=ON
  cmake --build build-shared
}

check() {
  cd ${pkgname}-${pkgver}
  ninja -Cbuild-shared test
}

package() {
  cd ${pkgname}-${pkgver}
  DESTDIR="${pkgdir}" cmake --install build-static
  DESTDIR="${pkgdir}" cmake --install build-shared

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

  cd "${pkgdir}"/usr/lib
  for lib in *.so; do
    ln -sf "${lib}" "${lib}.0"
  done
}

# vim: ts=2 sw=2 et:
