SUMMARY="A retro multiplayer shooter"
DESCRIPTION="Teeworlds is a free online multiplayer game, available for \
all major operating systems. Battle with up to 16 players in a variety of \
game modes, including Team Deathmatch and Capture The Flag. You can even \
design your own maps!"
HOMEPAGE="https://www.teeworlds.com"
COPYRIGHT="2007-2021 Magnus Auvinen"
LICENSE="Zlib"
REVISION="2"
SOURCE_URI="https://downloads.teeworlds.com/teeworlds-$portVersion-src.tar.gz"
CHECKSUM_SHA256="fcde2223398e027434ec96315103e9861fc458161b49b15908dc56b8e7a8ecd9"
SOURCE_DIR="teeworlds-$portVersion-src"
PATCHES="teeworlds-$portVersion.patchset"
ADDITIONAL_FILES="teeworlds.rdef.in"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	teeworlds$secondaryArchSuffix = $portVersion
	app:Teeworlds = $portVersion
	cmd:teeworlds_srv = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Teeworlds \
		-DCMAKE_BUILD_TYPE=Release
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mkdir -p $prefix/bin
	mv $appsDir/Teeworlds/bin/teeworlds $appsDir/Teeworlds/Teeworlds
	mv $appsDir/Teeworlds/bin/teeworlds_srv $appsDir/Teeworlds
	mv $appsDir/Teeworlds/share/teeworlds/data/* $appsDir/Teeworlds
	rm -rf $appsDir/Teeworlds/{bin,share}

	cat >$prefix/bin/teeworlds_srv << EOF
#!/bin/bash
cd $appsDir/Teeworlds
teeworlds_srv "$@"
EOF
	chmod +x $prefix/bin/teeworlds_srv

	local APP_SIGNATURE="application/x-vnd.teeworlds"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/teeworlds.rdef.in > $sourceDir/teeworlds.rdef

	addResourcesToBinaries  $sourceDir/teeworlds.rdef \
		$appsDir/Teeworlds/Teeworlds
	addAppDeskbarSymlink $appsDir/Teeworlds/Teeworlds
}
