SUMMARY="A port of Jagged Alliance 2 to SDL"
DESCRIPTION="The goal of the project is to make Jagged Alliance 2 available on \
a wide range of platforms, improve its stability, fix bugs and provide a \
stable  platform for mod development. Moddability is still in the early stages.

Data files from the original game are still required and will be used by \
JA2-Stracciatella."
HOMEPAGE="https://ja2-stracciatella.github.io/"
COPYRIGHT="2004 Strategy First Inc."
LICENSE="SFI-SCLA"
REVISION="1"
SOURCE_URI="https://github.com/ja2-stracciatella/ja2-stracciatella/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="750c56b7011479dc89ce1f57f3da551d856a75eb87b545bc655dcbb87c42ba43"
SOURCE_DIR="ja2-stracciatella-$portVersion"
PATCHES="ja2_stracciatella-$portVersion.patchset"
ADDITIONAL_FILES="
	ja2_stracciatella.rdef.in
	ja2_stracciatella.sh
"

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

PROVIDES="
	ja2_stracciatella$secondaryArchSuffix = $portVersion
	cmd:ja2$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_filesystem$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_filesystem$secondaryArchSuffix
	devel:libboost_system$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:python2
	cmd:rustc
	cmd:sed
	cmd:wget
	"

defineDebugInfoPackage ja2_stracciatella$secondaryArchSuffix \
	$appsDir/JA2/bin/ja2

BUILD()
{
	mkdir -p haiku_build && cd haiku_build
	cmake .. \
		-DSDL2_INCLUDE_DIR="$portPackageLinksDir/devel~libsdl2_2.0/$relativeIncludeDir/SDL2" \
		-DLOCAL_GTEST_LIB=OFF \
		-DWITH_UNITTESTS=OFF \
		-DCMAKE_INSTALL_PREFIX="$appsDir/JA2"

	make $jobArgs
}

INSTALL()
{
	cd haiku_build
	make install

	# Preparing the attributes
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/ja2_stracciatella.rdef.in \
			> ja2_stracciatella.rdef

	# Installing start-script
	cp $portDir/additional-files/ja2_stracciatella.sh \
		$appsDir/JA2
	chmod +x $appsDir/JA2/ja2_stracciatella.sh

	# Installing extra-attribs
	rc ja2_stracciatella.rdef
	resattr -o $appsDir/JA2/ja2_stracciatella.sh \
		ja2_stracciatella.rsrc

	addResourcesToBinaries ja2_stracciatella.rdef \
		$appsDir/JA2/bin/ja2

	# Creating Deskbar-link
	addAppDeskbarSymlink $appsDir/JA2/ja2_stracciatella.sh \
		"Jagged Alliance 2"

	# Cleanup
	mkdir -p $manDir
	mv $appsDir/JA2/share/man/* $manDir
	mv $appsDir/JA2/share/ja2/* $appsDir/JA2/bin
	rm -rf $appsDir/JA2/share
	ln -s $appsDir/JA2/lib $appsDir/JA2/bin
}
