SUMMARY="A 2D side-scroller platform video game"
DESCRIPTION="OpenClaw is a multiplatform C++ reimplementation of original \
Captain Claw published by Monolith Productions in 1997 about the \
anthropomorphic pirate cat Captain Nathaniel Joseph Claw, \
who sets on a quest to find an ancient amulet while fighting \
enemies and solving puzzles. For this reimplementation \
the whole codebase was written from scratch. \
The game uses assets from the original game archive (CLAW.REZ)"
HOMEPAGE="https://github.com/pjasicek/OpenClaw"
COPYRIGHT="2009 Peter \"Corsix\" Cawley
	2012 Michael L. McShaffry and David Graham"
LICENSE="MIT
	GNU GPL v3"
REVISION="1"
srcGitRev="3586dfade4a0ae9b4456d24b599c9e9b111522e2"
SOURCE_URI="https://github.com/pjasicek/OpenClaw/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="bb33a7d39745f050af013fcb9d444e6df17ec7c89f72648ace11038a4dc3d3ce"
SOURCE_FILENAME="openclaw-$portVersion-$srcGitRev.tar.gz"
SOURCE_DIR="OpenClaw-$srcGitRev"
SOURCE_URI_2="https://github.com/pjasicek/OpenClaw/releases/download/v0.0/openclaw_1.0-1.deb#noarchive"
CHECKSUM_SHA256_2="0e5cde1cb6f3113afb9255f89816f6716d33f03e305ea8a75853d0c5abdd58b1"
PATCHES="openclaw-$portVersion.patchset"
ADDITIONAL_FILES="openclaw.rdef.in"

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

GLOBAL_WRITABLE_FILES="
	settings/OpenClaw/config.xml keep-old
	settings/OpenClaw/SAVES.XML keep-old
	"

PROVIDES="
	openclaw$secondaryArchSuffix = $portVersion
	app:openclaw = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libsdl2_2.0$secondaryArchSuffix
	lib:libsdl2_mixer_2.0$secondaryArchSuffix
	lib:libsdl2_ttf$secondaryArchSuffix
	lib:libsdl2_image_2.0$secondaryArchSuffix
	lib:libsdl2_gfx$secondaryArchSuffix
	lib:libtinyxml$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libsdl2_2.0$secondaryArchSuffix
	devel:libsdl2_mixer_2.0$secondaryArchSuffix
	devel:libsdl2_ttf$secondaryArchSuffix
	devel:libsdl2_image_2.0$secondaryArchSuffix
	devel:libsdl2_gfx$secondaryArchSuffix
	devel:libtinyxml$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:ar
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:tar
	cmd:xz
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake ..
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/OpenClaw/assets
	cp Build_Release/openclaw $appsDir/OpenClaw/OpenClaw

	cp Build_Release/{clacon.ttf,ASSETS.ZIP,console02.tga} $appsDir/OpenClaw/assets

	mkdir -p $settingsDir/OpenClaw
	cp Build_Release/{config.xml,SAVES.XML} $settingsDir/OpenClaw

	ar x $sourceDir2/openclaw_1.0-1.deb
	tar xf data.tar.xz ./usr/share/openclaw/CLAW.REZ
	mv ./usr/share/openclaw/CLAW.REZ $appsDir/OpenClaw/assets

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

	addResourcesToBinaries  $sourceDir/build/openclaw.rdef $appsDir/OpenClaw/OpenClaw

	addAppDeskbarSymlink $appsDir/OpenClaw/OpenClaw
}
