SUMMARY="A probabilistic information retrieval library with numerous bindings"
DESCRIPTION="Xapian is an open source search engine library written in C++. \
It has bindings for a large number of other programming languages, including \
Perl, Python, Java and Ruby. It is hightly adaptable and extensible, fitting \
a wide range of information retrieval-related tasks. Xapian empowers the Omega \
search engine package. It supports a wide range of advanced features such as \
native Unicode support and modern search algorithms."
HOMEPAGE="https://xapian.org/"
COPYRIGHT="1999-2018 The Xapian Authors"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://oligarchy.co.uk/xapian/$portVersion/xapian-core-$portVersion.tar.xz"
CHECKSUM_SHA256="196ddbb4ad10450100f0991a599e4ed944cbad92e4a6fe813be6dce160244b77"
SOURCE_DIR="xapian-core-$portVersion"

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

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

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

PROVIDES="
	xapian$secondaryArchSuffix = $portVersion
	lib:libxapian$secondaryArchSuffix = $libVersionCompat
	cmd:copydatabase$commandSuffix = $portVersion
	cmd:quest$commandSuffix = $portVersion
	cmd:simpleexpand$commandSuffix = $portVersion
	cmd:simpleindex$commandSuffix = $portVersion
	cmd:simplesearch$commandSuffix = $portVersion
	cmd:xapian_check$commandSuffix = $portVersion
	cmd:xapian_compact$commandSuffix = $portVersion
	cmd:xapian_delve$commandSuffix = $portVersion
	cmd:xapian_metadata$commandSuffix = $portVersion
	cmd:xapian_pos$commandSuffix = $portVersion
	cmd:xapian_progsrv$commandSuffix = $portVersion
	cmd:xapian_replicate$commandSuffix = $portVersion
	cmd:xapian_replicate_server$commandSuffix = $portVersion
	cmd:xapian_tcpsrv$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libuuid$secondaryArchSuffix >= 1.3
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	xapian${secondaryArchSuffix}_devel = $portVersion
	devel:libxapian$secondaryArchSuffix = $libVersionCompat
	cmd:xapian_config$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	xapian$secondaryArchSuffix == $portVersion base
	"
if [ -n "$secondaryArchSuffix" -a "$commandBinDir" = "$binDir" ]; then
CONFLICTS_devel="
	xapian_devel
	"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libintl$secondaryArchSuffix
	devel:libuuid$secondaryArchSuffix >= 1.3
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmp
	cmd:diff
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

debugList=("$libDir"/libxapian.so.$libVersion)
for i in `echo "$PROVIDES" | sed -n -e \
		"s/^[\t]*cmd:\(.*\)$commandSuffix =.*/\1/p;" | sed -e "s/_/-/g"`; do
	debugList+=("$commandBinDir"/$i)
done
defineDebugInfoPackage xapian$secondaryArchSuffix "${debugList[@]}"

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

INSTALL()
{
	make install

	rm -f "$libDir"/libxapian.la

	if [ -n "$secondaryArchSuffix" -a "$commandBinDir" != "$binDir" ]; then
		mkdir -p "$binDir"
		mv "$commandBinDir"/xapian-config "$binDir"
	fi

	prepareInstalledDevelLib libxapian
	fixPkgconfig

	# move $libDir/cmake/xapian/* to $dataDir/cmake/Modules/xapian/*
	mkdir -p "$dataDir"/cmake
	mv "$libDir"/cmake "$dataDir"/cmake/Modules

	packageEntries devel \
		"$binDir"/xapian-config \
		"$manDir"/man1/xapian-config.1 \
		"$developDir" \
		"$dataDir"

	if [ -n "$secondaryArchSuffix" -a "$commandBinDir" != "$binDir" ]; then
		rmdir "$binDir"
	fi
}

TEST()
{
	LIBRARY_PATH="$sourceDir/.libs${LIBRARY_PATH:+:$LIBRARY_PATH}" \
	make check
}
