# Maintainer: Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>

# This is just for the Gamescope WSI layer.

pkgname=lib32-gamescope
_srctag=3.17.0
pkgver=${_srctag//-/.}
pkgrel=2
pkgdesc="gaming shell based on Xwayland, powered by Vulkan and DRM (32-bit)"
arch=(x86_64)
url="https://github.com/ValveSoftware/gamescope"
license=('MIT')
depends=('lib32-wayland' 'lib32-libx11' 'lib32-libxcb' 'lib32-vulkan-icd-loader')
makedepends=(openssh git meson cmake wayland-protocols ninja glslang glm vulkan-headers lib32-glm)
source=("lib32-gamescope::git+https://github.com/ValveSoftware/gamescope.git#tag=$_srctag"
        # FIXME Upstream gamescope is just selecting master branch at build time, so we are arbitrarily snapshotting a
        #       revision when bumping the version here such that the build is reproducible.
        "git+https://github.com/nothings/stb.git#commit=af1a5bc352164740c1cc1354942b1c6b72eacb8a"
        "git+https://github.com/g-truc/glm.git#commit=0af55ccecd98d4e5a8d1fad7de25ba429d60e863")
sha256sums=('7abf4c491b897e491772d725cce599c8ba4b9b0c54c9b9502f6ef0ea023bf762'
            'e39e0c91b297bfd707afcda84ecdc15a08c22e2ad4c347fc3533b1ed98fb3f85'
            '85f3e55fb527e9853bd4fc31300253587198831660a743eaa55f6b40fe1b9c90')

prepare() {
	cd "$pkgname"

	# meson subprojects
	rm -rf subprojects/stb
	git clone "$srcdir/stb" subprojects/stb
	cp -av subprojects/packagefiles/stb/* subprojects/stb/ # patch from the .wrap we elided

	rm -rf subprojects/glm
	git clone "$srcdir/glm" subprojects/glm
	cp -av subprojects/packagefiles/glm/* subprojects/glm/ # patch from the .wrap we elided
}

build() {
	cd "$pkgname"

	export CC="gcc -m32"
	export CXX="g++ -m32"
	export PKG_CONFIG="i686-pc-linux-gnu-pkg-config"

	rm -rf build
	mkdir build
	cd build
	arch-meson --libdir=/usr/lib32 -Denable_gamescope=false -Denable_gamescope_wsi_layer=true -Denable_openvr_support=false -Dpipewire=disabled --buildtype release --prefix /usr ..
	ninja
}

package() {
	cd "$pkgname/build"

	DESTDIR="$pkgdir" meson install --skip-subprojects

	rm -rf "$pkgdir"/usr/share/gamescope
}
