SUMMARY="2D motocross platform game"
DESCRIPTION="X-Moto is a challenging 2D motocross platform game, where \
physics play an all important role in the gameplay. You need to control \
your bike to its limit, if you want to have a chance finishing the more \
difficult of the challenges."
HOMEPAGE="https://xmoto.tuxfamily.org"
COPYRIGHT="2005-2021 Tuxfamily"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://github.com/xmoto/xmoto/archive/$portVersion/$portVersion.tar.gz"
CHECKSUM_SHA256="209c8c38b1742d0620d40f90365c7a56f67c86da826c80a76d37fa46ee9c9b66"
PATCHES="xmoto-$portVersion.patchset"
ADDITIONAL_FILES="xmoto.rdef.in"

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

PROVIDES="
	xmoto$secondaryArchSuffix = $portVersion
	app:XMoto = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix >= 5.3
	lib:libpng16$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_mixer_1.2$secondaryArchSuffix
	lib:libSDL_net_1.2$secondaryArchSuffix
	lib:libSDL_ttf$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix >= 5.3
	devel:libpng16$secondaryArchSuffix
	devel:libSDL$secondaryArchSuffix
	devel:libSDL_gfx$secondaryArchSuffix
	devel:libSDL_mixer$secondaryArchSuffix
	devel:libSDL_net$secondaryArchSuffix
	devel:libSDL_ttf$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:gettext$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build

	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/XMoto \
		-DCMAKE_CXX_FLAGS=-DdDOUBLE \
		-DODE_DOUBLE_PRECISION=ON \
		-DPREFER_SYSTEM_ODE=OFF \
		-DPREFER_SYSTEM_XDG=OFF

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mv $appsDir/XMoto/share/locale $appsDir/XMoto
	mv $appsDir/XMoto/share/xmoto/* $appsDir/XMoto
	mv $appsDir/XMoto/bin/xmoto $appsDir/XMoto/XMoto
	rm -rf $appsDir/XMoto/{bin,share,xmoto_icone_x.ico}

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

	addResourcesToBinaries  $sourceDir/xmoto.rdef $appsDir/XMoto/XMoto
	addAppDeskbarSymlink $appsDir/XMoto/XMoto
}
