SUMMARY="A library to handle the Public Suffix List"
DESCRIPTION="A Public Suffix List is a collection of Top Level Domains (TLDs) \
suffixes. libpsl can be used by browsers and other web clients to avoid \
privacy-leaking \"supercookies\" or \"super domain\" certificates, highlight \
parts of the domain in a user interface, and sort domain lists by site."
HOMEPAGE="https://rockdaboot.github.io/libpsl/"
COPYRIGHT="2014-2018 Tim Rühsen"
LICENSE="libpsl"
REVISION="1"
SOURCE_URI="https://github.com/rockdaboot/libpsl/releases/download/$portVersion/libpsl-$portVersion.tar.gz"
CHECKSUM_SHA256="ac6ce1e1fbd4d0254c4ddb9d37f1fa99dec83619c1253328155206b896210d4c"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

IDNA=libidn2
if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
	IDNA=libidn
fi

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

PROVIDES="
	libpsl$secondaryArchSuffix = $portVersion
	cmd:psl$secondaryArchSuffix = $portVersion
	cmd:psl_make_dafsa$secondaryArchSuffix = $portVersion
	lib:libpsl$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libunistring$secondaryArchSuffix
	lib:$IDNA$secondaryArchSuffix
	"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libunistring$secondaryArchSuffix
	devel:$IDNA$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:automake
	cmd:autoheader
	cmd:autoreconf
	cmd:autopoint
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	"

defineDebugInfoPackage libpsl$secondaryArchSuffix \
	"$binDir"/psl \
	"$libDir"/libpsl.so.$libVersion

PATCH()
{
	sed -i -e "s/\<_UNUSED/_&/g" src/psl.c
}

BUILD()
{
	autoreconf
	runConfigure ./configure --enable-runtime=$IDNA --enable-builtin=$IDNA
	make $jobArgs LIBS="-lnetwork"
}

INSTALL()
{
	make install
	install -t "$binDir" src/psl-make-dafsa

	rm -f "$libDir"/libpsl.la "$libDir"/libpsl.a

	prepareInstalledDevelLib libpsl
	fixPkgconfig

	packageEntries devel \
		"$developDir"
}

TEST()
{
	make check
}
