SUMMARY="Numerical linear algebra package"
DESCRIPTION="A library of Fortran 90 with subroutines for solving \
the most commonly occurring problems in numerical linear algebra."
HOMEPAGE="http://www.netlib.org/lapack/"
COPYRIGHT="1992-2021 The LAPACK Project"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/Reference-LAPACK/lapack/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="328c1bea493a32cac5257d84157dc686cc3ab0b004e2bea22044e0a59f6f8a19"
SOURCE_DIR="lapack-$portVersion"

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

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

PROVIDES="
	lapack$secondaryArchSuffix = $portVersion
	lib:liblapack$secondaryArchSuffix = $libVersionCompat
	lib:liblapacke$secondaryArchSuffix = $libVersionCompat
	lib:libcblas$secondaryArchSuffix = $libVersionCompat
	lib:libtmglib$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:libopenblas$secondaryArchSuffix
	lib:libquadmath$secondaryArchSuffix
	"

PROVIDES_devel="
	lapack${secondaryArchSuffix}_devel = $portVersion
	devel:liblapack$secondaryArchSuffix = $libVersionCompat
	devel:liblapacke$secondaryArchSuffix = $libVersionCompat
	devel:libcblas$secondaryArchSuffix = $libVersionCompat
	devel:libtmglib$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	lapack$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libopenblas$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:gfortran$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3.7
	cmd:sed
	cmd:strip$secondaryArchSuffix
	"

defineDebugInfoPackage lapack$secondaryArchSuffix \
	"$libDir"/liblapack.so.$libVersion \
	"$libDir"/liblapacke.so.$libVersion \
	"$libDir"/libtmglib.so.$libVersion \
	"$libDir"/libcblas.so.$libVersion

BUILD()
{
	rm -rf build
	cmake -B build -S . \
		$cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS=1 \
		-DCMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES=1 \
		-DUSE_OPTIMIZED_BLAS=ON \
		-DBUILD_SHARED_LIBS=ON \
		-DLAPACKE_WITH_TMG=ON \
		-DCBLAS=ON \
		-DBUILD_TESTING=ON \
		-DBUILD_DEPRECATED=ON

	cmake --build build
}

INSTALL()
{
	cmake --install build

	prepareInstalledDevelLibs liblapack \
		liblapacke \
		libcblas \
		libtmglib

	sed  -i "1i prefix=$prefix" \
		$libDir/pkgconfig/lapack.pc \
		$libDir/pkgconfig/lapacke.pc

	fixPkgconfig

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	cd build
	make test
}
