SUMMARY="An optimized BLAS library"
DESCRIPTION="OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD \
version."
HOMEPAGE="http://www.openblas.net/"
COPYRIGHT="2011-2021 The OpenBLAS Project"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="http://github.com/xianyi/OpenBLAS/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="1632c1e8cca62d8bed064b37747e331a1796fc46f688626337362bf0d16aeadb"
SOURCE_FILENAME="OpenBLAS-$portVersion.tar.gz"
SOURCE_DIR="OpenBLAS-$portVersion"

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

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

PROVIDES="
	openblas$secondaryArchSuffix = $portVersionCompat
	lib:libopenblas$secondaryArchSuffix = $libVersionCompat
	lib:libopenblasp_r$portVersion$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	"

PROVIDES_devel="
	openblas${secondaryArchSuffix}_devel = $portVersionCompat
	devel:libopenblas$secondaryArchSuffix = $libVersionCompat
	devel:libopenblasp_r$portVersion$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	openblas$secondaryArchSuffix == $portVersion base
	"

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

defineDebugInfoPackage openblas$secondaryArchSuffix \
	"$libDir"/libopenblas.so.0 \
	"$libDir"/libopenblasp-r$portVersion.so

# DYNAMIC_ARCH is x86 only
# PPC & others should specify TARGET=
case "$effectiveTargetArchitecture" in
	x86) target=NORTHWOOD;;
	x86_64) target=PRESCOTT;;
	*) target=;;
esac

BUILD_CONF="NO_STATIC=1 \
		NO_LAPACK=1 \
		NO_LAPACKE=1 \
		NO_AFFINITY=1 \
		NO_WARMUP=1 \
		NO_AVX512=1 \
		NUM_THREADS=64 \
		DYNAMIC_ARCH=1 \
		USE_OPENMP=1"

BUILD()
{
	make MAKE_NB_JOBS=${jobArgs#-j} \
		$BUILD_CONF \
		${target:+TARGET=$target} \
		libs shared
}

INSTALL()
{
	make install PREFIX=$prefix \
		OPENBLAS_LIBRARY_DIR=$libDir \
		OPENBLAS_INCLUDE_DIR=$includeDir \
		$BUILD_CONF \
		${target:+TARGET=$target}

	rm -f $libDir/*.a

	prepareInstalledDevelLibs libopenblas libopenblasp-r$portVersion

	fixPkgconfig

	cp -P $developLibDir/libopenblas.so.0 $libDir

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	make tests \
		$BUILD_CONF \
		${target:+TARGET=$target}
}
