SUMMARY="A new Game Boy, Game Boy Color, and Game Boy Advance emulator written in C"
DESCRIPTION="mGBA is a new generation of Game Boy Advance emulator. The project \
started in April 2013 with the goal of being fast enough to run on lower end \
hardware than other emulators support, without sacrificing accuracy or \
portability. Even in the initial version, games generally played without \
problems. mGBA has only gotten better since then, and now boasts being the \
most accurate GBA emulator around.

Other goals include accurate enough emulation to provide a development \
environment for homebrew software, a good workflow for tool-assist runners, \
and a modern feature set for emulators that older emulators may not support."
HOMEPAGE="https://mgba.io/"
COPYRIGHT="2013-2021 Jeffrey Pfau"
LICENSE="MPL v2.0"
REVISION="1"
SOURCE_URI="https://github.com/mgba-emu/mgba/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="29ca22ebc56b26a4e7224efbb5fa12c9c006563d41990afb0874d048db76add4"
ADDITIONAL_FILES="mgba.rdef.in"

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

PROVIDES="
	mgba$secondaryArchSuffix = $portVersion
	cmd:mgba$secondaryArchSuffix = $portVersion
	cmd:mgba_qt$secondaryArchSuffix = $portVersion
	lib:libmgba$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libedit$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libminizip$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
# If you have come here to upgrade mGBA to use SDL2, know this:
# Haiku's SDL2 port is (at time of writing) TOTALLY INCOMPATIBLE with
# Qt and cannot be run in the same binary as it, as both create
# BApplication objects independent of the other.
# SDL1.2 checks if one already exists first, so it's OK.
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzip$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libavcodec$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libedit$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libminizip$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Multimedia$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libswscale$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzip$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	cmake . $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-GNinja \
		-DBUILD_GL=OFF \
		-DBUILD_GLES2=OFF \
		-DBUILD_GLES3=OFF \
		-DUSE_DISCORD_RPC=OFF
	ninja $jobArgs
}

INSTALL()
{
	ninja install

	local APP_SIGNATURE="application/x-vnd.qt5-mgba"
	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/mgba.rdef.in > mgba.rdef

	# not needed
	rm -rf $prefix/share

	addResourcesToBinaries mgba.rdef $binDir/mgba-qt
	addAppDeskbarSymlink $binDir/mgba-qt mGBA
}
