SUMMARY="A suite of sparse matrix software"
DESCRIPTION="SuiteSparse is a suite of sparse matrix algorithms, including:

* GraphBLAS: graph algorithms in the language of linear algebra
* Mongoose: graph partitioning
* ssget: MATLAB and Java interface to the SuiteSparse Matrix Collection
* UMFPACK: multifrontal LU factorization.  Appears as LU and x=A\b in MATLAB.
* CHOLMOD: supernodal Cholesky.  Appears as CHOL and x=A\b in MATLAB.  Now \
with CUDA acceleration, in collaboration with NVIDIA.
* SPQR: multifrontal QR.  Appears as QR and x=A\b in MATLAB, with CUDA \
acceleration.
* KLU and BTF:  sparse LU factorization, well-suited for circuit simulation. 
* Ordering methods (AMD, CAMD, COLAMD, and CCOLAMD).  AMD and COLAMD appear \
in MATLAB.
* CSparse and CXSparse: a concise sparse Cholesky factorization package for \
my SIAM book.
* spqr_rank: a MATLAB package for reliable sparse rank detection, null set \
bases, pseudoinverse solutions, and basic solutions.
* Factorize: an object-oriented solver for MATLAB (a reusable backslash).
* SSMULT and SFMULT: sparse matrix multiplication.  Appears as the built-in \
C=A*B operator in MATLAB.
* ... and many other packages."
HOMEPAGE="http://www.suitesparse.com"
COPYRIGHT="1996-2019 Timothy A. Davis et al."
LICENSE="SUITESPARSE"
REVISION="1"
SOURCE_URI="https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="5ba5add1663d51a1b6fb128b50fe869b497f3096765ff7f8212f0ede044b9557"
SOURCE_DIR="SuiteSparse-$portVersion"
PATCHES="suitesparse-$portVersion.patchset"

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

libAMDVersion="2.4.6"
libAMDVersionCompat="$libAMDVersion compat >= ${libAMDVersion%%.*}"
libBTFVersion="1.2.6"
libBTFVersionCompat="$libBTFVersion compat >= ${libBTFVersion%%.*}"
libCAMDVersion="2.4.6"
libCAMDVersionCompat="$libCAMDVersion compat >= ${libCAMDVersion%%.*}"
libCCOLAMDVersion="2.9.6"
libCCOLAMDVersionCompat="$libCCOLAMDVersion compat >= ${libCCOLAMDVersion%%.*}"
libCHOLMODVersion="3.0.14"
libCHOLMODVersionCompat="$libCHOLMODVersion compat >= ${libCHOLMODVersion%%.*}"
libCOLAMDVersion="2.9.6"
libCOLAMDVersionCompat="$libCOLAMDVersion compat >= ${libCOLAMDVersion%%.*}"
libCXSPARSEVersion="3.2.0"
libCXSPARSEVersionCompat="$libCXSPARSEVersion compat >= ${libCXSPARSEVersion%%.*}"
libGRAPHBLASVersion="3.2.0"
libGRAPHBLASVersionCompat="$libGRAPHBLASVersion compat >= ${libGRAPHBLASVersion%%.*}"
libKLUVersion="1.3.8"
libKLUVersionCompat="$libKLUVersion compat >= ${libKLUVersion%%.*}"
libLDLVersion="2.2.6"
libLDLVersionCompat="$libLDLVersion compat >= ${libLDLVersion%%.*}"
libMETISVersion="$portVersion"
libMETISVersionCompat="$libMETISVersion compat >= ${libMETISVersion%%.*}"
libMONGOOSEVersion="2.0.4"
libMONGOOSEVersionCompat="$libMONGOOSEVersion compat >= ${libMONGOOSEVersion%%.*}"
libRBIOVersion="2.2.6"
libRBIOVersionCompat="$libRBIOVersion compat >= ${libRBIOVersion%%.*}"
libSPQRVersion="2.0.9"
libSPQRVersionCompat="$libSPQRVersion compat >= ${libSPQRVersion%%.*}"
libSUITESPARSE_CONFIGVersion="5.7.1"
libSUITESPARSE_CONFIGVersionCompat="$libSUITESPARSE_CONFIGVersion compat >= ${libSUITESPARSE_CONFIGVersion%%.*}"
libUMFPACKVersion="5.7.9"
libUMFPACKVersionCompat="$libUMFPACKVersion compat >= ${libUMFPACKVersion%%.*}"

