SUMMARY="A free Civilization-like game"
DESCRIPTION="Freeciv is a free Civilization-like game, primarily \
for X under Unix. It has support for multiplayer games locally or \
over a network, and an AI which gives most people a run for their money.
Freeciv aims to be mostly rule-compatible with Civilization II [tm], \
published by Sid Meier and Microprose [tm]. A few rules are different \
where we think it makes more sense, and we have lots and lots of \
adjustable parameters to make customizing games possible.
Freeciv has been implemented completely independently of Civilization; \
you do not need to own Civilization to play Freeciv."
HOMEPAGE="http://www.freeciv.org/"
COPYRIGHT="1996-2020 The Freeciv Team"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://netix.dl.sourceforge.net/project/freeciv/Freeciv%202.6/$portVersion/freeciv-$portVersion.tar.bz2"
CHECKSUM_SHA256="7bcfe5dd3c081122e7cde7cdb24f57c3681d6a9667496faed207a91ac3165811"
ADDITIONAL_FILES="freeciv.rdef.in"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ -z "${ARCHITECTURES##*!$targetArchitecture*}" ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

GLOBAL_WRITABLE_FILES="
	settings/freeciv/database.lua keep-old
	"

PROVIDES="
	freeciv$secondaryArchSuffix = $portVersion
	app:FreeCiv = $portVersion
	cmd:freeciv_manual$commandSuffix
	cmd:freeciv_sdl$commandSuffix
	cmd:freeciv_server$commandSuffix
	lib:libfreeciv$secondaryArchSuffix
	lib:libfreeciv_srv$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_gfx$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	lib:libSDL_mixer_1.2$secondaryArchSuffix
	lib:libSDL_ttf_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix >= 5.3
	devel:libintl$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libSDL_gfx$secondaryArchSuffix
	devel:libSDL_image_1.2$secondaryArchSuffix
	devel:libSDL_mixer_1.2$secondaryArchSuffix
	devel:libSDL_ttf_2.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	AUTOCONF=: AUTOMAKE=: ACLOCAL=: CFLAGS="-O2 -pipe" \
		runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir --enable-client=sdl --enable-fcmp=no \
		--enable-sys-lua --enable-shared --disable-static
	make $jobArgs
}

INSTALL()
{
	make install

	rm -f $libDir/*.a $libDir/*.la

	mkdir -p $appsDir
	ln -s $commandBinDir/freeciv-sdl $appsDir/Freeciv

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local INTERNAL="0"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@INTERNAL@|$INTERNAL|" \
		$portDir/additional-files/freeciv.rdef.in > freeciv.rdef

	addResourcesToBinaries freeciv.rdef \
		$appsDir/Freeciv

	addAppDeskbarSymlink $appsDir/Freeciv
	mv $prefix/share/* $dataRootDir
	rmdir $prefix/share
}
