SUMMARY="O A.D. - Game"
DESCRIPTION="A free, open-source, Real-Time Strategy (RTS) game."
HOMEPAGE="https://play0ad.com/"
COPYRIGHT="Wildfire Games"
LICENSE="0ADLicense"
REVISION="7"
SOURCE_URI="https://releases.wildfiregames.com/0ad-${portVersion/\~/-}-unix-build.tar.xz"
CHECKSUM_SHA256="01bff7641ee08cac896c54d518d7e4b01752513105558f212e3199d747512a37"
SOURCE_DIR="0ad-${portVersion/\~/-}"
PATCHES="0ad-$portVersion.patchset"
ADDITIONAL_FILES="0ad.rdef.in"

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

PROVIDES="
	0ad$secondaryArchSuffix = $portVersion
	app:0ad$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_filesystem$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libenet$secondaryArchSuffix
	lib:libgloox$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libicui18n$secondaryArchSuffix
	lib:libicuuc$secondaryArchSuffix
	lib:libminiupnpc$secondaryArchSuffix
	lib:libnspr4$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libplc4$secondaryArchSuffix
	lib:libplds4$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libsodium$secondaryArchSuffix
	lib:libvorbisfile$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	0ad_data == $portVersion
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_system$secondaryArchSuffix >= 1.69.0
	devel:libcurl$secondaryArchSuffix
	devel:libsdl2$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libnspr4$secondaryArchSuffix
	devel:libicudata$secondaryArchSuffix >= 66
	devel:libicui18n$secondaryArchSuffix >= 66
	devel:libicuio$secondaryArchSuffix >= 66
	devel:libicutest$secondaryArchSuffix >= 66
	devel:libicutu$secondaryArchSuffix >= 66
	devel:libicuuc$secondaryArchSuffix >= 66
	devel:libiconv$secondaryArchSuffix
	devel:libplc4$secondaryArchSuffix
	devel:libplds4$secondaryArchSuffix
	devel:libenet$secondaryArchSuffix
	devel:libgloox$secondaryArchSuffix
	devel:libminiupnpc$secondaryArchSuffix
	devel:libsodium$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	"

BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:g++$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:patch
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2
	cmd:sed
	cmd:which
	cmd:xargs
	"

BUILD()
{
	cd build/workspaces
	./update-workspaces.sh --disable-atlas --minimal-flags --without-pch \
		--datadir=$dataDir/0ad $jobArgs

	cd gcc
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/0ad $dataDir/0ad

	cp -R binaries/data/* $dataDir/0ad
	cp -R binaries/system/*.so binaries/system/pyrogenesis $appsDir/0ad

	local APP_SIGNATURE="application/x-vnd.pyrogenesis-0ad"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3 | cut -db -f1`"
	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/0ad.rdef.in > $sourceDir/build/0ad.rdef

	addResourcesToBinaries $sourceDir/build/0ad.rdef $appsDir/0ad/pyrogenesis

	addAppDeskbarSymlink $appsDir/0ad/pyrogenesis "0 A.D."
}

TEST()
{
	binaries/system/test -libdir "./binaries/system"
}
