SUMMARY="Open-source clone of Dune II: The Battle for Arrakis"
DESCRIPTION="An open source re-creation of the popular game \"Dune II\", \
originally made by Westwood Studios, and released by Virgin Entertainment.
It attempts to re-create the original game and apply modern technology to \
it to allow it to be run natively on most operating systems.

Please note that you must provide the original Dune II 1.07 data files in \
/boot/home/config/non-packaged/data/opendune directory \
for the game to run properly."
HOMEPAGE="http://www.opendune.org/"
COPYRIGHT="2009-2018 OpenDUNE Developers"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://github.com/OpenDUNE/OpenDUNE/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="8d5ed67669df1f17a44c097d9b6bee4e0623ce2a37f11938ce9cd77de546d06c"
SOURCE_FILENAME="OpenDUNE-$portVersion.tar.gz"
SOURCE_DIR="OpenDUNE-$portVersion"
PATCHES="opendune-$portVersion.patchset"
ADDITIONAL_FILES="opendune.rdef"

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

GLOBAL_WRITABLE_FILES="
	settings/opendune.ini keep-old
	"
USER_SETTINGS_FILES="
	settings/opendune directory
	settings/opendune/savegames directory
	settings/opendune/opendune.ini template settings/opendune.ini
	"

PROVIDES="
	opendune$secondaryArchSuffix = $portVersion
	app:OpenDUNE = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libSDL_image_1.2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	cmd:which
	"

BUILD()
{
	_dune2_data_dir=$(finddir B_USER_NONPACKAGED_DATA_DIRECTORY)/opendune

	export CFLAGS="-mmmx -DDUNE_DATA_DIR='\\\"${_dune2_data_dir}\\\"'"
	export LDFLAGS="-lstdc++"

	./configure \
		--disable-assert \
		--binary-name="OpenDUNE" \
		--install-dir="" \
		--binary-dir="${appsDir#/}" \
		--data-dir="${dataDir#/}/opendune" \
		--prefix-dir=""

	make $jobsArg V=1
}

INSTALL()
{
	mkdir -p $dataDir/opendune/

	make install DO_NOT_INSTALL_DOCS=1 DO_NOT_INSTALL_LICENSE=1

	sed  -e "s|the desired location|$(finddir B_USER_SETTINGS_DIRECTORY)\/opendune|g" \
		$sourceDir/bin/opendune.ini.sample > $sourceDir/bin/opendune.ini.tmp \
		&& mv $sourceDir/bin/opendune.ini.tmp $sourceDir/bin/opendune.ini.sample
	sed  -e "s|;savedir=\/home\/user\/.config\/opendune|savedir=$(finddir B_USER_SETTINGS_DIRECTORY)\/opendune/savegames|g" \
		$sourceDir/bin/opendune.ini.sample > $sourceDir/bin/opendune.ini.tmp \
		&& mv $sourceDir/bin/opendune.ini.tmp $sourceDir/bin/opendune.ini.sample

	cp $sourceDir/bin/opendune.ini.sample $settingsDir/opendune.ini

	cp $sourceDir/bundle/*.txt $dataDir/opendune
	cp $sourceDir/bundle/COPYING $dataDir/opendune

	addResourcesToBinaries $portDir/additional-files/opendune.rdef $appsDir/OpenDUNE
	addAppDeskbarSymlink $appsDir/OpenDUNE OpenDUNE
}
