SUMMARY="A fan-made multiplayer Super Mario Bros. style deathmatch game"
DESCRIPTION="Super Mario War is a fan-made multiplayer Super Mario Bros. style \
deathmatch game in which plyaers try to beat one another in a variety of \
gameplay modes. You can play on teams, design your own levels, design your own \
worlds, and much more!"
HOMEPAGE="https://github.com/mmatyas/supermariowar"
COPYRIGHT="2003-2018 Super Mario War developers"
LICENSE="GNU GPL v2"
REVISION="3"
SOURCE_URI="$HOMEPAGE/archive/v2.0-${portVersion%%[0-9]*}.${portVersion##*[a-z]}.tar.gz"
CHECKSUM_SHA256="ff0890e348c6fd56d4e1e7a3c3af405cb9ff7e23e7492f11e18832495366424d"
SOURCE_FILENAME="supermariowar-$portVersion.tar.gz"
SOURCE_DIR="supermariowar-2.0-${portVersion%%[0-9]*}.${portVersion##*[a-z]}"
PATCHES="supermariowar-$portVersion.patch"

ARCHITECTURES="all !x86_gcc2"
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
commandBinDir=$prefix/bin
fi

PROVIDES="
	supermariowar$secondaryArchSuffix = $portVersion
	app:SMW = $portVersion
	app:SMW_LevelEdit = $portVersion
	app:SMW_WorldEdit = $portVersion
	cmd:smw_server
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libenet$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	lib:libSDL_mixer_1.2$secondaryArchSuffix
	lib:libyaml_cpp$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libenet$secondaryArchSuffix
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libSDL_image_1.2$secondaryArchSuffix
	devel:libSDL_mixer_1.2$secondaryArchSuffix
	devel:libyaml_cpp$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:sed
	cmd:unzip
	"

defineDebugInfoPackage supermariowar$secondaryArchSuffix \
	"$appsDir/SMW" \
	"$appsDir/SMW-LevelEdit" \
	"$commandBinDir/smw-server" \
	"$appsDir/SMW-WorldEdit"

PATCH()
{
	sed -i "/SMW_BINDIR/ s|/games|/$relativeAppsDir|" CMakeLists.txt
}

BUILD()
{
	unzip -n data.zip
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_STATIC_LIBS=OFF \
		-DCMAKE_INSTALL_PREFIX="$prefix" \
		-DSMW_DATADIR="$dataDir/supermariowar"
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	install -m 755 -d "$appsDir" "$commandBinDir"
	install -m 755 Binaries/Release/smw-server "$commandBinDir"

	set smw SMW "Super Mario War" \
		smw-leveledit SMW-LevelEdit "Super Mario War Level Editor" \
		smw-worldedit SMW-WorldEdit "Super Mario War World Editor"

	while [ $# != 0 ]; do
		mv "$appsDir/$1" "$appsDir/$2"
		addAppDeskbarSymlink "$appsDir/$2" "$3"
		shift 3
	done

	chmod 755 "$appsDir"/*
}
