# Maintainer: Eric Naim <dnaim@cachyos.org>
# Contributor: Matthew Schwartz <matthew.schwartz@linux.dev>

pkgname=lib32-gamescope
pkgver=3.16.25
pkgrel=1
pkgdesc="WSI Layer for use with gamescope (32-bit)"
arch=(x86_64)
url="https://github.com/ValveSoftware/gamescope"
license=('BSD-2-Clause')
depends=(
    "gamescope=${pkgver}"
    'lib32-libx11'
    'lib32-libxcb'
    'lib32-vulkan-icd-loader'
    'lib32-wayland'
)
makedepends=(
    'cmake'
    'git'
    'meson'
    'ninja'
    'vulkan-headers'
    'wayland-protocols'
)
replaces=('lib32-gamescope-plus')
source=("git+${url}#tag=${pkgver}")
sha256sums=('fde4e64a2ab1a200ca4b9e572c1db4eafdde6ab94e11f0831ef0f62af29989d8')

prepare() {
    cd gamescope
    meson subprojects download
}

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

    arch-meson gamescope build \
        --libdir /usr/lib32 \
        -Denable_gamescope=false \
        -Denable_gamescope_wsi_layer=true \
        -Denable_openvr_support=false \
        -Dpipewire=disabled
    meson compile -C build
}

package() {
    DESTDIR="$pkgdir" meson install -C build --skip-subprojects

    rm -rf "$pkgdir"/usr/share/gamescope
    rm -rf "$pkgdir"/usr/include
    rm -rf "$pkgdir"/usr/lib/libwlroots*
    rm -rf "$pkgdir"/usr/lib32/libwlroots*
    rm -rf "$pkgdir"/usr/lib/pkgconfig
    rm -rf "$pkgdir"/usr/lib32/pkgconfig
}
