SUMMARY="A sandbox block game inspired by Minecraft Classic"
DESCRIPTION="ClassiCube is a custom Minecraft Classic and ClassiCube client written in \
C that works on Windows, macOS, Linux, Android, FreeBSD, NetBSD, OpenBSD, Solaris, \
Haiku, and in a web browser.

It is not affiliated with (or supported by) Mojang AB, Minecraft, or Microsoft in any way.

What ClassiCube is:
* A complete re-implementation of Minecraft Classic 0.30, with optional additions
* Lightweight, minimal memory usage compared to original Minecraft Classic
* Much better performance than original Minecraft Classic
* Works with effectively all graphics cards that support OpenGL or Direct3D 9

What ClassiCube isn't:
* It does not work with Minecraft Java or Bedrock edition servers
* It does not have a survival mode (nor will such a mode be added)
* It does not reimplement Minecraft Classic versions before 0.30"
HOMEPAGE="https://www.classicube.net/"
COPYRIGHT="2014-2022 UnknownShadow200"
LICENSE="BSD (3-clause)"
REVISION="2"
SOURCE_URI="https://github.com/UnknownShadow200/ClassiCube/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="8373605a45d89229520fe03bf8f5a1ada82377651e7330edd65a3f79327f8331"
SOURCE_DIR="ClassiCube-$portVersion"
ADDITIONAL_FILES="
	classicube.rdef.in
	launcher.sh
	"

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

PROVIDES="
	classicube$secondaryArchSuffix = $portVersion
	app:ClassiCube
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_image_2.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libexecinfo$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libSDL2_image_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

PATCH()
{
	sed -i -e 's|r.me##reg|r.e##reg|g' $sourceDir/src/Logger.c
}

BUILD()
{
	cd src
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/ClassiCube

	cp $portDir/additional-files/launcher.sh "$appsDir/ClassiCube/ClassiCube Launcher"
	cp src/ClassiCube $appsDir/ClassiCube
	strip $appsDir/ClassiCube/ClassiCube

	local APP_SIGNATURE="application/x-vnd.classicube"
	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/classicube.rdef.in > $sourceDir/classicube.rdef

	rc $sourceDir/classicube.rdef
	resattr -o "$appsDir/ClassiCube/ClassiCube Launcher" \
		$sourceDir/classicube.rsrc
	chmod +x "$appsDir/ClassiCube/ClassiCube Launcher"

	addResourcesToBinaries  $sourceDir/classicube.rdef \
		$appsDir/ClassiCube/ClassiCube
	addAppDeskbarSymlink "$appsDir/ClassiCube/ClassiCube Launcher" "ClassiCube"
}
