SUMMARY="Clone of Super Monkey Ball using SDL2/OpenGL"
DESCRIPTION="Tilt the floor to roll a ball through an obstacle course within \
the given time. If the ball falls or time expires, a ball is lost. \
Collect coins to unlock the exit and earn extra balls. Red coins are worth 5. \
Blue coins are worth 10. A ball is awarded for 100 coins."
HOMEPAGE="https://neverball.org"
COPYRIGHT="2002-2019 The Neverball Team"
LICENSE="GNU GPL v2"
REVISION="2"
srcGitRev="09a2a620a6b71bfc0afca1f0fc96a7dfb6cb9208"
SOURCE_URI="https://github.com/Neverball/neverball/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="66a9fa8b0f7676991e32b4dda669a64e902ddc07e5612d1f4f21a9003549fcde"
SOURCE_FILENAME="neverball-$portVersion-$srcGitRev.tar.gz"
SOURCE_DIR="neverball-$srcGitRev"
PATCHES="neverball-$portVersion.patchset"
ADDITIONAL_FILES="
	neverball.rdef.in
	neverputt.rdef.in
	"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

PROVIDES="
	neverball$secondaryArchSuffix = $portVersion
	app:neverball$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libphysfs$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_mixer_2.0$secondaryArchSuffix
	lib:libSDL2_ttf_2.0$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libphysfs$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libSDL2$secondaryArchSuffix
	devel:libSDL2_mixer$secondaryArchSuffix
	devel:libSDL2_ttf$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libpng_config$secondaryArchSuffix >= 1.6
	cmd:make
	"

PATCH()
{
	mv share/version.in.h share/version.h
	sed -i 's/0.0.0/1.6.1/g' share/version.h
}

BUILD()
{
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/Neverball
	cp -rf mapc README.md LICENSE.md data $appsDir/Neverball
	cp -f neverball $appsDir/Neverball/Neverball
	cp -f neverputt $appsDir/Neverball/Neverputt

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

	addResourcesToBinaries  $sourceDir/neverball.rdef \
		$appsDir/Neverball/Neverball

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

	addResourcesToBinaries  $sourceDir/neverputt.rdef \
		$appsDir/Neverball/Neverputt

	addAppDeskbarSymlink $appsDir/Neverball/Neverball
	addAppDeskbarSymlink $appsDir/Neverball/Neverputt
}
