SUMMARY="A game similar to Settlers 2"
DESCRIPTION="Widelands is a free, open source real-time strategy \
game with singleplayer campaigns and a multiplayer mode. The game \
was inspired by Settlers II™ (© Bluebyte) but has significantly \
more variety and depth to it. Still, it is easy to get started \
through playable tutorials."
HOMEPAGE="https://www.widelands.org/"
COPYRIGHT="2009-2021 By the Widelands Development Team"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/widelands/widelands/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="1dab0c4062873cc72c5e0558f9e9620b0ef185f1a78923a77c4ce5b9ed76031a"
SOURCE_DIR="widelands-$portVersion"
PATCHES="widelands-$portVersion.patchset"
ADDITIONAL_FILES="widelands.rdef.in"

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

PROVIDES="
	widelands$secondaryArchSuffix = $portVersion
	app:WideLands
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libicuuc$secondaryArchSuffix
	lib:libicudata$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libSDL2_image_2.0$secondaryArchSuffix
	lib:libSDL2_ttf$secondaryArchSuffix
	lib:libSDL2_mixer_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_system$secondaryArchSuffix >= 1.69.0
	devel:libcurl$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libicuuc$secondaryArchSuffix >= 66
	devel:libjpeg$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libSDL2$secondaryArchSuffix
	devel:libSDL2_image$secondaryArchSuffix
	devel:libSDL2_ttf$secondaryArchSuffix
	devel:libSDL2_mixer$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	"

BUILD()
{
	mkdir -p build
	cd build
	LDFLAGS="-lbsd -lnetwork -lintl" \
		cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/WideLands \
		-DWL_INSTALL_DATADIR=$appsDir/WideLands/data \
		-DOPTION_BUILD_WEBSITE_TOOLS=OFF \
		-DOPTION_BUILD_TESTS=OFF \
		-DOPTION_BUILD_CODECHECK=OFF \
		-DCMAKE_CXX_FLAGS="-D_BSD_SOURCE" \
		-DCMAKE_C_FLAGS="-D_BSD_SOURCE" \
		-DCMAKE_BUILD_TYPE=Release
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mv $appsDir/WideLands/widelands $appsDir/WideLands/WideLands
	rm -rf $appsDir/share

	local APP_SIGNATURE="application/x-vnd.widelands"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/widelands.rdef.in > $sourceDir/widelands.rdef

	addResourcesToBinaries  $sourceDir/widelands.rdef \
		$appsDir/WideLands/WideLands
	addAppDeskbarSymlink $appsDir/WideLands/WideLands
}
