SUMMARY="Mind-altering retro voxel-sandbox game"
DESCRIPTION="Vangers was originally released in 1998 and now we present you with \
the special reworked edition of the game with improved performance on modern \
operating systems. Game still runs in 800x600 resolution though, as it was intended to do. \
KranX Productions pledged Vangers to go open source under the GPLv3 on March 12, 2016."
HOMEPAGE="https://kranx.com"
COPYRIGHT="1998-2021 KranX Productions, K-D Lab"
LICENSE="GNU GPL v3"
REVISION="1"
srcGitRev="470654b738761a63546ef0fa625f85f79daa72fa"
SOURCE_URI="https://github.com/KranX/Vangers/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="95dc228a78d0ecc9496f8cf5959e56ea479287dbf8aeef43aeec200920062ed0"
SOURCE_DIR="Vangers-$srcGitRev"
srcGitRev2="6d4cbbe1b6f1e202b9945d20073952b254e8d530"
SOURCE_URI_2="https://github.com/stalkerg/clunk/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="a9ee979190530367ff3b48c50876c56c4c7e91e29d4e0a2ce956a12954466ea1"
SOURCE_DIR_2="clunk-$srcGitRev2"
srcGitRev3="558599f4761613559bc54eb54b8a5b04f24270ea"
SOURCE_URI_3="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev3.tar.gz"
CHECKSUM_SHA256_3="5435c273ad8f54f75fec3db1aaeafb4a5d1a821cc15ae256dedc054bc195f4f1"
SOURCE_DIR_3="BeGameLauncher-$srcGitRev3"
ADDITIONAL_FILES="vangers.rdef"

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

PROVIDES="
	vangers$secondaryArchSuffix = $portVersion
	app:vangers$secondaryArchSuffix
	"

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_net_2.0$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	ffmpeg${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libSDL2_net_2.0$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	cd $sourceDir2
	cmake . \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_CXX_FLAGS="`sdl2-config --cflags` -D__unix__"
	make $jobArgs
	cd ..
	rm -f clunk
	ln -s $sourceDir2 clunk

	cd $sourceDir
	mkdir -p build
	cd build
	cmake .. \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir \
		-DCLUNK_INCLUDE_DIR="$sourceDir2" \
		-DCLUNK_LIBRARY="$sourceDir2/libclunk.so" \
		-DCMAKE_BUILD_TYPE=Release \
		-DBINARY_SCRIPT=On \
		-DCMAKE_CXX_FLAGS="`sdl2-config --cflags` -D__unix__ -I$sourceDir2/../"
	make $jobArgs

	cd $sourceDir3
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DLAUNCHER=vangers
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/Vangers/engine/lib

	cd build
	cp src/vangers $appsDir/Vangers/engine/Vangers
	cd ..

	cp $sourceDir2/libclunk.so $appsDir/Vangers/engine/lib

	cp $sourceDir3/build/VangersLauncher $appsDir/Vangers/VangersLauncher

	settype -t application/x-vnd.Be-elfexecutable $appsDir/Vangers/engine/Vangers
	rc $portDir/additional-files/vangers.rdef -o vangers.rsrc
	resattr -o $appsDir/Vangers/engine/Vangers vangers.rsrc

	addAppDeskbarSymlink $appsDir/Vangers/VangersLauncher
}
