SUMMARY="An open-source reconstruction of Diablo"
DESCRIPTION="DevilutionX is a new effort of an open-source re-implementation \
of Blizzard's Diablo game from 1996.

To play, you'll need the file 'diabdat.mpq' from the original Diablo CD.
Visit the homepage for more info, a FAQ, controller mappings, etc."
HOMEPAGE="https://github.com/diasurgical/devilutionX"
COPYRIGHT="2018 GalaXyHaXz"
LICENSE="Public Domain"
REVISION="1"
SOURCE_URI="https://github.com/diasurgical/devilutionX/archive/$portVersion.zip"
CHECKSUM_SHA256="b235724e4c7128661898bf571e290e42a4f4afd5102d70a05cdbf08632e13a35"
SOURCE_DIR="devilutionX-$portVersion"
ADDITIONAL_FILES="devilutionx.sh"

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

USER_SETTINGS_FILES="
	settings/diasurgical/devilution/diablo.ini
	"

PROVIDES="
	devilutionx$secondaryArchSuffix = $portVersion
	app:devilutionx$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_mixer_2.0$secondaryArchSuffix
	lib:libSDL2_ttf$secondaryArchSuffix
	lib:libsodium$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libsdl2$secondaryArchSuffix
	devel:libSDL2_mixer_2.0$secondaryArchSuffix
	devel:libSDL2_ttf$secondaryArchSuffix
	devel:libsodium$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage devilutionx$secondaryArchSuffix \
	$appsDir/DevilutionX/devilutionx

BUILD()
{
	mkdir -p build && cd build
	cmake .. \
		-DASAN=OFF \
		-DUBSAN=OFF \
		-DDEBUG=OFF \
		-DDIST=OFF \
		-DDISABLE_LTO=ON \
		-DCMAKE_BUILD_TYPE=Release \
		-DVERSION_NUM=$portVersion
	make $jobArgs
}

INSTALL()
{
	cd build

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="0"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		../Packaging/haiku/devilutionX.rdef.in > devilutionx.rdef

	addResourcesToBinaries devilutionx.rdef devilutionx

	mkdir -p $appsDir/DevilutionX
	cp devilutionx $appsDir/DevilutionX

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

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

	addAppDeskbarSymlink $appsDir/DevilutionX/devilutionx.sh "DevilutionX"
}
