SUMMARY="A high-level 3D graphics toolkit"
DESCRIPTION="Coin is an OpenGL-based, 3D graphics library that has its roots \
in the Open Inventor 2.1 API, which Coin still is compatible with."
HOMEPAGE="https://github.com/coin3d/coin"
COPYRIGHT="Kongsberg Oil & Gas Technologies AS"
LICENSE="BSD (3-clause)"
REVISION="2"
SOURCE_URI="https://github.com/coin3d/coin/archive/Coin-$portVersion.tar.gz"
CHECKSUM_SHA256="b00d2a8e9d962397cf9bf0d9baa81bcecfbd16eef675a98c792f5cf49eb6e805"
SOURCE_DIR="coin-Coin-$portVersion"
PATCHES="coin-4.0.0-0001-updated-to-cmake-3.14.patch
	coin-4.0.0-0002-cpack.d-is-now-optional.patch
	coin-4.0.0-0003-Partially-incorporating-coin4.0.0a-patch-from-gentoo.patch
	coin-4.0.0-0004-Added-coin-default.cfg.patch
	coin-4.0.0-0005-Slightly-fix-coin.cfg.cmake.in.patch"

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

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

PROVIDES="
	coin$secondaryArchSuffix = $portVersion
	lib:libcoin$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
#	lib:libmozjs185$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	coin${secondaryArchSuffix}_devel = $portVersion
	cmd:coin_config$secondaryArchSuffix
	devel:libcoin$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	coin$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_system$secondaryArchSuffix
	devel:libboost_thread$secondaryArchSuffix
	devel:libbz2$secondaryArchSuffix
	devel:libexpat$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgl$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
#	devel:libmozjs185$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:doxygen
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage coin$secondaryArchSuffix \
	"$libDir"/libCoin.so.$libVersion

BUILD()
{
	mkdir -p haiku-build
	cd haiku-build

	cmake .. \
		-DCMAKE_INSTALL_PREFIX:PATH="$prefix" \
		-DCMAKE_INSTALL_BINDIR="$binDir" \
		-DCMAKE_INSTALL_DATAROOTDIR="$dataDir" \
		-DCMAKE_INSTALL_DOCDIR="$docDir" \
		-DCMAKE_INSTALL_FULL_DOCDIR="$docDir" \
		-DCMAKE_INSTALL_INCLUDEDIR="$includeDir" \
		-DCMAKE_INSTALL_LIBDIR="$libDir" \
		-DCMAKE_INSTALL_MANDIR="$manDir" \
		-DCOIN_BUILD_TESTS=NO \
		-DCOIN_BUILD_SHARED_LIBS=ON \
		-DCOIN_BUILD_DOCUMENTATION=ON \
		-DCOIN_BUILD_INTERNAL_DOCUMENTATION=OFF \
		-DCOIN_BUILD_DOCUMENTATION_MAN=ON \
		-DCOIN_BUILD_DOCUMENTATION_CHM=OFF \
		-DCOIN_THREADSAFE=ON \
		-DHAVE_VRML97=ON \
		-DCOIN_HAVE_JAVASCRIPT=OFF \
		-DHAVE_NODEKITS=ON \
		-DHAVE_DRAGGERS=ON \
		-DHAVE_MANIPULATORS=ON \
		-DHAVE_SOUND=OFF \
		-DHAVE_3DS_IMPORT_CAPABILITIES=ON \
		-DUSE_EXTERNAL_EXPAT=ON \
		-DUSE_EXCEPTIONS=ON \
		-DUSE_SUPERGLU=OFF \
		-DFONTCONFIG_RUNTIME_LINKING=OFF \
		-DFREETYPE_RUNTIME_LINKING=OFF \
		-DLIBBZIP2_RUNTIME_LINKING=OFF \
		-DOPENAL_RUNTIME_LINKING=OFF \
		-DSIMAGE_RUNTIME_LINKING=OFF \
		-DZLIB_RUNTIME_LINKING=OFF \
		-DGLU_RUNTIME_LINKING=OFF \
		-DSPIDERMONKEY_RUNTIME_LINKING=ON \
		-DCOIN_VERBOSE=NO \
		-DHAVE_MULTIPLE_VERSION=OFF \
		-DCOIN_BUILD_SINGLE_LIB=ON

	make $jobArgs
}

INSTALL()
{
	cd haiku-build
	make install


	prepareInstalledDevelLib libCoin
	fixPkgconfig

	packageEntries devel \
		$binDir \
		$developDir \
		$libDir/cmake \
		$manDir/man3
}

TEST()
{
	#Tests are broken (PIC/PIE)
	cd haiku-build
	make check
}
