SUMMARY="A Library for generating Text, XML, JSON, and HTML Output"
DESCRIPTION="The libxo library allows an application to generate text, XML, \
JSON, and HTML output using a common set of function calls. The application \
decides at run time which output style should be produced."
HOMEPAGE="https://github.com/Juniper/libxo"
COPYRIGHT="2014 Juniper Networks, Inc."
LICENSE="BSD (2-clause)"
REVISION="2"
SOURCE_URI="https://github.com/Juniper/libxo/releases/download/$portVersion/libxo-$portVersion.tar.gz"
CHECKSUM_SHA256="9f2f276d7a5f25ff6fbfc0f38773d854c9356e7f985501627d0c0ee336c19006"
PATCHES="libxo-$portVersion.patchset"

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

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

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

PROVIDES="
	libxo$secondaryArchSuffix = $portVersion
	lib:libxo$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku${secondaryArchSuffix}
	lib:libcrypto$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	"

PROVIDES_devel="
	libxo${secondaryArchSuffix}_devel = $portVersion
	cmd:libxo_config$commandSuffix = $libVersionCompat
	devel:libxo$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libxo$secondaryArchSuffix == $portVersion base
	devel:libcrypto$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	"

PROVIDES_tools="
	libxo${secondaryArchSuffix}_tools = $portVersion
	cmd:xo$commandSuffix = $libVersionCompat
	cmd:xohtml$commandSuffix = $libVersionCompat
	cmd:xolint$commandSuffix = $libVersionCompat
	cmd:xopo$commandSuffix = $libVersionCompat
	"
REQUIRES_tools="
	libxo$secondaryArchSuffix == $portVersion base
	haiku${secondaryArchSuffix}
	lib:libintl$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:msgfmt$secondaryArchSuffix
	cmd:gawk
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

defineDebugInfoPackage libxo$secondaryArchSuffix \
	$libDir/libxo.so.$libVersion

BUILD()
{
	LDFLAGS="-lbsd -lnetwork" CFLAGS="-D_DEFAULT_SOURCE" \
		runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install

	rm -rf $libDir/libxo.la
	rm -rf $libDir/libxo/encoder/*.la

	prepareInstalledDevelLib \
		libxo
	fixPkgconfig

	packageEntries devel \
		$commandBinDir/libxo-config \
		$developDir
	packageEntries tools \
		$commandBinDir \
		$dataDir \
		$manDir
}

TEST()
{
	make check
}
