SUMMARY="A single-player 2D action role playing game"
DESCRIPTION="Flare is a single-player 2D action RPG with fast-paced action \
and a dark fantasy style."
HOMEPAGE="https://flarerpg.org"
COPYRIGHT="2010-2021 Clint Bellanger"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/flareteam/flare-engine/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="035ffd936d9e120dc2eb792779a0b7ff64574d4a29a1124946deaf7946d1059d"
SOURCE_DIR="flare-engine-$portVersion"
PATCHES="flare-$portVersion.patchset"
ADDITIONAL_FILES="flare.rdef.in"

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

PROVIDES="
	flare$secondaryArchSuffix = $portVersion
	app:Flare$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	flare_data
	haiku$secondaryArchSuffix
	lib:libsdl2_2.0$secondaryArchSuffix
	lib:libsdl2_image_2.0$secondaryArchSuffix
	lib:libsdl2_mixer_2.0$secondaryArchSuffix
	lib:libsdl2_ttf_2.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libsdl2_2.0$secondaryArchSuffix
	devel:libsdl2_image_2.0$secondaryArchSuffix
	devel:libsdl2_mixer_2.0$secondaryArchSuffix
	devel:libsdl2_ttf_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2 \
		-DSDL2_IMAGE_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2 \
		-DSDL2_MIXER_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2 \
		-DSDL2_TTF_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2

	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir $dataDir/flare
	cp build/flare $appsDir/Flare
	cp -r mods $dataDir/flare

	local APP_SIGNATURE="application/x-vnd.flare"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/flare.rdef.in > $sourceDir/flare.rdef

	addResourcesToBinaries  $sourceDir/flare.rdef $appsDir/Flare
	addAppDeskbarSymlink $appsDir/Flare
}
