# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: William Pitcock <nenolod@dereferenced.org>
# Maintainer:
pkgname=xonotic
pkgver=0.8.1
pkgrel=0
pkgdesc="Game engine for Xonotic (quake1/nexuiz derivative)"
url="http://www.xonotic.org/"
arch="x86 x86_64"
license="GPL-2.0-or-later"
depends="xonotic-data"
depends_dev=""
makedepends="sdl-dev mesa-dev jpeg-dev libvorbis-dev libxpm-dev libxxf86dga-dev
	libxxf86vm-dev libmodplug-dev libpng-dev alsa-lib-dev"
install=""
subpackages="$pkgname-glx $pkgname-sdl"
source="$pkgname-$pkgver.zip::http://dl.xonotic.org/${pkgname}-${pkgver}-source.zip
	xonotic-moncontrol.patch"

builddir="$srcdir"/Xonotic
build() {
	# msg "building Xonotic-patched QuakeC compiler"
	# make -C "$builddir"/source/fteqcc CPUOPTIMIZATIONS="${CFLAGS}"

	local r
	for r in sv cl sdl; do
		make -C "$builddir"/source/darkplaces \
			CPUOPTIMIZATIONS="$CFLAGS" \
			DP_FS_BASEDIR="/usr/share/$pkgname" \
			DP_LINK_TO_LIBJPEG=1 \
			$r-release || return 1
	done
}

package() {
	mkdir -p "$pkgdir"/usr/bin
	install -Dm755 "$builddir"/source/darkplaces/darkplaces-dedicated \
		"$pkgdir"/usr/bin/xonotic-dedicated || return 1
}

sdl() {
	pkgdesc="$pkgdesc (SDL client)"
	mkdir -p "$subpkgdir"/usr/bin
	install -Dm755 "$builddir"/source/darkplaces/darkplaces-sdl \
		"$subpkgdir"/usr/bin/xonotic-sdl || return 1
}

glx() {
	pkgdesc="$pkgdesc (GLX client)"
	mkdir -p "$subpkgdir"/usr/bin
	install -Dm755 "$builddir"/source/darkplaces/darkplaces-glx \
		"$subpkgdir"/usr/bin/xonotic-glx || return 1
}

md5sums="8890191a21d2ea7b64447eee58b29f9f  xonotic-0.8.1.zip
67b56ab2676cbc76c015fc889d7c23e3  xonotic-moncontrol.patch"
sha256sums="c212e31fc1de2c0b49e439e222520a424daa15e87f92a526d9a0f52d0f6c62be  xonotic-0.8.1.zip
b745ba7c58f3c18b53464f6142c1c4552bda1c131b796453c633b4a91892040e  xonotic-moncontrol.patch"
sha512sums="50449e401672bee8cf90072c5d223d6e40548085dddee5101fd8cbe89cc892bdc25acfce755c6128feaccde449f1dd8e598457359e4dcbb3b49d9aed02c28716  xonotic-0.8.1.zip
d74a1d1421dc68dbf46595510cea463382e69c8421110cd7b187419530dbfe9d262d9b65843b89b49aa91d9e32041e11941e411fe52f2dcb0ede18311ab821ec  xonotic-moncontrol.patch"
