SUMMARY="Perl5 Compatible Regular Expressions"
DESCRIPTION="The PCRE2 library is a set of functions that implement regular \
expression pattern matching using the same syntax and semantics as Perl 5. \
PCRE2 has its own native API, as well as a set of wrapper functions that \
correspond to the POSIX regular expression API. The PCRE2 library is free, \
even for building proprietary software.
PCRE2 is a re-working of the original PCRE library to provide an entirely new \
API."
HOMEPAGE="https://www.pcre.org/"
COPYRIGHT="1997-2017 University of Cambridge"
LICENSE="PCRE"
REVISION="1"
SOURCE_URI="https://github.com/PhilipHazel/pcre2/releases/download/pcre2-$portVersion/pcre2-$portVersion.tar.bz2"
CHECKSUM_SHA256="0f03caf57f81d9ff362ac28cd389c055ec2bf0678d277349a1a4bee00ad6d440"
SOURCE_DIR="pcre2-$portVersion"
PATCHES="libpcre2-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86 x86_gcc2"

libpcre2Version="0.10.4"
libpcre2posixVersion="3.0.1"
libpcre2VersionCompat="$libpcre2Version compat >= ${libpcre2Version%%.*}"
libpcre2posixVersionCompat="$libpcre2posixVersion compat >= ${libpcre2posixVersion%%.*}"
portVersionCompat="$portVersion compat >= 10"

PROVIDES="
	libpcre2$secondaryArchSuffix = $portVersionCompat
	cmd:pcre2grep$secondaryArchSuffix
	cmd:pcre2test$secondaryArchSuffix
	lib:libpcre2_16$secondaryArchSuffix = $libpcre2VersionCompat
	lib:libpcre2_32$secondaryArchSuffix = $libpcre2VersionCompat
	lib:libpcre2_8$secondaryArchSuffix = $libpcre2VersionCompat
	lib:libpcre2_posix$secondaryArchSuffix = $libpcre2posixVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libedit$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	libpcre2${secondaryArchSuffix}_devel = $portVersionCompat
	cmd:pcre2_config$secondaryArchSuffix = $portVersionCompat
	devel:libpcre2_16$secondaryArchSuffix = $libpcre2VersionCompat
	devel:libpcre2_32$secondaryArchSuffix = $libpcre2VersionCompat
	devel:libpcre2_8$secondaryArchSuffix = $libpcre2VersionCompat
	devel:libpcre2_posix$secondaryArchSuffix = $libpcre2posixVersionCompat
	"
REQUIRES_devel="
	libpcre2$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libedit$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	libtoolize --force --copy --install
	aclocal
	autoconf
	automake --add-missing
	jitOption=--enable-jit
	if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
		jitOption=--disable-jit
	fi
	runConfigure ./configure \
		--with-pic \
		--enable-pcre2-16 \
		--enable-pcre2-32 \
		$jitOption \
		--enable-pcre2grep-libz \
		--enable-pcre2grep-libbz2 \
		--enable-pcre2test-libedit \
		#--enable-pcre2test-libreadline \
		#--enable-debug
	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool files
	rm -f "$libDir"/libpcre2-*.la

	# prepare develop/lib
	prepareInstalledDevelLibs \
		libpcre2-8 \
		libpcre2-16 \
		libpcre2-32 \
		libpcre2-posix
	fixPkgconfig

	# fix pcre-config
	fixDevelopLibDirReferences $binDir/pcre2-config

	if [ -z "$secondaryArchSuffix" ]; then
		maybe_manDir_man1_pcre2_config="$manDir"/man1/pcre2-config.1
		maybe_manDir_man3="$manDir"/man3
	else
		maybe_manDir_man1_pcre2_config=
		maybe_manDir_man3=
		rm -rf "$documentationDir"
	fi

	# devel package
	packageEntries devel \
		"$binDir"/pcre2-config \
		"$developDir" \
		${maybe_manDir_man1_pcre2_config:+"$maybe_manDir_man1_pcre2_config"} \
		${maybe_manDir_man3:+"$maybe_manDir_man3"}
}

TEST()
{
	make check
}
