SUMMARY="A Doom 3 GPL source modification"
DESCRIPTION="dhewm3 is a source port of the original Doom3 (not Doom3 BFG, for that \
you may want to try RBDoom3BFG). It's known to work on Windows, Linux, macOS, FreeBSD, \
OpenBSD and AROS, but it should work on (or be easily portable to) any system that \
supports OpenGL 1.4 with ARB shaders, SDL and OpenAL.

Compared to the original version of Doom3, dhewm3 has many bugfixes, supports \
EAX-like sound effects on all operating systems and hardware (via OpenAL Softs EFX \
support), has much better support for widescreen resolutions and has 64bit support.

Note that while the Doom3 source code has been released under GPL, you still need \
to legally own the game and provide dhewm3 the game data to play."
HOMEPAGE="https://dhewm3.org/"
COPYRIGHT="
	2011-2019 dhewm3 teams, and contributors
	2004 id Software
	"
LICENSE="GNU GPL v3"
REVISION="2"
SOURCE_URI="https://github.com/dhewm/dhewm3/archive/${portVersion}_PRE1.tar.gz"
CHECKSUM_SHA256="bb454cfdf6e698bac2c6b1cfca19d7b1381b8a59cfb8bc4d38b483b7ee23da47"
SOURCE_DIR="dhewm3-${portVersion}_PRE1"
#cdoom mod
srcGitRev2="5070b8c7ec6f3a8ba1cb4123de37732f9cd9437f"
SOURCE_URI_2="https://github.com/dhewm/dhewm3-sdk/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="301d4114a11859fb7a0f9ee1ecae50a8de5ba6add0e3564b54af9b5b972ec710"
SOURCE_DIR_2="dhewm3-sdk-$srcGitRev2"
#rivensin mod
srcGitRev3="b651f9dc1ddb958eaee3f0a1373fc4af7dce67e5"
SOURCE_URI_3="https://github.com/dhewm/dhewm3-sdk/archive/$srcGitRev3.tar.gz"
CHECKSUM_SHA256_3="334b2a882b05f00a8120ece8944974de0625f4dc439dd8b8505c358c04a7948a"
SOURCE_DIR_3="dhewm3-sdk-$srcGitRev3"
#denton mod
srcGitRev4="aaec7be6276661d6c9e612de99ffe8af33828404"
SOURCE_URI_4="https://github.com/dhewm/dhewm3-sdk/archive/$srcGitRev4.tar.gz"
CHECKSUM_SHA256_4="16e6e3a67b6d9efe66cd3b6a4918f4d4b046aef21f83ed4c3125832634df7458"
SOURCE_DIR_4="dhewm3-sdk-$srcGitRev4"
#fitz mod
srcGitRev5="6ebb6b8394c047dd042aec47fa79ddec2b901754"
SOURCE_URI_5="https://github.com/dhewm/dhewm3-sdk/archive/$srcGitRev5.tar.gz"
CHECKSUM_SHA256_5="12ed335709af159179e7d20e88a8f03b7481ace443315edb00c4a8d8df32b741"
SOURCE_DIR_5="dhewm3-sdk-$srcGitRev5"
#hardqore2 mod
srcGitRev6="024a8683431e2b06847d585fc1e75968310b0548"
SOURCE_URI_6="https://github.com/dhewm/dhewm3-sdk/archive/$srcGitRev6.tar.gz"
CHECKSUM_SHA256_6="a5f62a616eba85a40af2cf6d029a032eb574a7b0f567fcfe005e04b7e6b42eb3"
SOURCE_DIR_6="dhewm3-sdk-$srcGitRev6"
#launcher
srcGitRev7="d5157392c6f63ec82aaa715e74b364c284701536"
SOURCE_URI_7="https://github.com/EXL/BeGameLauncher/archive/$srcGitRev7.tar.gz"
CHECKSUM_SHA256_7="ef1c197be64590ba509c7cf6c6f758475ebcdac1d014e596e32d26b12b024f16"
SOURCE_DIR_7="BeGameLauncher-$srcGitRev7"

PATCHES="dhewm3-$portVersion.patchset"
PATCHES_2="dhewm3_mods-$portVersion.patchset"
PATCHES_3="dhewm3_mods-$portVersion.patchset"
PATCHES_4="dhewm3_mods-$portVersion.patchset"
PATCHES_5="dhewm3_mods-$portVersion.patchset"
PATCHES_6="dhewm3_mods-$portVersion.patchset"

ADDITIONAL_FILES="dhewm3.rdef.in"

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

PROVIDES="
	dhewm3$secondaryArchSuffix = $portVersion
	app:dhewm3
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libvorbisfile$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libvorbisfile$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 ../neo \
		-DCMAKE_BUILD_TYPE=Release	\
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2
	make $jobArgs
	cd ..

	# build mod: classic doom
	mkdir -p build_cdoom
	cd build_cdoom
	cmake $sourceDir2 -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
	cd ..
	# build mod: rivensin
	mkdir -p build_rivensin
	cd build_rivensin
	cmake $sourceDir3 -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
	cd ..
	# build mod: dentonmod
	mkdir -p build_dentonmod
	cd build_dentonmod
	cmake $sourceDir4 -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
	cd ..
	# build mod: fitz
	mkdir -p build_fitz
	cd build_fitz
	cmake $sourceDir5 -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
	cd ..
	# build mod: hardqore2
	mkdir -p build_hardqore2
	cd build_hardqore2
	cmake $sourceDir6 -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
	cd ..
	# build launcher
	mkdir -p build_launcher
	cd build_launcher
	cmake $sourceDir7 \
		-DCMAKE_BUILD_TYPE=Release \
		-DLAUNCHER=dhewm3
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/dhewm3/lib

	cp build/dhewm3 $appsDir/dhewm3
	cp build/*.so $appsDir/dhewm3/lib
	cp build_{cdoom,rivensin,dentonmod,fitz,hardqore2}/*.so $appsDir/dhewm3/lib
	cp build_launcher/Dhewm3Launcher "$appsDir/dhewm3/dhewm3 Launcher"

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

	addResourcesToBinaries build/dhewm3.rdef $appsDir/dhewm3/dhewm3
	addAppDeskbarSymlink "$appsDir/dhewm3/dhewm3 Launcher" "DOOM 3"
}
