SUMMARY="An original engine for Serious Sam Classic games"
DESCRIPTION="The Serious Engine lets you run the Serious Sam Classic: The First Encounter \
and the Serious Sam Classic: The Second Encounter games. In addition, custom game mods \
are supported also. Croteam pledged Serious Engine to go open source under the \
GPLv2 on March 11, 2016."
HOMEPAGE="http://www.croteam.com"
COPYRIGHT="2001-2016 Croteam, 2016 Ryan C. Gordon, 2017 ptitSeb, 2018 EXL"
LICENSE="GNU GPL v2"
REVISION="4"
srcGitRev="0f342ca13f814f2fd42f703bca5b10a01139cc81"
SOURCE_URI="https://github.com/EXLMOTODEV/Serious-Engine/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="24afc4a5c747140699c7f29b4d03b9884e512cd24d21ca63e4b57a6939969f1d"
SOURCE_DIR="Serious-Engine-$srcGitRev"
srcGitRev2="65546dd190d6168c0c06580c7e8cb7e7b4b198e7"
SOURCE_URI_2="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="7c9dc3f1331a89ad92c5a233e9a2f7cb559979d18d0b90519d592336f6dc06b7"
SOURCE_DIR_2="BeGameLauncher-$srcGitRev2"
ADDITIONAL_FILES="serious_sam.rdef"

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

PROVIDES="
	serious_sam$secondaryArchSuffix = $portVersion
	app:SeriousSam$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:flex
	cmd:bison
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	cd Sources
	mkdir -p build_tse ; cd build_tse
	cmake .. \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_CXX_FLAGS="`sdl2-config --cflags` -DPLATFORM_HAIKU=1 -DPLATFORM_UNIX=1 -w"
	make ecc
	make $jobArgs

	cd ..
	mkdir -p build_tfe ; cd build_tfe
	cmake .. \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir \
		-DCMAKE_BUILD_TYPE=Release \
		-DTFE=True \
		-DCMAKE_CXX_FLAGS="`sdl2-config --cflags` -DPLATFORM_HAIKU=1 -DPLATFORM_UNIX=1 -w"
	make ecc
	make $jobArgs

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

INSTALL()
{
	mkdir -p $appsDir/Serious/{tfe,tse}

	cp $sourceDir/Sources/build_tse/ssam $appsDir/Serious
	cp $sourceDir/Sources/build_tfe/ssam-tfe $appsDir/Serious
	cp $sourceDir/SE1_10.gro $appsDir/Serious
	cp -aR $sourceDir/Sources/build_tse/Debug/*.so $appsDir/Serious/tse
	cp -aR $sourceDir/Sources/build_tfe/Debug/*.so $appsDir/Serious/tfe

	cp $sourceDir2/build/SeriousLauncher "$appsDir/Serious/Serious Sam Classic"

	settype -t application/x-vnd.Be-elfexecutable $appsDir/Serious/ssam
	settype -t application/x-vnd.Be-elfexecutable $appsDir/Serious/ssam-tfe
	rc $portDir/additional-files/serious_sam.rdef -o serious_sam.rsrc
	resattr -o $appsDir/Serious/ssam serious_sam.rsrc
	resattr -o $appsDir/Serious/ssam-tfe serious_sam.rsrc

	addAppDeskbarSymlink "$appsDir/Serious/Serious Sam Classic"
}
