SUMMARY="Perl5 Compatible Regular Expressions"
DESCRIPTION="The PCRE library is a set of functions that implement regular \
expression pattern matching using the same syntax and semantics as Perl 5. \
PCRE has its own native API, as well as a set of wrapper functions that \
correspond to the POSIX regular expression API. The PCRE library is free, even \
for building proprietary software.
This package contains the native API."
COPYRIGHT="1997-2018 University of Cambridge
	2007-2012, Google Inc. All rights reserved."
HOMEPAGE="http://www.pcre.org/"
LICENSE="PCRE"
REVISION="1"
SOURCE_URI="https://ftp.pcre.org/pub/pcre/pcre-$portVersion.tar.bz2"
CHECKSUM_SHA256="4dae6fdcd2bb0bb6c37b5f97c33c2be954da743985369cddac3546e3218bffb8"
SOURCE_DIR="pcre-$portVersion"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

pcreLibs="\
	libpcre \
	libpcre16 \
	libpcre32 \
	libpcrecpp \
	libpcreposix \
	"
libpcreVersion="1.2.13"
libpcrecppVersion="0.0.2"
libpcreposixVersion="0.0.7"
portVersionCompat="$portVersion compat >= 8"
for i in $pcreLibs; do
	eval "${i}VersionCompat=\"\$${i}Version compat >= \${${i}Version%%.*}\""
done

PROVIDES="
	libpcre$secondaryArchSuffix = $portVersion
	lib:libpcre$secondaryArchSuffix = $libpcreVersionCompat
	lib:libpcre16$secondaryArchSuffix = $libpcreVersionCompat
	lib:libpcre32$secondaryArchSuffix = $libpcreVersionCompat
	lib:libpcrecpp$secondaryArchSuffix = $libpcrecppVersionCompat
	lib:libpcreposix$secondaryArchSuffix = $libpcreposixVersionCompat
	"
if [ -z "$secondaryArchSuffix" ];then
PROVIDES="$PROVIDES
	cmd:pcregrep = $portVersionCompat
	cmd:pcretest = $portVersionCompat
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	libpcre${secondaryArchSuffix}_devel = $portVersion
	cmd:pcre_config$secondaryArchSuffix = $portVersionCompat
	devel:libpcre$secondaryArchSuffix = $libpcreVersionCompat
	devel:libpcre16$secondaryArchSuffix = $libpcreVersionCompat
	devel:libpcre32$secondaryArchSuffix = $libpcreVersionCompat
	devel:libpcrecpp$secondaryArchSuffix = $libpcrecppVersionCompat
	devel:libpcreposix$secondaryArchSuffix = $libpcreposixVersionCompat
	"
REQUIRES_devel="
	libpcre$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

debugList=(
	"$libDir"/libpcre.so.$libpcreVersion
	"$libDir"/libpcrecpp.so.$libpcrecppVersion
	"$libDir"/libpcreposix.so.$libpcreposixVersion
	)
if [ -z "$secondaryArchSuffix" ]; then
for i in `echo "$PROVIDES" | sed -n -e \
		"s/^[\t]*cmd:\(.*\)$secondaryArchSuffix =.*/\1/p;"`; do
	debugList+=("$binDir"/$i)
done
fi
defineDebugInfoPackage libpcre$secondaryArchSuffix "${debugList[@]}"

BUILD()
{
	libtoolize --force --copy --install
	aclocal
	autoconf
	automake --add-missing
	runConfigure ./configure \
		--enable-pcre16 \
		--enable-pcre32 \
		--enable-utf8 \
		--enable-unicode-properties \
		--with-pic
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libpcre*.la

	# prepare develop/lib
	prepareInstalledDevelLibs $pcreLibs
	fixPkgconfig

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

	if [ -n "$secondaryArchSuffix" ]; then
		maybe_manDir_man1_pcre_config=
		maybe_manDir_man3=
	 	rm -rf $documentationDir
	else
		maybe_manDir_man1_pcre_config=$manDir/man1/pcre-config.1
		maybe_manDir_man3=$manDir/man3
	fi

	# devel package
	packageEntries devel \
		$binDir/pcre-config \
		$developDir \
		$maybe_manDir_man1_pcre_config \
		$maybe_manDir_man3

	if [ -n "$secondaryArchSuffix" ]; then
	 	rm -rf $binDir
	fi
}

TEST()
{
	make check
}
