SUMMARY="A free implementation of the unicode bidirectional algorithm"
DESCRIPTION="This is GNU FriBidi. The Free Implementation of the Unicode \
Bidirectional Algorithm. One of the missing links stopping the penetration \
of free software in Middle East is the lack of support for the Arabic and \
Hebrew alphabets. In order to have proper Arabic and Hebrew support, the \
BiDi algorithm should have been implemented. It is our hope that this \
library will stimulate more free software in the Middle Eastern countries."
HOMEPAGE="https://github.com/fribidi/fribidi"
COPYRIGHT="2004 Sharif FarsiWeb, Inc
	2001-2005 Behdad Esfahbod
	1999-2019 Dov Grobgeld"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://github.com/fribidi/fribidi/releases/download/v$portVersion/fribidi-$portVersion.tar.xz"
CHECKSUM_SHA256="30f93e9c63ee627d1a2cedcf59ac34d45bf30240982f99e44c6e015466b4e73d"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

commandBinDir=$binDir
commandSuffix=$secondaryArchSuffix
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

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

PROVIDES="
	fribidi$secondaryArchSuffix = $portVersion
	lib:libfribidi$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

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

if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES_tools="
		fribidi${secondaryArchSuffix}_tools = $portVersion
		cmd:fribidi$commandSuffix = $portVersion
		"
	REQUIRES_tools="
		fribidi$secondaryArchSuffix == $portVersion base
		haiku$secondaryArchSuffix
		"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autoheader
	cmd:automake
	cmd:autoreconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage fribidi$secondaryArchSuffix \
	$libDir/libfribidi.so.$libVersion

BUILD()
{
	autoreconf -vfi
	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libfribidi.la

		# remove command for secondary architecture
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf "$commandBinDir"
	fi

	prepareInstalledDevelLibs libfribidi
	fixPkgconfig

	if [ -z "$secondaryArchSuffix" ]; then
		maybe_manDir="$manDir"
	else
		rm -rf "$manDir"
		maybe_manDir=
	fi

	# devel package
	packageEntries devel \
		"$developDir" \
		${maybe_manDir:+"$maybe_manDir"}

	if [ -z "$secondaryArchSuffix" ]; then
		packageEntries tools \
			"$commandBinDir"
	fi
}

TEST()
{
	make check
}
