SUMMARY="Realistic physics simulation game"
DESCRIPTION="The Butterfly Effect is a free and open source game that uses realistic \
physics simulations to combine lots of simple mechanical elements to achieve a simple \
goal in the most complex way possible."
HOMEPAGE="http://the-butterfly-effect.org/"
COPYRIGHT="Peter van Ginneken, Klaas van Gend"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/the-butterfly-effect/tbe/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="7e59ddb1d28c589e3e4aff756dbf76eab0e85f1dc9288c151cd4eff6dcb913a3"
SOURCE_DIR="tbe-$portVersion"
PATCHES="tbe-$portVersion.patchset"
ADDITIONAL_FILES="tbe.rdef.in"

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

PROVIDES="
	tbe$secondaryArchSuffix = $portVersion
	app:TheButterflyEffect$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	cmake . -DCMAKE_INSTALL_PREFIX=$appsDir/TBE
	make $jobArgs
}

INSTALL()
{
	make install

	mv $appsDir/TBE/tbe "$appsDir/TBE/The Butterfly Effect"
	rm -rf $appsDir/TBE/{applications,icons}

	local APP_SIGNATURE="application/x-vnd.the-butterfly-effect"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local INTERNAL="`echo "$portVersion" | cut -d. -f4`"
	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|@INTERNAL@|$INTERNAL|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/tbe.rdef.in > $sourceDir/tbe.rdef

	addResourcesToBinaries  $sourceDir/tbe.rdef \
		"$appsDir/TBE/The Butterfly Effect"

	mimeset -f "$appsDir/TBE/The Butterfly Effect"

	addAppDeskbarSymlink "$appsDir/TBE/The Butterfly Effect"
}
