SUMMARY="Advanced Doom source port with OpenGL support"
DESCRIPTION="Consider all these features that ZDoom has that are not found in \
the standard Doom originally released by id:

* It runs well under all modern versions of Windows, from Windows XP to the \
new Windows 10. If you have Mac or Linux, it works with that too.
* Can play all Doom engine games, including Ultimate Doom, Doom II, Heretic, \
Hexen, Strife, and more.
* Supports all the editing features of Hexen. (ACS, hubs, new map format, etc.)
* Supports most of the Boom editing features.
* Many more all-new editing features such as:
* Colored lighting.
* 3D floors.
* Portals.
* Advanced polyobjects free from the restrictions of their original \
implementation in Hexen.
* Custom monsters, weapons, items, player classes, and other entities.
* High resolution textures and sprites.
* Translucency (regular and additive).
* Many, many extensions to ACS that were not present in Hexen.
* More music formats: Ogg Vorbis, MOD, XM, IT, S3M, MIDI, and MP3 as well as \
old-fashioned MUS all work.
* More sound formats: FLAC and WAVE can both be used for sound effects.
* More texture formats: PNG and JPEG are both useable for artwork.
* All Doom limits are gone.
* Several softsynths for MUS and MIDI playback, including an OPL softsynth
for an authentic "oldschool" flavor.
* High resolutions.
* Quake-style console and key bindings.
* Crosshairs.
* Free look (look up/down).
* Jumping, crouching, swimming, and flying.
* Full-featured joystick/gamepad support under Windows.
* Up to 8 player network games using UDP/IP, including team-based gameplay.
* Support for the Bloodbath announcer from the classic Monolith game Blood.
* Walk over/under monsters and other things."
HOMEPAGE="https://zdoom.org/"
COPYRIGHT="
	1998-2019 ZDoom + GZDoom teams, and contributors
	1997 id Software, Raven Software, and contributors
	"
LICENSE="GNU GPL v3"
REVISION="2"
SOURCE_URI="https://zdoom.org/files/gzdoom/src/gzdoom-src-g${portVersion}_legacy.zip"
CHECKSUM_SHA256="0c3af7b0af6b59f1ecbcc50e4fc0f70d6b1a33f554f63998a421bbc4da2913e6"
SOURCE_DIR="gzdoom-g${portVersion}_legacy"
srcGitRev2="f6ab178af2c85df04d8cc34b61f90ebf1502ed1f"
SOURCE_URI_2="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="45b42bb906e7ad1d94819fd18140505ab517ba78b3b593c3315f29bb391cf1ee"
SOURCE_DIR_2="BeGameLauncher-$srcGitRev2"
PATCHES="gzdoom-$portVersion.patchset"
ADDITIONAL_FILES="gzdoom.rdef.in"

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

PROVIDES="
	gzdoom$secondaryArchSuffix = $portVersion
	app:GZDoom
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfluidsynth$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libgme$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfluidsynth$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libgme$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:install
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_CXX_FLAGS="-D_GNU_SOURCE -D_BSD_SOURCE"
	make $jobArgs

	cd $sourceDir2
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DLAUNCHER=gzdoom
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/GZDoom

	cp build/gzdoom $appsDir/GZDoom/GZDoom
	cp build/*.pk3 $appsDir/GZDoom
	cp $sourceDir2/build/GZDoomLauncher $appsDir/GZDoom

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

	addResourcesToBinaries gzdoom.rdef $appsDir/GZDoom/GZDoom
	addAppDeskbarSymlink $appsDir/GZDoom/GZDoomLauncher "GZDoom"
}
