SUMMARY="A strong chess engine, among the strongest in the world"
DESCRIPTION="Stockfish is a free UCI chess engine derived from Glaurung 2.1. It \
is not a complete chess program and requires some UCI-compatible GUI (e.g. \
XBoard with PolyGlot, eboard, Arena, Sigma Chess, Shredder, ChessPartner or \
Fritz) in order to be used comfortably. Read the documentation for your GUI of \
choice for information about how to use Stockfish with it."
HOMEPAGE="https://www.stockfishchess.org/"
COPYRIGHT="2004-2008 Tord Romstad (Glaurung author)
	2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
	2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/official-stockfish/Stockfish/archive/sf_$portVersion.tar.gz"
CHECKSUM_SHA256="d0f33765376b381868d13cc8bfd4e1fa51040074b7ab388cc93b613dd88f67c4"
SOURCE_FILENAME="stockfish-$portVersion.tar.gz"
SOURCE_DIR="Stockfish-sf_$portVersion"

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

if [ "$targetArchitecture" != x86_gcc2 ]; then
	commandSuffix=$secondaryArchSuffix
	commandBinDir=$binDir
else
	commandSuffix=
	commandBinDir=$prefix/bin
fi
case "$effectiveTargetArchitecture" in
	x86) commandArch=x86-32;;
	x86_64) commandArch=x86-64;;
	arm) commandArch=armv7;;
	ppc) commandArch=ppc-32;;
esac

PROVIDES="
	stockfish$secondaryArchSuffix = $portVersion
	cmd:stockfish$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

BUILD()
{
	make -C src build ARCH=$commandArch
}

INSTALL()
{
	install -d $docDir
	install -t $docDir AUTHORS Readme.md

	make -C src install BINDIR=$commandBinDir
}

TEST()
{
	test `src/stockfish bench 2>&1 1>/dev/null \
		| sed -n -e "s/^Nodes searched *: *//p"` \
		-eq 5023629
}
