SUMMARY="A role playing game battling roboters"
DESCRIPTION="The game tells the story of a world destroyed by a conflict \
between robots and their human masters. Play as Tux in a quest to save the \
world from the murderous rebel bots who know no mercy. You get to choose \
which path you wish to follow, and freedom of choice is everywhere in the game.

FreedroidRPG features a real time combat system with melee and ranged \
weapons, fairly similar to the proprietary game Diablo. There is an \
innovative system of programs that can be run in order to take control of \
enemy robots, alter their behavior, or improve one's characteristics. You \
can use over 50 different kinds of items and fight countless enemies on your \
way to your destiny. An advanced dialog system provides story background and \
immersive role playing situations.

The game is complete, fully playable, and can provide about 10 hours of fun.
It is still being actively developed, and help is welcome in many areas. \
People having - or trying to acquire - programming, map editing, or writing \
skills will find FreedroidRPG to be an exciting, fast-moving project in which \
they can fully express their creativity."
HOMEPAGE="https://freedroid.org"
COPYRIGHT="2002-2019 The Freedroid team"
LICENSE="GNU GPL v2"
REVISION="4"
SOURCE_URI="ftp://ftp.osuosl.org/pub/freedroid/freedroidRPG-${portVersion%\~*}/freedroidRPG-${portVersion//\~}.tar.gz"
CHECKSUM_SHA256="feb3e8118422ce4a1c4a5b2b0b3095bee08ca8bdbb4ba25791095ed194b25382"
SOURCE_DIR="freedroidrpg-1.0RC2"
PATCHES="freedroidrpg-$portVersion.patchset"
ADDITIONAL_FILES="freedroidrpg.rdef.in"

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

PROVIDES="
	freedroidrpg$secondaryArchSuffix = $portVersion
	app:freedroidrpg$secondaryArchSuffix = $portVersion
	cmd:croppy$secondaryArchSuffix = $portVersion
	cmd:explode_atlas$secondaryArchSuffix = $portVersion
	cmd:explodefont$secondaryArchSuffix = $portVersion
	cmd:gluefont$secondaryArchSuffix = $portVersion
	cmd:make_atlas$secondaryArchSuffix = $portVersion
	cmd:pngtoico$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	freedroidrpg_data == $portVersion
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_gfx$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

SUMMARY_data="Data files for the game FreedroidRPG"
ARCHITECTURES_data="any"
PROVIDES_data="
	freedroidrpg_data = $portVersion
	"
REQUIRES_data="
	haiku
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libSDL$secondaryArchSuffix
	devel:libSDL_gfx$secondaryArchSuffix
	devel:libSDL_image$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:automake
	cmd:gawk
	cmd:gcc$secondaryArchSuffix
	cmd:gettext
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	cmd:which
	"

PATCH()
{
	sed -i 's/lua.h/..\/lua\/lua.h/g' src/*.c
	sed -i 's/lua.h/..\/lua\/lua.h/g' src/*.h
	sed -i 's/lauxlib.h/..\/lua\/lauxlib.h/g' src/*.c
	sed -i 's/lauxlib.h/..\/lua\/lauxlib.h/g' src/*.h
	sed -i 's/lualib.h/..\/lua\/lualib.h/g' src/*.c
	sed -i 's/lualib.h/..\/lua\/lualib.h/g' src/*.h
}

BUILD()
{
	echo "=== libtoolize"
	libtoolize --force --copy --install
	echo "=== aclocal"
	aclocal
	echo "=== automake"
	automake --add-missing
	echo "=== autoreconf"
	autoreconf
	echo "=== autoconf"
	autoconf
	echo "=== automake"
	automake

	local APPDIR="$appsDir/FreedroidRPG/"

	./configure \
		--prefix=$APPDIR \
		--bindir=$APPDIR \
		--sbindir=$APPDIR \
		--datarootdir=$APPDIR \
		--datadir=$APPDIR \
		--mandir=$manDir \
		--docdir=$docDir \
		--disable-sdltest \
		--with-embedded-lua
	make $jobArgs
}

INSTALL()
{
	make install

	mv $appsDir/FreedroidRPG/freedroidRPG $appsDir/FreedroidRPG/FreedroidRPG
	rm -rf $appsDir/FreedroidRPG/{applications,icons,metainfo}

	packageEntries data $appsDir/FreedroidRPG/freedroidrpg

	local APP_SIGNATURE="application/x-vnd.freedroidrpg"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2 | 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/freedroidrpg.rdef.in > $sourceDir/freedroidrpg.rdef

	addResourcesToBinaries  $sourceDir/freedroidrpg.rdef $appsDir/FreedroidRPG/FreedroidRPG

	addAppDeskbarSymlink $appsDir/FreedroidRPG/FreedroidRPG
}
