SUMMARY="High performance OpenGL-based 3D graphics toolkit"
DESCRIPTION="The OpenSceneGraph is an open source high performance 3D \
graphics toolkit, used by application developers in fields such as visual \
simulation, games, virtual reality, scientific visualization and modelling. \
Written entirely in Standard C++ and OpenGL it runs on all Windows platforms, \
OSX, GNU/Linux, IRIX, Solaris, HP-Ux, AIX and FreeBSD operating systems. The \
OpenSceneGraph is now well established as the world leading scene graph \
technology, used widely in the vis-sim, space, scientific, oil-gas, games and \
virtual reality industries."
HOMEPAGE="http://www.openscenegraph.org/"
COPYRIGHT="2002-2018 Robert Osfield and others"
LICENSE="OSGPL"
REVISION="1"
SOURCE_URI="https://github.com/openscenegraph/OpenSceneGraph/archive/OpenSceneGraph-$portVersion.tar.gz"
CHECKSUM_SHA256="aea196550f02974d6d09291c5d83b51ca6a03b3767e234a8c0e21322927d1e12"
SOURCE_DIR="OpenSceneGraph-OpenSceneGraph-$portVersion"
PATCHES="openscenegraph-$portVersion.patchset"

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

libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
libOpenThreadsVersion="3.3.1"
libOpenThreadsVersionCompat="$libOpenThreadsVersion compat >= ${libOpenThreadsVersion%%.*}"

PROVIDES="
	openscenegraph$secondaryArchSuffix = $portVersion
	lib:libOpenThreads$secondaryArchSuffix = $libOpenThreadsVersionCompat
	lib:libosg$secondaryArchSuffix = $libVersionCompat
	lib:libosgAnimation$secondaryArchSuffix = $libVersionCompat
	lib:libosgDB$secondaryArchSuffix = $libVersionCompat
	lib:libosgFX$secondaryArchSuffix = $libVersionCompat
	lib:libosgGA$secondaryArchSuffix = $libVersionCompat
	lib:libosgManipulator$secondaryArchSuffix = $libVersionCompat
	lib:libosgParticle$secondaryArchSuffix = $libVersionCompat
	lib:libosgPresentation$secondaryArchSuffix = $libVersionCompat
	lib:libosgShadow$secondaryArchSuffix = $libVersionCompat
	lib:libosgSim$secondaryArchSuffix = $libVersionCompat
	lib:libosgTerrain$secondaryArchSuffix = $libVersionCompat
	lib:libosgText$secondaryArchSuffix = $libVersionCompat
	lib:libosgUI$secondaryArchSuffix = $libVersionCompat
	lib:libosgUtil$secondaryArchSuffix = $libVersionCompat
	lib:libosgViewer$secondaryArchSuffix = $libVersionCompat
	lib:libosgVolume$secondaryArchSuffix = $libVersionCompat
	lib:libosgWidget$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	mesa$secondaryArchSuffix
#	lib:libavcodec$secondaryArchSuffix
	lib:libcairo$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libEGL$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgdal$secondaryArchSuffix
	lib:libgif$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
#	lib:libgstreamer_1.0$secondaryArchSuffix
	lib:libhalf$secondaryArchSuffix
	lib:libIlmImf$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjasper$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
#	lib:libOpenCOLLADABaseUtils$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libpoppler${secondaryArchSuffix}_glib
	lib:libsdl$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
