SUMMARY="A modern multi-purpose calculator library"
DESCRIPTION="libqalculate is math libary for expression evaluation with \
units, variables and functions support and CAS functionality."
HOMEPAGE="https://qalculate.github.io/"
COPYRIGHT="2003-2007, 2008, 2016-2021  Hanna Knutsson"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/Qalculate/libqalculate/releases/download/v$portVersion/libqalculate-$portVersion.tar.gz"
CHECKSUM_SHA256="2a2b6f8de4b43acdff98efdda338436db1a3f7ecd994e1bc2a422a65fba03479"

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

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

PROVIDES="
	libqalculate$secondaryArchSuffix = $portVersion
	lib:libqalculate$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:gnuplot
	lib:libcurl$secondaryArchSuffix
	lib:libgettextpo$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libhistory$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libicudata$secondaryArchSuffix
	lib:libicui18n$secondaryArchSuffix >= 66
	lib:libicuuc$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libmpfr$secondaryArchSuffix >= 6
	lib:libreadline$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	"

PROVIDES_devel="
	libqalculate${secondaryArchSuffix}_devel = $portVersion
	devel:libqalculate$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libqalculate$secondaryArchSuffix == $portVersion base
	devel:libgmp$secondaryArchSuffix
	devel:libmpfr$secondaryArchSuffix >= 6
	"

SUMMARY_tools="$SUMMARY (Qalculate! binary)"
DESCRIPTION_tools="
Qalculate! is a multi-purpose cross-platform desktop calculator. It is \
simple to use but provides power and versatility normally reserved for \
complicated math packages, as well as useful tools for everyday needs \
(such as currency conversion and percent calculation). Features include a \
large library of customizable functions, unit calculations and conversion, \
symbolic calculations (including integrals and equations), arbitrary \
precision, uncertainty propagation, interval arithmetic, plotting, and a \
user-friendly interface."
PROVIDES_tools="
	libqalculate${secondaryArchSuffix}_tools = $portVersion
	cmd:qalc$secondaryArchSuffix = $portVersion
	"
REQUIRES_tools="
	libqalculate$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	$REQUIRES
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libgettextlib$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libhistory$secondaryArchSuffix >= 8
	devel:libicudata$secondaryArchSuffix
	devel:libicui18n$secondaryArchSuffix >= 66
	devel:libiconv$secondaryArchSuffix
	devel:libicuuc$secondaryArchSuffix >= 66
	devel:libintl$secondaryArchSuffix
	devel:libmpfr$secondaryArchSuffix >= 6
	devel:libreadline$secondaryArchSuffix >= 8
	devel:libxml2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:intltoolize
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libqalculate$secondaryArchSuffix \
	$libDir/libqalculate.so.$libVersion \
	"$(getPackagePrefix tools)/$relativeBinDir"/qalc

BUILD()
{
	runConfigure ./configure \
		--disable-static
	make $jobArgs
}

INSTALL()
{
	make install
	rm $libDir/libqalculate.la

	prepareInstalledDevelLib libqalculate
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
	packageEntries tools \
		$binDir \
		$manDir
}

TEST()
{
	make check
}
