SUMMARY="XBoard-compatible 3D chess interface and engine"
DESCRIPTION="DreamChess is an open source chess game. Our primary target \
platforms are Windows, macOS and Linux. DreamChess features 3D OpenGL \
graphics and provides various chess board sets, ranging from classic wooden \
to flat figurines.

A moderately strong chess engine is included: Dreamer. However, should this \
engine be too weak for you, then you can use any other XBoard-compatible \
chess engine, including the popular Crafty and GNU Chess.

Other features include music, sound effects, on-screen move lists using SAN \
notation, undo functionality, and savegames in PGN format.

The DreamChess team currently consists of only a handful of people. We could \
use help in many areas, such as programming, graphics, sound and testing. If \
you’re interested in helping out, please send an email to feedback at \
dreamchess.org."
HOMEPAGE="https://www.dreamchess.org/"
COPYRIGHT="2003-2007 Andrew Ball, Annie Kirkpatrick, Brandon May, Kris McAulay, \
Walter van Niftrik, Rogier van Schaijk, Lawrence Sebald, Matthew P. Smith
	1991-1993 The Regents of the University of California
	1998-2005 Gilles Vollant"
LICENSE="GNU GPL v3"
REVISION="5"
SOURCE_URI="https://github.com/dreamchess/dreamchess/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="b070a34acf69ed92e523902683d104abb295d78b6f37663f4668e929b9e90470"
PATCHES="dreamchess-$portVersion.patchset"
ADDITIONAL_FILES="dreamchess.rdef.in"

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

PROVIDES="
	dreamchess$secondaryArchSuffix = $portVersion
	app:DreamChess$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libmxml$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_image_2.0$secondaryArchSuffix
	lib:libSDL2_mixer_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexpat$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix
	devel:libmxml$secondaryArchSuffix
	devel:libSDL2$secondaryArchSuffix
	devel:libSDL2_image$secondaryArchSuffix
	devel:libSDL2_mixer$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:bison
	cmd:cmake
	cmd:find
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir/DreamChess \
		-DCMAKE_INSTALL_BINDIR=$appsDir/DreamChess \
		-DCMAKE_INSTALL_MANDIR=$appsDir/DreamChess/man \
		-DCMAKE_INSTALL_DOCDIR=$appsDir/DreamChess/doc \
		-DCMAKE_INSTALL_FULL_DATADIR=$appsDir/DreamChess/data \
		-DCMAKE_INSTALL_DATAROOTDIR=$appsDir/DreamChess/data \
		-DCMAKE_INSTALL_DATADIR=$appsDir/DreamChess/data
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mv $appsDir/DreamChess/dreamchess $appsDir/DreamChess/DreamChess
	rm -rf $appsDir/DreamChess/{man,data/applications,data/icons}

	local APP_SIGNATURE="application/x-vnd.DreamChess"
	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/dreamchess.rdef.in > dreamchess.rdef

	addResourcesToBinaries dreamchess.rdef $appsDir/DreamChess/DreamChess
	addAppDeskbarSymlink $appsDir/DreamChess/DreamChess DreamChess
}
