SUMMARY="A GameCube and Wii emulator"
DESCRIPTION="Dolphin is an emulator for two recent Nintendo video game consoles: the \
GameCube and the Wii. It allows PC gamers to enjoy games for these two consoles in \
full HD (1080p) with several enhancements: compatibility with all PC controllers, \
turbo speed, networked multiplayer, and even more!"
HOMEPAGE="https://dolphin-emu.org/"
COPYRIGHT="2020 Dolphin Emulator Project"
LICENSE="GNU GPL v2"
REVISION="5"
gitRevision="a34823df61df65168aa40ef5e82e44defd4a0138"
SOURCE_URI="https://github.com/dolphin-emu/dolphin/archive/$gitRevision.tar.gz"
CHECKSUM_SHA256="f2fcdcd26e8156b15adc0bc031fdaae3ff29bee59f46376ad57d7165b3c1f0c9"
SOURCE_DIR="dolphin-$gitRevision"
PATCHES="dolphin_emu-$portVersion.patchset"
ADDITIONAL_FILES="dolphin_emu.rdef.in"

ARCHITECTURES="?all !x86_gcc2 !x86"

PROVIDES="
	dolphin_emu = $portVersion
	app:Dolphin = $portVersion
	"
REQUIRES="
	haiku
	lib:libavcodec
	lib:libavformat
	lib:libavutil
	lib:libbz2
	lib:libcubeb
	lib:libcurl
	lib:libGL
	lib:libiconv
	lib:liblzma
	lib:libminiupnpc
	lib:libopenal
	lib:libpng16
	lib:libQt5Core
	lib:libQt5Widgets
	lib:libsdl_1.2
	lib:libswscale
	lib:libusb_1.0
	lib:libz
	"

BUILD_REQUIRES="
	haiku_devel
	devel:libavcodec
	devel:libavformat
	devel:libavutil
	devel:libbz2
	devel:libcubeb
	devel:libcurl
	devel:libGL
	devel:liblzma
	devel:libminiupnpc
	devel:libopenal
	devel:libpng16
	devel:libQt5Core
	devel:libQt5Widgets
	devel:libsdl_1.2
	devel:libswscale
	devel:libusb_1.0
	devel:libz
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc
	cmd:ld
	cmd:lrelease >= 5
	cmd:ninja
	cmd:pkg_config
	"

BUILD()
{
	cmake . \
		-GNinja \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Dolphin/ \
		-DCMAKE_INSTALL_BINDIR=$appsDir/Dolphin/ \
		-DDOLPHIN_WC_DESCRIBE="$portVersion" \
		-DENABLE_VULKAN=OFF \
		-DENABLE_NOGUI=OFF

	ninja $jobArgs
}

INSTALL()
{
	ninja install
	mv $appsDir/Dolphin/bin/dolphin-emu $appsDir/Dolphin/Dolphin
	rm -rf $appsDir/Dolphin/bin

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

	addResourcesToBinaries dolphin_emu.rdef $appsDir/Dolphin/Dolphin

	addAppDeskbarSymlink $appsDir/Dolphin/Dolphin Dolphin
}
