# Contributor: Rogério da Silva Yokomizo <me@ro.ger.io>
# Maintainer: Rogério da Silva Yokomizo <me@ro.ger.io>
pkgname=looking-glass
_pkgver=B6
pkgver=6b
pkgrel=3
pkgdesc="Allows the use of a KVM configured for VGA PCI Pass-through without an attached physical monitor, keyboard or mouse"
url="https://looking-glass.io/"
arch="x86_64"
license="GPL-2.0-or-later"
makedepends="
	cmake
	fontconfig-dev
	libsamplerate-dev
	libx11-dev
	libxcursor-dev
	libxfixes-dev
	libxi-dev
	libxinerama-dev
	libxkbcommon-dev
	libxpresent-dev
	libxscrnsaver-dev
	nettle-dev
	obs-studio-dev
	pipewire-dev
	pulseaudio-dev
	samurai
	spice-dev
	wayland-dev
	wayland-protocols
	"
source="$pkgname-$_pkgver.tar.gz::https://looking-glass.io/artifact/$_pkgver/source
	missing-includes.patch
	obs-plugins-lib.patch
	werror.patch
	module_1075-fix-build-linux64.patch
	module_1124-fix-build-linux610.patch
	AKMBUILD
	"
subpackages="$pkgname-obs $pkgname-module"
builddir="$srcdir/$pkgname-$_pkgver"
options="!check" # There are no tests nor --version.

build() {
	cmake -S client -B build-client -G Ninja \
		-DENABLE_BACKTRACE=OFF \
		-DOPTIMIZE_FOR_NATIVE=OFF \
		-DCMAKE_INSTALL_PREFIX=/usr

	cmake -S obs -B build-obs -G Ninja \
		-DENABLE_BACKTRACE=OFF \
		-DOPTIMIZE_FOR_NATIVE=OFF \
		-DCMAKE_INSTALL_PREFIX=/usr

	cmake --build build-client
	cmake --build build-obs
}

package() {
	DESTDIR="$pkgdir" cmake --install build-client
	DESTDIR="$pkgdir" cmake --install build-obs
}

module() {
	pkgdesc="Looking Glass kernel module (AKMS)"
	depends="akms"
	install -Dm644 "$srcdir"/AKMBUILD "$subpkgdir"/usr/src/looking-glass/AKMBUILD
	install -Dm644 "$builddir"/module/kvmfr* "$subpkgdir"/usr/src/looking-glass/.
	install -Dm644 "$builddir"/module/Makefile "$subpkgdir"/usr/src/looking-glass/.
	chmod -R u=rwX,go=rX-w "$subpkgdir"/usr/src/looking-glass
	mkdir -p "$subpkgdir"/etc/udev/rules.d
	echo 'SUBSYSTEM=="kvmfr", OWNER="root", GROUP="kvm", MODE="0660"' > "$subpkgdir"/etc/udev/rules.d/99-kvmfr.rules
}

obs() {
	pkgdesc="$pkgdesc (obs plugin)"
	amove usr/lib/obs-plugins
}

sha512sums="
558981d6b32098076ef0775a748da349941551352cbef836e37310e43e5cd6072df3dec6fa2418a9abecc7729ef0c1c6869e3168d05a3d76bea46c6eb8c4e82c  looking-glass-B6.tar.gz
6d2449764a8316dd3c1b5cc0aa552671068f89ed2f95297f3c5256af8529b93e5ec7af8f979bd2e744fd09b11063e8a93f3ed26284f0e49294e467ca10f6e772  missing-includes.patch
33c5463412a16691f47d7833ebf81d7cf20c560a077dca141dcc9f02a5d6dfb676e483835f39a06012b114be9f509dda4614fe253bb1c72a0142e82dc265a5ca  obs-plugins-lib.patch
b952d1fd284aed15bcfe7990f160dec3a4565fb5833ce339920f62de6bb46fbc09265a0a79fe80d212eecc6a1813614e1e193a8846c37e2afd18431dc3a89ca4  werror.patch
c6bf503f8d1b6695faac1e2fbb23b944ab4f03ece8972ea166377f27df2804b4d56f798786a5ccfe4df53bb1c47d2fc4eec509e756ca32af2221f5f9ab8917af  module_1075-fix-build-linux64.patch
6e8c2d3bf6fa3ea826b844f73d574e5933763e37ad4eb1442c2dfec4d7ceba46918eaa5ee138cfb6437305b7d7e40e157535fff08e3412f2e05cbd1099c29eba  module_1124-fix-build-linux610.patch
9e510d43e2849647ea6ff8ae76872ae2f0aac65119b510c3d1f8b6e4e22263f7be60ab092a853733a3aa22794d0ff0c97619a69e22d79c4936916f99f381d087  AKMBUILD
"