PROVIDES="
	suitesparse$secondaryArchSuffix = $portVersion
	cmd:mongoose
	lib:libamd$secondaryArchSuffix = $libAMDVersionCompat
	lib:libbtf$secondaryArchSuffix = $libBTFVersionCompat
	lib:libcamd$secondaryArchSuffix = $libCAMDVersionCompat
	lib:libccolamd$secondaryArchSuffix = $libCCOLAMDVersionCompat
	lib:libcholmod$secondaryArchSuffix = $libCHOLMODVersionCompat
	lib:libcolamd$secondaryArchSuffix = $libCOLAMDVersionCompat
	lib:libcxsparse$secondaryArchSuffix = $libCXSPARSEVersionCompat
	lib:libgraphblas$secondaryArchSuffix = $libGRAPHBLASVersionCompat
	lib:libklu$secondaryArchSuffix = $libKLUVersionCompat
	lib:libldl$secondaryArchSuffix = $libLDLVersionCompat
	lib:libmetis$secondaryArchSuffix = $libMETISVersionCompat
	lib:libmongoose$secondaryArchSuffix = $libMONGOOSEVersionCompat
	lib:librbio$secondaryArchSuffix = $libRBIOVersionCompat
	lib:libspqr$secondaryArchSuffix = $libSPQRVersionCompat
	lib:libsuitesparseconfig$secondaryArchSuffix = $libSUITESPARSE_CONFIGVersionCompat
	lib:libumfpack$secondaryArchSuffix = $libUMFPACKVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:liblapack$secondaryArchSuffix
	lib:libopenblas$secondaryArchSuffix
	lib:libtbb$secondaryArchSuffix
	"
REPLACES="
	suitesparse${secondaryArchSuffix}_amd
	suitesparse${secondaryArchSuffix}_btf
	suitesparse${secondaryArchSuffix}_camd
	suitesparse${secondaryArchSuffix}_ccolamd
	suitesparse${secondaryArchSuffix}_cholmod
	suitesparse${secondaryArchSuffix}_colamd
	suitesparse${secondaryArchSuffix}_cxsparse
	suitesparse${secondaryArchSuffix}_graphblas
	suitesparse${secondaryArchSuffix}_klu
	suitesparse${secondaryArchSuffix}_ldl
	suitesparse${secondaryArchSuffix}_metis
	suitesparse${secondaryArchSuffix}_mongoose
	suitesparse${secondaryArchSuffix}_rbio
	suitesparse${secondaryArchSuffix}_spqr
	suitesparse${secondaryArchSuffix}_umfpack
	"

