SUMMARY="Continuous Collision Detection and Physics Library"
DESCRIPTION="Bullet Physics is a professional open source collision \
detection, rigid body and soft body dynamicslibrary written in portable C++. \
The library is primarily designed for use in games, visual effects \
and robotic simulation. The library is free for commercial use under \
the ZLib license."
HOMEPAGE="http://www.bulletphysics.com/"
COPYRIGHT="2003-2020 Erwin Coumans and the Bullet Physics Library Team"
LICENSE="Zlib"
REVISION="1"
SOURCE_URI="https://github.com/bulletphysics/bullet3/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="baa642c906576d4d98d041d0acb80d85dd6eff6e3c16a009b1abf1ccd2bc0a61"
SOURCE_DIR="bullet3-$portVersion"

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

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

PROVIDES="
	bullet$secondaryArchSuffix = $portVersion
	lib:libBullet2FileLoader$secondaryArchSuffix = $libVersionCompat
	lib:libBullet3Collision$secondaryArchSuffix = $libVersionCompat
	lib:libBullet3Common$secondaryArchSuffix = $libVersionCompat
	lib:libBullet3Dynamics$secondaryArchSuffix = $libVersionCompat
	lib:libBullet3Geometry$secondaryArchSuffix = $libVersionCompat
	lib:libBullet3OpenCL_clew$secondaryArchSuffix = $libVersionCompat
	lib:libBulletCollision$secondaryArchSuffix = $libVersionCompat
	lib:libBulletDynamics$secondaryArchSuffix = $libVersionCompat
	lib:libBulletInverseDynamics$secondaryArchSuffix = $libVersionCompat
	lib:libBulletSoftBody$secondaryArchSuffix = $libVersionCompat
	lib:libLinearMath$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:python3
	lib:libgl$secondaryArchSuffix
	lib:libglew$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	"

PROVIDES_devel="
	bullet${secondaryArchSuffix}_devel = $portVersion
	devel:libBullet2FileLoader$secondaryArchSuffix = $libVersionCompat
	devel:libBullet3Collision$secondaryArchSuffix = $libVersionCompat
	devel:libBullet3Common$secondaryArchSuffix = $libVersionCompat
	devel:libBullet3Dynamics$secondaryArchSuffix = $libVersionCompat
	devel:libBullet3Geometry$secondaryArchSuffix = $libVersionCompat
	devel:libBullet3OpenCL_clew$secondaryArchSuffix = $libVersionCompat
	devel:libBulletCollision$secondaryArchSuffix = $libVersionCompat
	devel:libBulletDynamics$secondaryArchSuffix = $libVersionCompat
	devel:libBulletInverseDynamics$secondaryArchSuffix = $libVersionCompat
	devel:libBulletSoftBody$secondaryArchSuffix = $libVersionCompat
	devel:libLinearMath$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	bullet$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgl$secondaryArchSuffix
	devel:libglew$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	"

defineDebugInfoPackage bullet$secondaryArchSuffix \
	$libDir/libBullet3Collision.so.$libVersion \
	$libDir/libBullet3Common.so.$libVersion \
	$libDir/libBullet3Dynamics.so.$libVersion \
	$libDir/libBullet3Geometry.so.$libVersion \
	$libDir/libBullet3OpenCL_clew.so.$libVersion \
	$libDir/libBullet2FileLoader.so.$libVersion \
	$libDir/libBulletCollision.so.$libVersion \
	$libDir/libBulletDynamics.so.$libVersion \
	$libDir/libBulletInverseDynamics.so.$libVersion \
	$libDir/libBulletSoftBody.so.$libVersion \
	$libDir/libLinearMath.so.$libVersion

BUILD()
{
	mkdir -p build_haiku
	cd build_haiku

	export LDFLAGS="-lroot -lnetwork -lbsd"
	export CFLAGS="-D_BSD_SOURCE"

	cmake .. \
		-Wno-dev \
		-DBUILD_SHARED_LIBS=ON \
		-DUSE_DOUBLE_PRECISION=ON \
		-DBUILD_BULLET2_DEMOS=OFF \
		-DBUILD_EXTRAS=OFF \
		-DBUILD_UNIT_TESTS=OFF \
		-DCMAKE_BUILD_TYPE=Release \
		-DINSTALL_LIBS=ON \
		-DLIB_SUFFIX="$secondaryArchSubDir" \
		-DINCLUDE_INSTALL_DIR="$includeDir/bullet/" \
		$cmakeDirArgs
	make $jobArgs
}

INSTALL()
{
	cd build_haiku

	make install

	prepareInstalledDevelLibs \
		libBullet3Collision \
		libBullet3Common \
		libBullet3Dynamics \
		libBullet3Geometry \
		libBullet3OpenCL_clew \
		libBullet2FileLoader \
		libBulletCollision \
		libBulletDynamics \
		libBulletInverseDynamics \
		libBulletSoftBody \
		libLinearMath

	fixPkgconfig

	sed -i "s|Cflags:.*|Cflags: -I$includeDir/bullet|" $developLibDir/pkgconfig/bullet.pc

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	make check
}
