SUMMARY="An open source re-implementation of Caesar III"
DESCRIPTION="Julius is an open source re-implementation of Caesar III.

The aim of this project is to create an open-source version of Caesar 3, \
with the same logic as the original, but with some UI enhancements, that \
is able to be played on multiple platforms. The same logic means that the \
saved games are 100% compatible, and any gameplay bugs present in the \
original Caesar 3 game will also be present in Julius.

Julius requires the original assets (graphics, sounds, etc) from Caesar 3 to run."
HOMEPAGE="https://github.com/bvschaik/julius/"
COPYRIGHT="Bianca van Schaik"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/bvschaik/julius/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="f50eade82c1f011a642a89ec526fe9e9589ac44ffa6041e072577336233b8166"
srcGitRev2="0eaa8f0d4c7e92d522974a3530da8e5d63a722de"
SOURCE_URI_2="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="85e94ba8174879d986f3a9d35898bfa5eb67728c3910a41aca2ad143db803a88"
SOURCE_DIR_2="BeGameLauncher-$srcGitRev2"
PATCHES="julius-$portVersion.patchset"
ADDITIONAL_FILES="julius.rdef.in"

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

PROVIDES="
	julius$secondaryArchSuffix = $portVersion
	app:Julius$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libsdl2_2.0$secondaryArchSuffix
	lib:libsdl2_mixer_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgl$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libsdl2_2.0$secondaryArchSuffix
	devel:libsdl2_mixer_2.0$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_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Julius \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2 \
		-DSDL2_MIXER_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2 \
		-DHAIKU_BUILD=ON
	make $jobArgs

	cd $sourceDir2
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DLAUNCHER=julius
	make $jobArgs
}

INSTALL()
{
	cd build

	mkdir -p $appsDir/Julius

	cp julius $appsDir/Julius/Julius
	cp $sourceDir2/build/JuliusLauncher "$appsDir/Julius/Julius Launcher"

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

	addResourcesToBinaries $sourceDir/build/julius.rdef $appsDir/Julius/Julius

	addAppDeskbarSymlink "$appsDir/Julius/Julius Launcher" "Julius"
}
