SUMMARY="A classic overhead run-and-gun game"
DESCRIPTION="C-Dogs SDL is a classic overhead run-and-gun game, supporting up to 4 players in co-op \
and deathmatch modes. Customize your player, choose from many weapons, and blast, slide and slash \
your way through over 100 user-created campaigns. Have fun!"
HOMEPAGE="https://github.com/cxong/cdogs-sdl"
COPYRIGHT="1995 Ronny Wester
	2003 Jeremy Chin
	2003-2010 Lucas Martin-King
	2013-2022 Cong Xu"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/cxong/cdogs-sdl/archive/$portVersion.tar.gz"
SOURCE_DIR="cdogs-sdl-$portVersion"
CHECKSUM_SHA256="20ed6d261dcc1a6c5f197ffa49aeb2b9c30d2ece514745b144c6ebaeada9bcaf"
PATCHES="cdogs_sdl-$portVersion.patchset"
ADDITIONAL_FILES="cdogs.rdef.in"

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

PROVIDES="
	cdogs_sdl$secondaryArchSuffix = $portVersion
	app:C_Dogs_SDL
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_image_2.0$secondaryArchSuffix
	lib:libSDL2_mixer_2.0$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libSDL2_image_2.0$secondaryArchSuffix
	devel:libSDL2_mixer_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:ar
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

defineDebugInfoPackage cdogs_sdl$secondaryArchSuffix $appsDir/C-Dogs\ SDL

BUILD()
{
	# CDOGS_DATA_DIR needs the trailing slash
	# editor needs GTK, perhaps in a subpackage later
	cmake \
		-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DCDOGS_BIN_DIR=$appsDir \
		-DCDOGS_DATA_DIR=$dataDir/cdogs-sdl/ \
		-DCDOGS_DOC_DIR=$documentationDir/cdogs-sdl \
		-DBUILD_EDITOR=OFF \
		.

	make $jobArgs
}

INSTALL()
{
	make install

	# cleanup
	# TODO move some of this into the cmake logic or patch the code as needed
	mv $dataDir/cdogs-sdl/README.md $documentationDir/cdogs-sdl/README.md
	mv $appsDir/cdogs-sdl $appsDir/C-Dogs\ SDL
	mkdir -p $dataDir/cdogs-sdl/doc
	ln -s $documentationDir/cdogs-sdl/CREDITS $dataDir/cdogs-sdl/doc/CREDITS

	# add our version and other application resources
	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/cdogs.rdef.in > cdogs.rdef

	addResourcesToBinaries cdogs.rdef $appsDir/C-Dogs\ SDL

	addAppDeskbarSymlink $appsDir/C-Dogs\ SDL C-Dogs\ SDL
}
