SUMMARY="Script Creation Utility for Maniac Mansion Virtual Machine"
DESCRIPTION="ScummVM is a program which allows you to run certain classic \
graphical point-and-click adventure games, provided you already have their \
data files. The clever part about this: ScummVM just replaces the executables \
shipped with the games, allowing you to play them on systems for which they \
were never designed!"
HOMEPAGE="https://www.scummvm.org/"
COPYRIGHT="2001-2021 ScummVM Team"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="http://www.scummvm.org/frs/scummvm/$portVersion/scummvm-$portVersion.tar.gz"
CHECKSUM_SHA256="023a83cb15614cda59364a721180250048974bcc91bbce5035594f74572af1e4"
ADDITIONAL_FILES="scummvm.rdef.in"

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

PROVIDES="
	scummvm$secondaryArchSuffix = $portVersion
	app:scummvm$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liba52$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfaad$secondaryArchSuffix
	lib:libflac$secondaryArchSuffix
	lib:libfluidsynth$secondaryArchSuffix >= 2
	lib:libfreetype$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libmad$secondaryArchSuffix
	lib:libmpeg2$secondaryArchSuffix
	lib:libnghttp2$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_net_2.0$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libtheora$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liba52$secondaryArchSuffix
	devel:libbz2$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfaad$secondaryArchSuffix
	devel:libflac$secondaryArchSuffix
	devel:libfluidsynth$secondaryArchSuffix >= 2
	devel:libfreetype$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix >= 2.2
	devel:libglu$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libmad$secondaryArchSuffix
	devel:libmpeg2$secondaryArchSuffix
	devel:libnghttp2$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libSDL2_net_2.0$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libtheora$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:nasm
	cmd:pkg_config$secondaryArchSuffix
	"

PATCH()
{
	sed -i 's/xdg-open/open/g' backends/platform/sdl/posix/posix.cpp
}

BUILD()
{
	libtoolize --force --copy --install
	CPPFLAGS=`freetype-config --cflags` ./configure --prefix=$prefix \
		--bindir=$appsDir --libdir=$libDir --datarootdir=$dataDir \
		--mandir=$manDir --docdir=$docDir \
		--enable-c++11 --disable-debug --enable-release --disable-eventrecorder
		#--disable-all-engines #can be used to compile scummvm without \
		#engines, which makes it build faster (to test), those that \
		#are still under construction can be built with --enable-all-engines \
		#for testing purposes
	make $jobArgs
}

INSTALL()
{
	make install
	mv $appsDir/scummvm $appsDir/ScummVM

	#we are not linux
	rm -r $dataDir/{applications,icons,pixmaps}

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/scummvm.rdef.in > scummvm.rdef

	addResourcesToBinaries scummvm.rdef \
		$appsDir/ScummVM

	addAppDeskbarSymlink $appsDir/ScummVM
}

TEST()
{
	make test
}