#	lib:libTKGeomBase$secondaryArchSuffix #opencascade
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	openscenegraph${secondaryArchSuffix}_devel = $portVersion
	devel:libOpenThreads$secondaryArchSuffix = $libVersionCompat
	devel:libosg$secondaryArchSuffix = $libVersionCompat
	devel:libosgAnimation$secondaryArchSuffix = $libVersionCompat
	devel:libosgDB$secondaryArchSuffix = $libVersionCompat
	devel:libosgFX$secondaryArchSuffix = $libVersionCompat
	devel:libosgGA$secondaryArchSuffix = $libVersionCompat
	devel:libosgManipulator$secondaryArchSuffix = $libVersionCompat
	devel:libosgParticle$secondaryArchSuffix = $libVersionCompat
	devel:libosgPresentation$secondaryArchSuffix = $libVersionCompat
	devel:libosgShadow$secondaryArchSuffix = $libVersionCompat
	devel:libosgSim$secondaryArchSuffix = $libVersionCompat
	devel:libosgTerrain$secondaryArchSuffix = $libVersionCompat
	devel:libosgText$secondaryArchSuffix = $libVersionCompat
	devel:libosgUI$secondaryArchSuffix = $libVersionCompat
	devel:libosgUtil$secondaryArchSuffix = $libVersionCompat
	devel:libosgViewer$secondaryArchSuffix = $libVersionCompat
	devel:libosgVolume$secondaryArchSuffix = $libVersionCompat
	devel:libosgWidget$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	openscenegraph$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
#	devel:libavcodec$secondaryArchSuffix
	devel:libcairo$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libEGL$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgdal$secondaryArchSuffix >= 28
	devel:libgif$secondaryArchSuffix >= 7
	devel:libgl$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
#	devel:libgstreamer_1.0$secondaryArchSuffix
	devel:libilmimf_2_4$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjasper$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
#	devel:libOpenCOLLADABaseUtils$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libpoppler${secondaryArchSuffix}_glib >= 8.12
	devel:libsdl$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix >= 5
#	devel:libTKGeomBase$secondaryArchSuffix #opencascade
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage openscenegraph$secondaryArchSuffix \
	$libDir/libOpenThreads.so.$libOpenThreadsVersion \
	$libDir/libosg.so.$libVersion \
	$libDir/libosgAnimation.so.$libVersion \
	$libDir/libosgDB.so.$libVersion \
	$libDir/libosgFX.so.$libVersion \
	$libDir/libosgGA.so.$libVersion \
	$libDir/libosgManipulator.so.$libVersion \
	$libDir/libosgParticle.so.$libVersion \
	$libDir/libosgPresentation.so.$libVersion \
	$libDir/libosgShadow.so.$libVersion \
	$libDir/libosgSim.so.$libVersion \
	$libDir/libosgTerrain.so.$libVersion \
	$libDir/libosgText.so.$libVersion \
	$libDir/libosgUI.so.$libVersion \
	$libDir/libosgUtil.so.$libVersion \
	$libDir/libosgViewer.so.$libVersion \
	$libDir/libosgVolume.so.$libVersion \
	$libDir/libosgWidget.so.$libVersion

BUILD()
{
	mkdir -p build && cd build
	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DBUILD_OSG_APPLICATIONS:BOOL=OFF \
		-DOSG_GL3_AVAILABLE:BOOL=ON \
		-DOSG_WINDOWING_SYSTEM=None \
		$cmakeDirArgs
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mkdir -p $includeDir
	mv $prefix/include/* $includeDir/
	rm -rf $prefix/include

	# Secondary-arch libdir cleanup
	mkdir -p $prefix/lib-temp
	mv $prefix/lib/* $prefix/lib-temp/
	mkdir -p $libDir
	mv $prefix/lib-temp/* $libDir
	rm -rf $prefix/lib-temp

	# Move plugins to system addons directory
	mkdir -p $addOnsDir
	mv $libDir/osgPlugins-$portVersion $addOnsDir

	prepareInstalledDevelLibs libOpenThreads libosg libosgAnimation libosgDB \
		libosgFX libosgGA libosgManipulator libosgParticle libosgPresentation \
		libosgShadow libosgSim libosgTerrain libosgText libosgUI libosgUtil \
		libosgViewer libosgVolume libosgWidget

	fixPkgconfig

	packageEntries devel \
		$developDir
}
