SUMMARY="A cross-platform chess game"
DESCRIPTION="Qt-based chess application + engine \"gupta\""
HOMEPAGE="https://sourceforge.net/projects/gambitchess/"
COPYRIGHT="Jelle Geerts"
LICENSE="CC0-1.0"
REVISION="1"
SOURCE_URI="https://sourceforge.net/projects/gambitchess/files/Gambit-$portVersion/Gambit-$portVersion-src.tar.gz"
CHECKSUM_SHA256="b07645d8fc43c2c37769469aceef8929819db00191fe15c28f59fbe644acacbc"
SOURCE_DIR="Gambit-$portVersion-src"
PATCHES="gambit-$portVersion.patchset"
ADDITIONAL_FILES="gambit.rdef.in"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

PROVIDES="
	gambit$secondaryArchSuffix = $portVersion
	app:Gambit = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:make
	"

BUILD()
{
	cmake . \
		-DCONFIG_ENABLE_UPDATE_CHECKER=OFF \
		-DCONFIG_GUPTA_ENGINE_DIRECTORY=$appsDir/Gambit/engine/ \
		-DCONFIG_RESOURCE_PATH_PREFIX=$appsDir/Gambit/data/
	make $jobArgs

	cd engine/gupta
	make -f GNUmakefile
}

INSTALL()
{
	mkdir -p $appsDir/Gambit/engine
	cp gambitchess $appsDir/Gambit/Gambit
	cp engine/gupta/gupta $appsDir/Gambit/engine
	cp -rf data $appsDir/Gambit

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

	addResourcesToBinaries  $sourceDir/gambit.rdef \
		$appsDir/Gambit/Gambit
	mimeset -f $appsDir/Gambit/Gambit
	addAppDeskbarSymlink $appsDir/Gambit/Gambit
}
