SUMMARY="The free space simulation to explore our universe in 3 dimensions"
DESCRIPTION="Unlike most planetarium software, Celestia doesn't confine you to \
the surface of the Earth. You can travel throughout the solar system, to any of \
over 100,000 stars, or even beyond the galaxy.

All movement in Celestia is seamless; the exponential zoom feature lets you \
explore space across a huge range of scales, from galaxy clusters down to \
spacecraft only a few meters across. A 'point-and-goto' interface makes it \
simple to navigate through the universe to the object you want to visit.

Celestia is expandable. Celestia comes with a large catalog of stars, galaxies, \
planets, moons, asteroids, comets, and spacecraft. If that's not enough, you \
can download dozens of easy to install add-ons with more objects."
HOMEPAGE="http://celestia.sourceforge.net"
COPYRIGHT="2001-2020 Celestia Development Team"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://fossies.org/linux/misc/Celestia-$portVersion.tar.gz"
CHECKSUM_SHA256="be146fa9d6f4c38c686cc1728677d73e4457d85dbf051e485f24537c3e4d452d"
SOURCE_DIR="Celestia-$portVersion"
PATCHES="celestia-$portVersion.patchset"
ADDITIONAL_FILES="celestia.rdef.in"

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

GLOBAL_WRITABLE_FILES="
	settings/Celestia/scripts directory auto-merge
	settings/Celestia/celestia.cfg keep-old
	"

PROVIDES="
	celestia$secondaryArchSuffix = $portVersion
	app:celestia$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgl$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblua5.1$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autoreconf
	cmd:gcc$secondaryArchSuffix
	cmd:gettext
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	local
	for cf in -O2 -ffast-math \
		-fexpensive-optimizations \
		-fomit-frame-pointer; do
		sed -i \
			-e "s/${cf}//g" \
			configure.ac admin/* || die "sed failed"
	done

	autoreconf -fi

	export LIBS="-lbe -lGL -lGLU -lglut -lintl -lnetwork"

	runConfigure ./configure \
		--datarootdir=$dataDir \
		--datadir=$dataDir \
		--disable-rpath \
		--with-glut \
		--with-lua

	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir $settingsDir/Celestia
	make install
	mv $binDir/celestia $appsDir/Celestia
	rm -rf $binDir

	mv $dataDir/celestia/scripts $settingsDir/Celestia
	ln -s $settingsDir/Celestia/scripts $dataDir/celestia/scripts
	mv $dataDir/celestia/celestia.cfg $settingsDir/Celestia
	ln -s $settingsDir/Celestia/celestia.cfg $dataDir/celestia/celestia.cfg

	local APP_SIGNATURE="application/x-vnd.celestia"
	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/celestia.rdef.in > celestia.rdef

	addResourcesToBinaries celestia.rdef $appsDir/Celestia
	mimeset -f $appsDir/Celestia
	addAppDeskbarSymlink $appsDir/Celestia
}
