SUMMARY="A Regular Expression Library"
DESCRIPTION="RE2 is a fast, safe, thread-friendly alternative to backtracking \
regular expression engines like those used in PCRE, PERL and Python. It is a \
C++ library."
HOMEPAGE="https://github.com/google/re2"
COPYRIGHT="2009-2018 The RE2 Authors"
LICENSE="BSD (3-clause)"
REVISION="3"
RE_VERSION="${portVersion//./-}"
SOURCE_URI="https://github.com/google/re2/archive/$RE_VERSION.tar.gz"
CHECKSUM_SHA256="b0382aa7369f373a0148218f2df5a6afd6bfa884ce4da2dfb576b979989e615e"
SOURCE_FILENAME="re2-$portVersion.tar.gz"
SOURCE_DIR="re2-$RE_VERSION"
PATCHES="re2-$portVersion.patchset"

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

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

PROVIDES="
	re2$secondaryArchSuffix = $portVersion
	lib:libre2$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	re2${secondaryArchSuffix}_devel = $portVersion
	devel:libre2$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	re2$secondaryArchSuffix == $portVersion base
	"

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

defineDebugInfoPackage re2$secondaryArchSuffix \
	$libDir/libre2.so.$libVersion

BUILD()
{
	make $jobArgs
}

INSTALL()
{
	make prefix=$prefix libdir=$libDir install

	mkdir -p $includeDir
	mv $prefix/include/* $includeDir
	rmdir $prefix/include

	echo -e "prefix=$prefix\n$(cat $libDir/pkgconfig/re2.pc)" \
		> $libDir/pkgconfig/re2.pc
	sed -i -e "s/\-pthread//g" $libDir/pkgconfig/re2.pc
	# prepare develop/lib
	prepareInstalledDevelLibs libre2
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	LIBRARY_PATH="$sourceDir/obj/so${LIBRARY_PATH:+:$LIBRARY_PATH}" \
	make test
}
