SUMMARY="Libraries to write tests in C, C++ and shell"
DESCRIPTION="ATF, or Automated Testing Framework, is a collection of libraries \
to write test programs in C, C++ and POSIX shell.

The ATF libraries offer a simple API. The API is orthogonal through \
the various bindings, allowing developers to quickly learn how to write \
test programs in different languages.

ATF-based test programs offer a consistent end-user command-line interface to \
allow both humans and automation to run the tests.

ATF-based test programs rely on an execution engine to be run and \
this execution engine is not shipped with ATF. Kyua is the engine of choice."
HOMEPAGE="https://github.com/jmmv/atf"
COPYRIGHT="2007-2012 The NetBSD Foundation, Inc.
	2011, 2012, 2014 Google Inc."
LICENSE="BSD (2-clause)
	BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/jmmv/atf/releases/download/atf-$portVersion/atf-$portVersion.tar.gz"
CHECKSUM_SHA256="92bc64180135eea8fe84c91c9f894e678767764f6dbc8482021d4dde09857505"
PATCHES="atf-$portVersion.patchset"

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

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

libVersion="1.0.0"
libCppVersion="2.0.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
libCppVersionCompat="$libCppVersion compat >= ${libCppVersion%%.*}"

PROVIDES="
	atf$secondaryArchSuffix = $portVersion
	cmd:atf_sh$secondaryArchSuffix = $portVersion
	lib:libatf_c$secondaryArchSuffix = $libVersionCompat
	lib:libatf_c++$secondaryArchSuffix = $libCppVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	atf${secondaryArchSuffix}_devel = $portVersion
	devel:libatf_c$secondaryArchSuffix = $libVersionCompat
	devel:libatf_c++$secondaryArchSuffix = $libCppVersionCompat
	"
REQUIRES_devel="
	atf$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:awk
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:make
	cmd:sed
	"

TEST_REQUIRES="
	cmd:kyua$commandSuffix
	"

defineDebugInfoPackage atf$secondaryArchSuffix \
	"$binDir/atf-sh" \
	"$libDir/libatf-c.so.$libVersion" \
	"$libDir/libatf-c++.so.$libCppVersion"

BUILD()
{
	CPPFLAGS="-D_BSD_SOURCE" LIBS="-Wl,--as-needed -lbsd" \
	runConfigure --omit-dirs "libExecDir" ./configure \
		--libexecdir="$libExecDir/atf" \
		--enable-developer=no
	make $jobArgs
}

INSTALL()
{
	make install

	rm "$docDir"/{COPYING,README}

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

	prepareInstalledDevelLibs libatf-c++ libatf-c
	fixPkgconfig
	# Turns out their .pc files don't have ${prefix}
	sed -e "s|\${prefix}|$prefix|g" -i "$developLibDir/pkgconfig"/*.pc
	sed \
		-e "s|\${exec_prefix}/bin/atf-sh|$binDir/atf-sh|" \
		-i "$developLibDir/pkgconfig/atf-sh.pc"
	packageEntries devel \
		"$developDir" \
		"$dataDir/aclocal" \
		"$manDir/man3"/atf-c*
}

TEST()
{
	CPATH="$PWD" kyua test
}
