SUMMARY="A cross-platform 3D game interpreter"
DESCRIPTION="ResidualVM is a program which allows you to run certain classic \
3D games, provided you already have their data files. ResidualVM just \
replaces the executables shipped with the game, allowing you to play them on \
systems for which they were never designed!"
HOMEPAGE="https://www.residualvm.org/"
COPYRIGHT="2003-2018 ResidualVM Team"
LICENSE="GNU GPL v2"
REVISION="7"
SOURCE_URI="https://www.residualvm.org/downloads/release/$portVersion/residualvm-$portVersion-sources.tar.gz"
CHECKSUM_SHA256="515b02129dd374bc9c0b732ddeaaaa3a342cc25ea0ea3c4ccf19141b5d362e1d"
PATCHES="residualvm-$portVersion.patchset"
ADDITIONAL_FILES="residualvm.rdef.in"

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

PROVIDES="
	residualvm$secondaryArchSuffix = $portVersion
	app:ResidualVM$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfaad$secondaryArchSuffix
	lib:libflac$secondaryArchSuffix
	lib:libfluidsynth$secondaryArchSuffix >= 1
	lib:libfreetype$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libmad$secondaryArchSuffix
	lib:libmpeg2$secondaryArchSuffix
	lib:libnghttp2$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_net_2.0$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libtheoradec$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libvorbisfile$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfaad$secondaryArchSuffix
	devel:libflac$secondaryArchSuffix
	devel:libfluidsynth$secondaryArchSuffix >= 1
	devel:libfreetype$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libmad$secondaryArchSuffix
	devel:libmpeg2$secondaryArchSuffix
	devel:libnghttp2$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libSDL2_net_2.0$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libtheoradec$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libvorbisfile$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:nasm
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	CPPFLAGS=`freetype-config --cflags` ./configure --prefix=$appsDir/ResidualVM \
		--enable-all-engines \
		--enable-release \
		--enable-libcurl \
		--enable-fluidsynth \
		--enable-flac \
		--enable-faad \
		--enable-text-console \
		--enable-cloud \
		--disable-debug \
		--disable-updates

	make $jobArgs
}

INSTALL()
{
	make install
	mv $appsDir/ResidualVM/bin/residualvm $appsDir/ResidualVM/ResidualVM
	rm -R $appsDir/ResidualVM/bin

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

	addResourcesToBinaries  $sourceDir/residualvm.rdef \
		$appsDir/ResidualVM/ResidualVM

	addAppDeskbarSymlink $appsDir/ResidualVM/ResidualVM
}
