SUMMARY="A Simulator Construction Toolkit"
DESCRIPTION="SimGear is a set of open-source libraries designed as building \
blocks for quickly assembling 3D simulations, games, and visualization \
applications."
HOMEPAGE="https://home.flightgear.org/"
COPYRIGHT="2002-2018 Curtis Olsen and others"
LICENSE="GNU GPL v2"
REVISION="5"
SOURCE_URI="https://downloads.sourceforge.net/flightgear/simgear-$portVersion.tar.bz2"
CHECKSUM_SHA256="f61576bc36aae36f350154749df1cee396763604c06b8a71c4b50452d9151ce5"
PATCHES="simgear-$portVersion.patchset"

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

libVersion="$portVersion"

PROVIDES="
	simgear$secondaryArchSuffix = $portVersion
	lib:libSimGearCored$secondaryArchSuffix = $libVersion
	lib:libSimGearScened$secondaryArchSuffix = $libVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libosg$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	simgear${secondaryArchSuffix}_devel = $portVersion
	devel:libSimGearCored$secondaryArchSuffix = $libVersion
	devel:libSimGearScened$secondaryArchSuffix = $libVersion
	"
REQUIRES_devel="
	simgear$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_system$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libosg$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage simgear$secondaryArchSuffix \
	"$libDir"/libSimGearCored.so.$libVersion \
	"$libDir"/libSimGearScened.so.$libVersion \


PATCH()
{
	sed -i \
		-e "/^[ ]*install .*DESTINATION include/ \
			s|include\(/simgear/\)|$relativeIncludeDir\1|" \
		CMakeLists.txt \
		simgear/CMakeLists.txt \
		CMakeModules/SimGearComponent.cmake
}

BUILD()
{
	mkdir -p build && cd build
	cmake .. $cmakeDirArgs \
		-DCMAKE_INSTALL_PREFIX:PATH="$prefix" \
		-DCMAKE_INSTALL_INCLUDEDIR:PATH="$includeDir" \
		-DCMAKE_INSTALL_LIBDIR:PATH="$libDir" \
		-DSIMGEAR_SHARED:BOOL=ON \
		-DENABLE_TESTS:BOOL=OFF
	make $jobArgs
}

INSTALL()
{
	cd build
	cmake -P cmake_install.cmake

	sed -i \
		-e "s|\(\${_IMPORT_PREFIX}/\)include;|\1$relativeIncludeDir;|" \
		"$libDir"/cmake/SimGear/SimGearTargets.cmake

	prepareInstalledDevelLibs libSimGearCored libSimGearScened
	fixPkgconfig

	packageEntries devel \
		"$developDir" \
		"$libDir"/cmake
}
