SUMMARY="A port of Star Control II"
DESCRIPTION="The project started in August 2002, when Toys For Bob released \
the partially ported sources of Star Control 2 3DO version to the fan \
community. Our goal is to port this wonderful game to current personal \
computers and operating systems.
It is and will remain 100% free of charge, and anyone can contribute to the \
project and thus help make it even better. For more information, look at \ ourinfo page."
HOMEPAGE="http://sc2.sourceforge.net/"
COPYRIGHT="2005-2018 VCMI Team"
LICENSE="GNU GPL v2"
REVISION="4"
SOURCE_URI="https://sourceforge.net/projects/sc2/files/UQM/0.7/uqm-$portVersion-1-source.tgz"
CHECKSUM_SHA256="136015af296b03e45a47cd19e6c4815de118c26e56548dc75d182f8d8bd028e7"
SOURCE_DIR="uqm-$portVersion-1"
SOURCE_URI_2="https://sourceforge.net/projects/sc2/files/UQM/0.7/uqm-$portVersion-content.uqm#noarchive"
CHECKSUM_SHA256_2="b8f6db8ba29f0628fb1d5c233830896b19f441aee3744bda671ea264b44da3bf"
SOURCE_URI_3="https://sourceforge.net/projects/sc2/files/UQM/0.7/uqm-$portVersion-voice.uqm#noarchive"
CHECKSUM_SHA256_3="bcccf801b4ba37594ff6217b292744ea586ee2d447e927804842ccae8b73c979"
SOURCE_URI_4="https://sourceforge.net/projects/sc2/files/UQM/0.7/uqm-$portVersion-3domusic.uqm#noarchive"
CHECKSUM_SHA256_4="c57085e64dad4bddf8a679a9aa2adf63f2156d5f6cbabe63af80519033dbcb82"

PATCHES="uqm-$portVersion.patchset"
ADDITIONAL_FILES="uqm.rdef.in"

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

PROVIDES="
	uqm$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libmikmod$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libpng$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libsdl_image$secondaryArchSuffix
	lib:libvorbisfile$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libmikmod$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libSDL$secondaryArchSuffix
	devel:libsdl_image$secondaryArchSuffix
	devel:libvorbisfile$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:as$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	cmd:tr
	"

PATCH()
{
	sed -i -e '/read CHOICE/d' build/unix/menu_functions
	sed -i -e "s/-O3//" build/unix/build.config
	sed -i -e "s:~/.uqm/:~/config/settings/UQM/:g" src/config_unix.h.in
}

BUILD()
{
	cat <<-EOF > config.state
	CHOICE_debug_VALUE='nodebug'
	CHOICE_graphics_VALUE='pure'
	CHOICE_sound_VALUE='mixsdl'
	CHOICE_accel_VALUE='asm'
	INPUT_install_prefix_VALUE='$appsDir/UQM'
	INPUT_install_bindir_VALUE='$appsDir/UQM'
	INPUT_install_libdir_VALUE='$appsDir/UQM/lib'
	INPUT_install_sharedir_VALUE='$appsDir/UQM'
	EOF

	./build.sh uqm
}

INSTALL()
{
	mkdir -p $appsDir/UQM/content/addons
	mkdir -p $appsDir/UQM/content/packages
	cp -f uqm "$appsDir/UQM/The Ur-Quan Masters"
	cp $sourceDir2/uqm-$portVersion-content.uqm $appsDir/UQM/content/packages
	cp $sourceDir3/uqm-$portVersion-voice.uqm $appsDir/UQM/content/addons
	cp $sourceDir4/uqm-$portVersion-3domusic.uqm $appsDir/UQM/content/addons
	echo $portVersion > $appsDir/UQM/content/version

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

	addResourcesToBinaries $sourceDir/uqm.rdef "$appsDir/UQM/The Ur-Quan Masters"
	addAppDeskbarSymlink "$appsDir/UQM/The Ur-Quan Masters"
}
