SUMMARY="A library for processing spreadsheet documents"
DESCRIPTION="Orcus is a library that provides a collection of standalone file \
processing filters. It is currently focused on providing filters for \
spreadsheet documents."
HOMEPAGE="https://gitlab.com/orcus/orcus"
COPYRIGHT="Kohei Yoshida et al."
LICENSE="MPL v2.0"
REVISION="1"
SOURCE_URI="https://gitlab.com/orcus/orcus/-/archive/$portVersion/orcus-$portVersion.tar.bz2"
CHECKSUM_SHA256="cc4fd01811e46b68ddeee5cce7fe6b2a9decb760b9f8ff534b418f0a2d1cea07"
SOURCE_DIR="orcus-$portVersion"

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

boostMinimumVersion=1.69.0

soVersion="${portVersion%.*}"
ixionSoVersion=$soVersion

PROVIDES="
	orcus$secondaryArchSuffix = $portVersion
	cmd:orcus_css_dump$secondaryArchSuffix = $portVersion
	cmd:orcus_csv$secondaryArchSuffix = $portVersion
	cmd:orcus_detect$secondaryArchSuffix = $portVersion
	cmd:orcus_gnumeric$secondaryArchSuffix = $portVersion
	cmd:orcus_json$secondaryArchSuffix = $portVersion
	cmd:orcus_mso_encryption$secondaryArchSuffix = $portVersion
	cmd:orcus_ods$secondaryArchSuffix = $portVersion
	cmd:orcus_styles_ods$secondaryArchSuffix = $portVersion
	cmd:orcus_xls_xml$secondaryArchSuffix = $portVersion
	cmd:orcus_xlsx$secondaryArchSuffix = $portVersion
	cmd:orcus_xml$secondaryArchSuffix = $portVersion
	cmd:orcus_xml_dump$secondaryArchSuffix = $portVersion
	cmd:orcus_yaml$secondaryArchSuffix = $portVersion
	cmd:orcus_zip_dump$secondaryArchSuffix = $portVersion
	lib:liborcus_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	lib:liborcus_mso_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	lib:liborcus_parser_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	lib:liborcus_spreadsheet_model_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_date_time$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libboost_filesystem$secondaryArchSuffix
	lib:libboost_iostreams$secondaryArchSuffix
	lib:libboost_program_options$secondaryArchSuffix
	lib:libixion_$ixionSoVersion$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	orcus${secondaryArchSuffix}_devel = $portVersion
	devel:liborcus_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	devel:liborcus_mso_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	devel:liborcus_parser_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	devel:liborcus_spreadsheet_model_$soVersion$secondaryArchSuffix = 0.0.0 compat >= 0
	"
REQUIRES_devel="
	orcus$secondaryArchSuffix == $portVersion base
	devel:libixion_$ixionSoVersion$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_date_time$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_system$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_filesystem$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_iostreams$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_program_options$secondaryArchSuffix >= $boostMinimumVersion
	devel:libixion_$ixionSoVersion$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:mdds >= 1.5
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage orcus$secondaryArchSuffix \
	$binDir/orcus-css-dump \
	$binDir/orcus-csv \
	$binDir/orcus-detect \
	$binDir/orcus-gnumeric \
	$binDir/orcus-json \
	$binDir/orcus-mso-encryption \
	$binDir/orcus-ods \
	$binDir/orcus-styles-ods \
	$binDir/orcus-xls-xml \
	$binDir/orcus-xlsx \
	$binDir/orcus-xml \
	$binDir/orcus-yaml \
	$binDir/orcus-zip-dump \
	$libDir/liborcus-$soVersion.so.0.0.0 \
	$libDir/liborcus-mso-$soVersion.so.0.0.0 \
	$libDir/liborcus-parser-$soVersion.so.0.0.0 \
	$libDir/liborcus-spreadsheet-model-$soVersion.so.0.0.0

PATCH()
{
	sed -i 's/-pthread//g' configure.ac src/parser/Makefile.am
	sed -i 's#$with_boost/include#$with_boost/headers#g' m4/boost.m4
}

BUILD()
{
	autoreconf -fi
	BOOST_ROOT=$portPackageLinksDir/devel~libboost_program_options/develop
	runConfigure ./configure --disable-python
	make $jobArgs
}

INSTALL()
{
	make install

	for la in "" -mso -parser -spreadsheet-model; do
		library=liborcus$la-$soVersion
		rm $libDir/$library.la
		prepareInstalledDevelLib $library
	done
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
