SUMMARY="Numerical analysis and data processing library"
DESCRIPTION="ALGLIB is a cross-platform numerical analysis and data \
processing library. It supports several programming languages (C\+\+, C\#, \
Delphi) and several operating systems (Windows and POSIX, including Linux).

ALGLIB features include:
* Data analysis (classification/regression, statistics)
* Optimization and nonlinear solvers
* Interpolation and linear/nonlinear least-squares fitting
* Linear algebra (direct algorithms, EVD/SVD), direct and iterative linear \
solvers
* Fast Fourier Transform and many other algorithms"
HOMEPAGE="https://www.alglib.net/"
COPYRIGHT="1999-2019 Sergey Bochkanov"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://www.alglib.net/translator/re/alglib-$portVersion.cpp.gpl.tgz"
CHECKSUM_SHA256="41fa15d25f7332f357ebecdec3e5370619361365b469b6c92401fec059b69867"
SOURCE_DIR="cpp"
ADDITIONAL_FILES="CMakeLists.txt.in"

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

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

PROVIDES="
	alglib$secondaryArchSuffix = $portVersion
	lib:libalglib$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	"

PROVIDES_devel="
	alglib${secondaryArchSuffix}_devel = $portVersion
	devel:libalglib$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	alglib$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage alglib$secondaryArchSuffix \
	"$libDir"/libalglib.so.$portVersion \

BUILD()
{
	# ALGLIB doesn't provide any build system
	local VERSION="$portVersion"
	local SOVERSION="`echo ${portVersion%.*}`"
	sed \
		-e "s|@VERSION@|$VERSION|" \
		-e "s|@SOVERSION@|$SOVERSION|" \
		$portDir/additional-files/CMakeLists.txt.in > CMakeLists.txt

	mkdir -p build && cd build

	cmake .. \
		-DBUILD_TEST=ON \
		$cmakeDirArgs

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	install -m 0755 -d "$developDocDir"
	install -m 0644 -t "$developDocDir" ../manual.cpp.html

	prepareInstalledDevelLibs libalglib

	packageEntries devel \
		$developDir
}

TEST()
{
	cd build
	make test
}
