SUMMARY="Community-maintained Star Wars Jedi Knight II: Jedi Outcast, story version"
DESCRIPTION="OpenJK is an effort by the JACoders group to maintain and improve the \
game engines on which the Jedi Academy (JA) and Jedi Outcast (JO) games run on, while \
maintaining full backwards compatibility with the existing games. This project does \
not attempt to rebalance or otherwise modify core gameplay.

Our aims are to:
* Improve the stability of the engine by fixing bugs and improving performance.
* Provide a clean base from which new JO and JA code modifications can be made.

Make available this engine to more operating systems.
Currently, the most stable portion of this project is the Jedi Academy multiplayer code, \
with the single player code in a reasonable state.

Rough support for Jedi Outcast single player is also available, however this should be \
considered heavily work in progress. This is not currently actively worked on or tested. \
OpenJK does not have Jedi Outcast multiplayer support."
HOMEPAGE="https://github.com/JACoders/OpenJK"
COPYRIGHT="2003 Activision"
LICENSE="GNU GPL v2"
REVISION="4"
srcGitRev="52030235f052772008d99e6ccb16de48e7ddb688"
SOURCE_URI="https://github.com/JACoders/OpenJK/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="2b6fadf16cca2fdf4cce32f977e0d0aa34e2a19d1c596b996f9857b6a97c7d32"
SOURCE_DIR="OpenJK-$srcGitRev"
srcGitRev2="68b5907feff0dda72fe5435e1108ccd2ad7e8ed5"
SOURCE_URI_2="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="e564291d665ad3c9bb329e6849ab399d1ce0cbc59bd47bcc15a22f3c6e9345a1"
SOURCE_DIR_2="BeGameLauncher-$srcGitRev2"
PATCHES="openjk_outcast-$portVersion.patchset"
ADDITIONAL_FILES="openjk_outcast.rdef.in"

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

PROVIDES="
	openjk_outcast$secondaryArchSuffix = $portVersion
	app:JediOutcast$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libsdl2_2.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgl$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libsdl2_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build

	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir/JediOutcast \
		-DUseInternalZlib=ON \
		-DUseInternalPNG=ON \
		-DUseInternalJPEG=ON \
		-DBuildJK2SPEngine=ON \
		-DBuildJK2SPGame=ON \
		-DBuildJK2SPRdVanilla=ON \
		-DBuildMPCGame=OFF \
		-DBuildMPDed=OFF \
		-DBuildMPEngine=OFF \
		-DBuildMPGame=OFF \
		-DBuildMPRdVanilla=OFF \
		-DBuildMPUI=OFF \
		-DBuildSPEngine=OFF \
		-DBuildSPGame=OFF \
		-DBuildSPRdVanilla=OFF \
		-DBuildTests=OFF
	make $jobArgs

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

INSTALL()
{
	cd build

	mkdir -p $appsDir/JediOutcast/lib

	cp openjo_sp.* $appsDir/JediOutcast/JediOutcast
	cp code/rd-vanilla/*.so $appsDir/JediOutcast/lib
	cp codeJK2/game/*.so $appsDir/JediOutcast/lib
	cp $sourceDir2/build/JediOutcastLauncher $appsDir/JediOutcast

	local APP_SIGNATURE="application/x-vnd.JediOutcast"
	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/openjk_outcast.rdef.in > $sourceDir/build/openjk_outcast.rdef

	addResourcesToBinaries $sourceDir/build/openjk_outcast.rdef $appsDir/JediOutcast/JediOutcast

	addAppDeskbarSymlink $appsDir/JediOutcast/JediOutcastLauncher "StarWars Jedi Knight II: Jedi Outcast"
}
