# Template file for 'glslang'
# Libraries are unversioned, beware of ABI breakage (rebuild shaderc on updates)
pkgname=glslang
version=16.3.0
revision=1
build_style=cmake
hostmakedepends="python3 bison gtest-devel"
makedepends="SPIRV-Tools-devel"
short_desc="Khronos reference front-end for GLSL, ESSL, and sample SPIR-V generator"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://github.com/KhronosGroup/glslang"
distfiles="https://github.com/KhronosGroup/glslang/archive/${version}.tar.gz"
checksum=efff5a15258dce1ca2d323bf64c974f5fca03778174615dbc30c8d36db645bf5

if [ "$CROSS_BUILD" ]; then
	export cmake_crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
fi

do_configure() {
	cmake -B build-shared -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_EXTERNAL=OFF \
		-DBUILD_SHARED_LIBS=ON \
		-DALLOW_EXTERNAL_SPIRV_TOOLS=YES \
		$cmake_crossopts


	cmake -B build-static -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_EXTERNAL=OFF \
		-DBUILD_SHARED_LIBS=OFF \
		-DALLOW_EXTERNAL_SPIRV_TOOLS=YES \
		$cmake_crossopts
}

do_build() {
	ninja -C build-shared
	ninja -C build-static
}

do_install() {
	DESTDIR=$DESTDIR ninja install -C build-static
	DESTDIR=$DESTDIR ninja install -C build-shared
}

pre_check() {
	cmake_builddir="build-static"
}

post_install() {
	sed -n '2,32p' < glslang/GenericCodeGen/CodeGen.cpp > LICENSE
	vlicense LICENSE
}

glslang-devel_package() {
	depends="glslang-${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/lib/cmake
	}
}
