SUMMARY="Chess board program"
DESCRIPTION="KNights is a chess game. As a player, your goal is to defeat your opponent by checkmating their king.

Features:
* Local play between two players on the same computer
* Play against any computer program that supports the XBoard protocol
* Play on the Free Internet Chess Server (FICS)
* Watching two computer engines play against each other
* Support for legal move checking
* Markers for possible moves, opponent’s last move and sources of check
* Board borders and site notations
* Complete time control, with Plasma-styled clocks
* Several themes, with the possibility of downloading new ones from within the program
* Animated moves (configurable)
* Views for playing on a chess server, including a seek graph, text console, and chat widget
* Option to undo and redo moves
* Graphic interface for making and receiving offers from remote players
* Support for the UCI protocol (used by Stockfish, Chessbase, and many others)
* Support for saving and loading Portable game notation (PGN) files
* Use of Jovie, the KDE text-to-speak program, to speak opponent’s moves
* Ability to control the program via a D-Bus interface"
HOMEPAGE="https://apps.kde.org/en/knights"
COPYRIGHT="2010-2021 KDE Organisation"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://download.kde.org/stable/release-service/$portVersion/src/knights-$portVersion.tar.xz"
CHECKSUM_SHA256="1f2080d98e57a6bf748e8401ceb52d98232f3e1b6e844158386624fb75b4e26c"
SOURCE_DIR="knights-$portVersion"
ADDITIONAL_FILES="knights.rdef.in"

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

PROVIDES="
	knights$secondaryArchSuffix = $portVersion
	app:KNights$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:gnuchess
	cmd:stockfish
	lib:libKF5Archive$secondaryArchSuffix
	lib:libKF5Auth$secondaryArchSuffix
	lib:libKF5Bookmarks$secondaryArchSuffix
	lib:libKF5Codecs$secondaryArchSuffix
	lib:libKF5Completion$secondaryArchSuffix
	lib:libKF5ConfigCore$secondaryArchSuffix
	lib:libKF5ConfigGui$secondaryArchSuffix
	lib:libKF5ConfigWidgets$secondaryArchSuffix
	lib:libKF5CoreAddons$secondaryArchSuffix
	lib:libKF5Crash$secondaryArchSuffix
	lib:libKF5DBusAddons$secondaryArchSuffix
	lib:libKF5GuiAddons$secondaryArchSuffix
	lib:libKF5I18n$secondaryArchSuffix
	lib:libKF5IconThemes$secondaryArchSuffix
	lib:libKF5ItemViews$secondaryArchSuffix
	lib:libKF5KDEGames$secondaryArchSuffix
	lib:libKF5Package$secondaryArchSuffix
	lib:libKF5Plasma$secondaryArchSuffix
	lib:libKF5Plotting$secondaryArchSuffix
	lib:libKF5Service$secondaryArchSuffix
	lib:libKF5Solid$secondaryArchSuffix
	lib:libKF5SonnetUi$secondaryArchSuffix
	lib:libKF5TextEditor$secondaryArchSuffix
	lib:libKF5TextWidgets$secondaryArchSuffix
	lib:libKF5Wallet$secondaryArchSuffix
	lib:libKF5WidgetsAddons$secondaryArchSuffix
	lib:libKF5WindowSystem$secondaryArchSuffix
	lib:libKF5XmlGui$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	extra_cmake_modules$secondaryArchSuffix >= 5.86
	devel:libKF5Archive$secondaryArchSuffix
	devel:libKF5Auth$secondaryArchSuffix
	devel:libKF5Bookmarks$secondaryArchSuffix
	devel:libKF5Codecs$secondaryArchSuffix
	devel:libKF5Completion$secondaryArchSuffix
	devel:libKF5ConfigCore$secondaryArchSuffix
	devel:libKF5ConfigWidgets$secondaryArchSuffix
	devel:libKF5CoreAddons$secondaryArchSuffix
	devel:libKF5Crash$secondaryArchSuffix
	devel:libKF5DBusAddons$secondaryArchSuffix
	devel:libKF5DocTools$secondaryArchSuffix
	devel:libKF5GuiAddons$secondaryArchSuffix
	devel:libKF5I18n$secondaryArchSuffix
	devel:libKF5IconThemes$secondaryArchSuffix
	devel:libKF5ItemModels$secondaryArchSuffix
	devel:libKF5ItemViews$secondaryArchSuffix
	devel:libKF5JobWidgets$secondaryArchSuffix
	devel:libKF5KDEGames$secondaryArchSuffix
	devel:libKF5KIOCore$secondaryArchSuffix
	devel:libKF5Package$secondaryArchSuffix
	devel:libKF5Plasma$secondaryArchSuffix
	devel:libKF5Plotting$secondaryArchSuffix
	devel:libKF5Service$secondaryArchSuffix
	devel:libKF5Solid$secondaryArchSuffix
	devel:libKF5SonnetUi$secondaryArchSuffix
	devel:libKF5TextEditor$secondaryArchSuffix
	devel:libKF5TextWidgets$secondaryArchSuffix
	devel:libKF5Wallet$secondaryArchSuffix
	devel:libKF5WidgetsAddons$secondaryArchSuffix
	devel:libKF5WindowSystem$secondaryArchSuffix
	devel:libKF5XmlGui$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix >= 5.15
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	# disable docs generation
	sed -e '/add_subdirectory(doc)/ s/^#*/#/' -i CMakeLists.txt
	sed -e '/kdoctools_install(po)/ s/^#*/#/' -i CMakeLists.txt

	mkdir -p build
	cd build

	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir \
		-DCMAKE_INSTALL_DATADIR=$dataDir \
		-DCMAKE_INSTALL_DATAROOTDIR=$dataDir \
		-DSHARE_INSTALL_PREFIX=$dataDir \
		-DECM_DIR=/system/data/cmake/Modules/ECM/cmake
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mv $appsDir/bin/knights $appsDir/KNights
	rm -rf $appsDir/bin

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

	addResourcesToBinaries knights.rdef $appsDir/KNights
	addAppDeskbarSymlink $appsDir/KNights
}
