SUMMARY="A free multiplayer action game where you control small and nimble humanoids"
DESCRIPTION="OpenClonk is a multiplayer-action-tactics-skill game. \
It is often referred to as a mixture of The Settlers and Worms. In a \
simple 2D antfarm-style landscape, the player controls his crew of Clonks, \
small but robust humanoid beings. The game encourages free play but the \
normal goal is to either exploit valuable resources from the earth by \
building a mine or fight each other on an arena-like map."
HOMEPAGE="https://www.openclonk.org/"
COPYRIGHT="2009-2019 OpenClonk Team and contributors"
LICENSE="ISC"
REVISION="4"
srcGitRev="a080958de3b3f95edcc5756cdd2fe56adb0cf64f"
SOURCE_URI="https://github.com/openclonk/openclonk/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="30c0c71f22e586b5c0e2c60aceb210bf39e519c8779b83e495a5791db48a5929"
SOURCE_DIR="openclonk-$srcGitRev"
PATCHES="openclonk-$portVersion.patchset"
ADDITIONAL_FILES="openclonk.rdef.in"

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

PROVIDES="
	openclonk$secondaryArchSuffix = $portVersion
	app:OpenClonk$secondaryArchSuffix
	cmd:c4group$secondaryArchSuffix
	cmd:openclonk_server$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libalut$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgio_2.0$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libgthread_2.0$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_image_2.0$secondaryArchSuffix
	lib:libSDL2_mixer_2.0$secondaryArchSuffix
	lib:libtinyxml$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libalut$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgio_2.0$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgmodule_2.0$secondaryArchSuffix
	devel:libgobject_2.0$secondaryArchSuffix
	devel:libgthread_2.0$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libSDL2$secondaryArchSuffix
	devel:libSDL2_image$secondaryArchSuffix
	devel:libSDL2_mixer$secondaryArchSuffix
	devel:libtinyxml$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/OpenClonk \
		-DWITH_APPDIR_INSTALLATION=ON \
		-DCMAKE_BUILD_TYPE=Release
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mv $appsDir/OpenClonk/bin/openclonk $appsDir/OpenClonk/OpenClonk
	mkdir -p $binDir
	mv $appsDir/OpenClonk/bin/* $binDir
	mv $appsDir/OpenClonk/share/games/openclonk $appsDir/OpenClonk/data
	rm -rf $appsDir/OpenClonk/{share,games,bin}

	local APP_SIGNATURE="application/x-vnd.openclonk"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2 | cut -d~ -f1`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/openclonk.rdef.in > $sourceDir/openclonk.rdef

	addResourcesToBinaries  $sourceDir/openclonk.rdef \
		"$appsDir/OpenClonk/OpenClonk"
	addAppDeskbarSymlink $appsDir/OpenClonk/OpenClonk
}
