SUMMARY="Memory efficient serialization library"
DESCRIPTION="FlatBuffers is an efficient cross platform serialization library \
for C++, C#, C, Go, Java, JavaScript, Lobster, Lua, TypeScript, PHP, Python, \
and Rust. It was originally created at Google for game development and other \
performance-critical applications."
HOMEPAGE="https://google.github.io/flatbuffers/"
COPYRIGHT="2014 Google Inc."
LICENSE="Apache v2"
REVISION="1"
SOURCE_URI="https://github.com/google/flatbuffers/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="62f2223fb9181d1d6338451375628975775f7522185266cd5296571ac152bc45"
SOURCE_FILENAME="flatbuffers-$portVersion.tar.gz"

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

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

PROVIDES="
	flatbuffers$secondaryArchSuffix = $portVersion
	lib:libflatbuffers$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	flatbuffers${secondaryArchSuffix}_devel = $portVersion
	cmd:flatc$secondaryArchSuffix = $portVersion
	devel:libflatbuffers$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	haiku$secondaryArchSuffix
	flatbuffers$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	"

defineDebugInfoPackage flatbuffers$secondaryArchSuffix \
	"$libDir"/libflatbuffers.so.$portVersion

BUILD()
{
	mkdir -p haiku_build
	cd haiku_build

	cmake .. \
		-DFLATBUFFERS_BUILD_SHAREDLIB=ON \
		-DFLATBUFFERS_BUILD_FLATLIB=OFF \
		-DFLATBUFFERS_BUILD_FLATC=ON \
		-DFLATBUFFERS_BUILD_FLATHASH=ON \
		-DFLATBUFFERS_BUILD_TESTS=ON \
		-DFLATBUFFERS_INSTALL=ON \
		$cmakeDirArgs

	make $jobArgs
}

INSTALL()
{
	cd haiku_build
	make install

	install -d -m 755 "$binDir"
	install -m 755 -t "$binDir" flatc

	# prepare develop/lib
	prepareInstalledDevelLibs libflatbuffers

	# devel package
	packageEntries devel \
		$binDir \
		$developDir \
		$libDir/cmake
}

TEST()
{
	cd haiku_build
	make test
}
