SUMMARY="An open-source port of Prince of Persia"
DESCRIPTION="SDLPoP is an open-source port of Prince of Persia that runs natively on Windows and Linux. \
It is based on a disassembly of the DOS version, and uses SDL."
HOMEPAGE="https://www.princed.org/"
COPYRIGHT="Dávid Nagy"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/NagyD/SDLPoP/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="1af170f7f6def61b2ab9c3a9227feca335461d224faa99f3578fc09115ac505c"
SOURCE_DIR="SDLPoP-$portVersion"
PATCHES="sdlpop-$portVersion.patchset"
ADDITIONAL_FILES="sdlpop.rdef.in"

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

GLOBAL_WRITABLE_FILES="
	settings/SDLPoP/SDLPoP.ini keep-old
	settings/SDLPoP/SDLPoP.cfg keep-old
	"

PROVIDES="
	sdlpop$secondaryArchSuffix = $portVersion
	app:SDLPop$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_image_2.0${secondaryArchSuffix}
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libSDL2_image_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	cd src
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/SDLPoP $settingsDir/SDLPoP
	cp -rf data doc mods $appsDir/SDLPoP
	cp prince "$appsDir/SDLPoP/Prince of Persia"

	cp SDLPoP.ini $settingsDir/SDLPoP
	touch $settingsDir/SDLPoP/SDLPoP.cfg

	ln -s $settingsDir/SDLPoP/SDLPoP.cfg \
		$appsDir/SDLPoP/SDLPoP.cfg
	ln -s $settingsDir/SDLPoP/SDLPoP.ini \
		$appsDir/SDLPoP/SDLPoP.ini

	local APP_SIGNATURE="application/x-vnd.sdlpop"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="0"
	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/sdlpop.rdef.in > $sourceDir/sdlpop.rdef

	addResourcesToBinaries  $sourceDir/sdlpop.rdef \
		"$appsDir/SDLPoP/Prince of Persia"
	addAppDeskbarSymlink "$appsDir/SDLPoP/Prince of Persia"
}