PROVIDES_devel="
	suitesparse${secondaryArchSuffix}_devel = $portVersion
	devel:libamd$secondaryArchSuffix = $libAMDVersion
	devel:libbtf$secondaryArchSuffix = $libBTFVersion
	devel:libcamd$secondaryArchSuffix = $libCAMDVersion
	devel:libccolamd$secondaryArchSuffix = $libCCOLAMDVersion
	devel:libcholmod$secondaryArchSuffix = $libCHOLMODVersion
	devel:libcolamd$secondaryArchSuffix = $libCOLAMDVersion
	devel:libcxsparse$secondaryArchSuffix = $libCXSPARSEVersion
	devel:libgraphblas$secondaryArchSuffix = $libGRAPHBLASVersion
	devel:libklu$secondaryArchSuffix = $libKLUVersion
	devel:libldl$secondaryArchSuffix = $libLDLVersion
	devel:libmetis$secondaryArchSuffix = $libMETISVersion
	devel:libmongoose$secondaryArchSuffix = $libMONGOOSEVersion
	devel:librbio$secondaryArchSuffix = $libRBIOVersion
	devel:libspqr$secondaryArchSuffix = $libSPQRVersion
	devel:libsuitesparseconfig$secondaryArchSuffix = $libSUITESPARSE_CONFIGVersion
	devel:libumfpack$secondaryArchSuffix = $libUMFPACKVersion
	devel:suitesparse$secondaryArchSuffix = $libSUITESPARSE_CONFIGVersion
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	suitesparse$secondaryArchSuffix == $portVersion base
	devel:libexecinfo$secondaryArchSuffix
	devel:libgfortran$secondaryArchSuffix
	devel:liblapack$secondaryArchSuffix
	devel:libopenblas$secondaryArchSuffix
	devel:libtbb$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexecinfo$secondaryArchSuffix
	devel:libgfortran$secondaryArchSuffix
	devel:liblapack$secondaryArchSuffix
	devel:libopenblas$secondaryArchSuffix
	devel:libtbb$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:diff
	cmd:gawk
	cmd:gcc$secondaryArchSuffix
	cmd:gfortran$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:m4
	cmd:make
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2
	"

defineDebugInfoPackage suitesparse$secondaryArchSuffix \
	"$libDir"/libsuitesparseconfig.so.$libSUITESPARSE_CONFIGVersion \
	"$libDir"/libamd.so.$libAMDVersion \
	"$libDir"/libbtf.so.$libBTFVersion \
	"$libDir"/libcamd.so.$libCAMDVersion \
	"$libDir"/libccolamd.so.$libCCOLAMDVersion \
	"$libDir"/libcholmod.so.$libCHOLMODVersion \
	"$libDir"/libcolamd.so.$libCOLAMDVersion \
	"$libDir"/libcxsparse.so.$libCXSPARSEVersion \
	"$libDir"/libgraphblas.so.$libGRAPHBLASVersion \
	"$libDir"/libklu.so.$libKLUVersion \
	"$libDir"/libldl.so.$libLDLVersion \
	"$libDir"/libmetis.so \
	"$libDir"/libmongoose.so.$libMONGOOSEVersion \
	"$libDir"/librbio.so.$libRBIOVersion \
	"$libDir"/libspqr.so.$libSPQRVersion \
	"$libDir"/libumfpack.so.$libUMFPACKVersion

BUILD()
{
	CMAKE_OPTIONS="$cmakeDirArgs" LIBRARY_PATH="$sourceDir/lib:$LIBRARY_PATH" \
		LDFLAGS="-lnetwork -lbsd -lexecinfo" CF="-D_BSD_SOURCE" \
		TBB="-ltbb" SPQR_CONFIG="-DHAVE_TBB" make library $jobArgs
#		make TBB="-ltbb" $jobArgs # for building and running tests
}

INSTALL()
{
	LIBRARY_PATH="$sourceDir/lib:$LIBRARY_PATH" \
		LDFLAGS="-lnetwork -lbsd -lexecinfo" CF="-D_BSD_SOURCE" \
		TBB="-ltbb" SPQR_CONFIG="-DHAVE_TBB" INSTALL="$prefix" \
		INSTALL_LIB="$libDir" INSTALL_INCLUDE="$includeDir" \
		INSTALL_DOC="$docDir" make install

	prepareInstalledDevelLibs libamd \
		libbtf \
		libcamd \
		libccolamd \
		libcholmod \
		libcolamd \
		libcxsparse \
		libgraphblas \
		libklu \
		libldl \
		libmetis \
		libmongoose \
		librbio \
		libspqr \
		libsuitesparseconfig \
		libumfpack

	fixPkgconfig

	# DEVEL
	packageEntries devel \
		$developDir
}
