# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=libsurvive
pkgver=1.01
pkgrel=5
pkgdesc="Open Source Lighthouse Tracking System"
url="https://github.com/cntools/libsurvive"
arch="all"
license="MIT"
depends="xr-hardware"
depends_dev="
	eigen-dev
	libpcap-dev
	libusb-dev
	openblas-dev
	zlib-dev
	"
makedepends="$depends_dev
	cmake
	sciplot
	"
subpackages="$pkgname-static $pkgname-dev $pkgname-bash-completion $pkgname-web::noarch"
source="https://github.com/cntools/libsurvive/releases/download/v$pkgver/libsurvive-v$pkgver-source.zip
	off64_t.patch
	sciplot-0.3.0.patch
	"
options="!check" # Requires live test data
builddir="$srcdir/$pkgname"

build() {
	cmake -B build \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_STATIC=OFF \
		-DUSE_OPENBLAS=ON \
		-DDOWNLOAD_EIGEN=OFF \
		-DCMAKE_INSTALL_RPATH=/usr/lib/libsurvive/plugins
	cmake --build build
}

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

	install -Dm644 useful_files/81-vive.rules "$pkgdir"/usr/lib/udev/rules.d/81-vive.rules
	install -Dm644 survive_autocomplete.sh "$pkgdir"/usr/share/bash-completion/completions/survive
}

web() {
	depends="$pkgname websocketd"
	mkdir -p "$subpkgdir"/usr/share/webapps
	cp -r "$builddir"/tools/viz "$subpkgdir"/usr/share/webapps/survive-viz

	amove usr/bin/survive-websocketd
}

sha512sums="
6033d2524581bdefb0e1ed6e27c8044ba6ff32aa997845124c0b29d1a5a3f082a50605b2b654a642051ad0f22c6c8ad4ea8ca98888e28443d52ab68eb566effc  libsurvive-v1.01-source.zip
35ec5f53027fcf69ce335794f5b3e01421bb9d2ffbfec571703cdd136216f3f85794774b788cccd844ca9a803a605b5d6d7124b9d49767ea0614c6b2c869791b  off64_t.patch
c838efca5cdaabac903b435a50859232903723cc30a992755029e4c2fac3a2793f6eb866a1c95650c075c1da0ba9def917cffddb7ce10948aa213ed1cb79d8ac  sciplot-0.3.0.patch
"
