SUMMARY="Seven Kingdoms: Ancient Adversaries"
DESCRIPTION="Seven Kingdoms, designed by Trevor Chan, brings a unique blend of Real-Time Strategy \
with the addition of trade, diplomacy, and espionage.

The game enables players to compete against up to six other kingdoms allowing players to \
conquer opponents by defeating them in war (with troops or machines), capturing their \
buildings with spies, or offering opponents money for their kingdom."
HOMEPAGE="https://www.7kfans.com/"
COPYRIGHT="Enlight Software Ltd."
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/the3dfxdude/7kaa/releases/download/v2.15.4p1/7kaa-2.15.4p1.tar.xz"
CHECKSUM_SHA256="f0265c077025d77b435f1c10b8ba178bdb16329e51ab735330ebaa71a104fbf8"
PATCHES="7kaa-2.15.4p1.patchset"
ADDITIONAL_FILES="7kaa.rdef.in"

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

PROVIDES="
	7kaa$secondaryArchSuffix
	app:SevenKingdoms
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libenet$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:curl_config$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libenet$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:g++$secondaryArchSuffix
	cmd:make
	"

BUILD() {
	# for some reason the configure script doesn't find these variables by itself
	CURL_CFLAGS=$(curl-config --cflags)
	CURL_LIBS=$(curl-config --libs)
	export CURL_CFLAGS
	export CURL_LIBS
	
	runConfigure ./configure pkgdatadir=$dataDir/7kaa
	make $jobArgs
	make install
}

INSTALL() {
	# prepare the rdef file
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3 | cut -dp -f1`"
	local SHORT_INFO="$SUMMARY"
	local LONG_INFO="$SUMMARY"
	
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@SHORT_INFO@|$SHORT_INFO|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/7kaa.rdef.in > $portDir/7kaa.rdef
	
	mkdir -p $appsDir
	mkdir -p $dataDir
	
	mv data/ $dataDir/7kaa
	
	mv $binDir/7kaa $appsDir/"Seven Kingdoms"
	
	addResourcesToBinaries $portDir/7kaa.rdef $appsDir/"Seven Kingdoms"
	addAppDeskbarSymlink $appsDir/"Seven Kingdoms"
	
}
