SUMMARY="Cross-platform port of Arx Fatalis, a first-person role-playing game"
DESCRIPTION="Arx Libertatis is a cross-platform, open source port of Arx Fatalis, \
a 2002 first-person role-playing game/dungeon crawler developed by Arkane Studios. \
Arx Fatalis features crafting, melee and ranged combat, as well as a unique casting \
system where the player draws runes in real time to effect the desired spell. \
Arx Libertatis updates and improves Arx Fatalis by supporting modern systems, \
porting the game to new systems as well as eliminating bugs and limitations."
HOMEPAGE="https://arx-libertatis.org/"
COPYRIGHT="2012-2021 Arx-Libertatis team"
LICENSE="GNU GPL v3"
REVISION="3"
SOURCE_URI="https://github.com/arx/ArxLibertatis/releases/download/$portVersion/arx-libertatis-$portVersion.tar.xz"
CHECKSUM_SHA256="bacf7768c4e21c9166c7ea57083d4f20db0deb8f0ee7d96b5f2829e73a75ad0c"
SOURCE_DIR="arx-libertatis-$portVersion"
srcGitRev2="68b5907feff0dda72fe5435e1108ccd2ad7e8ed5"
SOURCE_URI_2="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="e564291d665ad3c9bb329e6849ab399d1ce0cbc59bd47bcc15a22f3c6e9345a1"
SOURCE_DIR_2="BeGameLauncher-$srcGitRev2"
PATCHES="arx_libertatis-$portVersion.patchset"
ADDITIONAL_FILES="arx_libertatis.rdef"

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

PROVIDES="
	arx_libertatis$secondaryArchSuffix = $portVersion
	app:ArxLibertatis
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_filesystem$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:glm
	devel:libboost_filesystem$secondaryArchSuffix
	devel:libboost_system$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:python
	"

BUILD()
{
	#disable c++11 thread_local
	sed -e '/check_cxx11("thread_local"/ s/^#*/#/' -i CMakeLists.txt

	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Arx-Libertatis \
		-DCMAKE_INSTALL_BINDIR=$appsDir/Arx-Libertatis \
		-DCMAKE_INSTALL_LIBDIR=$appsDir/Arx-Libertatis/lib \
		-DCMAKE_INSTALL_DATAROOTDIR=$appsDir/Arx-Libertatis \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2 \
		-DUSER_DIR="ArxLibertatis" \
		-DUSER_DIR_PREFIXES=`finddir B_USER_SETTINGS_DIRECTORY`/ \
		-DCONFIG_DIR="ArxLibertatis" \
		-DCONFIG_DIR_PREFIXES=`finddir B_USER_SETTINGS_DIRECTORY`/ \
		-DDATA_DIR="games/arx:arx" \
		-DDATA_DIR_PREFIXES="$appsDir/Arx-Libertatis/" \
		-DBUILD_TOOLS=OFF \
		-DBUILD_IO_LIBRARY=OFF \
		-DBUILD_CRASHHANDLER=OFF \
		-DBUILD_CRASHREPORTER=OFF \
		-DBUILD_PROFILER=OFF \
		-DBUILD_TESTS=OFF \
		-DUNITY_BUILD=OFF
	make $jobArgs

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

INSTALL()
{
	cd build
	make install

	strip $appsDir/Arx-Libertatis/arx
	mv $appsDir/Arx-Libertatis/arx $appsDir/Arx-Libertatis/Arx-Libertatis
	rm -rf $appsDir/Arx-Libertatis/{applications,blender,include,man}

	cp $sourceDir2/build/ArxLibertatisLauncher $appsDir/Arx-Libertatis/Arx-Libertatis-Launcher

	settype -t application/x-vnd.Be-elfexecutable $appsDir/Arx-Libertatis/Arx-Libertatis
	rc $portDir/additional-files/arx_libertatis.rdef -o arx_libertatis.rsrc
	resattr -o $appsDir/Arx-Libertatis/Arx-Libertatis arx_libertatis.rsrc

	addAppDeskbarSymlink $appsDir/Arx-Libertatis/Arx-Libertatis-Launcher "Arx-Libertatis"
}
