SUMMARY="A lightweight C++ API library for Lua"
DESCRIPTION="Lutok provides thin C++ wrappers around the Lua C API to ease the \
interaction between C++ and Lua. These wrappers make intensive use of RAII to \
prevent resource leakage, expose C++-friendly data types, report errors by means \
of exceptions and ensure that the Lua stack is always left untouched in the face \
of errors. The library also provides a small subset of miscellaneous utility \
functions built on top of the wrappers.

Lutok focuses on providing a clean and safe C++ interface; the drawback is that \
it is not suitable for performance-critical environments. In order to implement \
error-safe C++ wrappers on top of a Lua C binary library, Lutok adds several \
layers of abstraction and error checking that go against the original spirit of \
the Lua C API and thus degrade performance."
HOMEPAGE="https://github.com/jmmv/lutok"
COPYRIGHT="2011, 2012, 2014 Google Inc"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/jmmv/lutok/releases/download/lutok-$portVersion/lutok-$portVersion.tar.gz"
CHECKSUM_SHA256="2cec51efa0c8d65ace8b21eaa08384b77abc5087b46e785f78de1c21fb754cd5"

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

commandSuffix="$secondaryArchSuffix"
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=""
fi

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

PROVIDES="
	lutok$secondaryArchSuffix = $portVersion
	lib:liblutok$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix
	"

PROVIDES_devel="
	lutok${secondaryArchSuffix}_devel = $portVersion
	devel:liblutok$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	lutok$secondaryArchSuffix == $portVersion base
	devel:liblua$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liblua$secondaryArchSuffix
	devel:libatf_c++$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:atf_sh$secondaryArchSuffix
	cmd:awk
	cmd:diff
	cmd:doxygen
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

TEST_REQUIRES="
	cmd:kyua$commandSuffix
	"

defineDebugInfoPackage lutok$secondaryArchSuffix \
	"$libDir/liblutok.so.$libVersion"

BUILD()
{
	runConfigure --omit-dirs docDir ./configure \
		--docdir="$developDocDir" \
		--enable-developer=no
	make $jobArgs
}

INSTALL()
{
	make install

	install -d -m 755 "$docDir"
	mv "$developDocDir/AUTHORS" "$docDir"
	rm "$developDocDir"/{README,COPYING}

	rm -f "$libDir"/*.la
	rm -rf "$prefix"/tests

	prepareInstalledDevelLib liblutok
	fixPkgconfig
	# Not all .pc file use ${prefix}
	sed -e "s|\${prefix}|$prefix|g" -i "$developLibDir/pkgconfig/lutok.pc"
	packageEntries devel "$developDir"
}

TEST()
{
	make check
}
