# Template file for 'SuiteSparse'
pkgname=SuiteSparse
version=7.0.1
revision=1
hostmakedepends="cmake gcc-fortran"
makedepends="libgomp-devel mpfr-devel
 $(vopt_if openblas 'openblas-devel' 'lapack-devel')"
short_desc="Suite of sparse matrix software"
maintainer="Gonzalo Tornaría <tornaria@cmat.edu.uy>"
license="custom:multiple"
homepage="https://people.engr.tamu.edu/davis/suitesparse.html"
changelog="https://raw.githubusercontent.com/DrTimothyAldenDavis/SuiteSparse/master/ChangeLog"
distfiles="https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v${version}.tar.gz"
checksum=dc2f8d5c2657c120b30cce942f634ec08fc3a4b0b10e19d3eef7790b2bec8d1e

build_options="openblas"

case "$XBPS_TARGET_MACHINE" in
	x86_64*|i686*|aarch64*|armv[67]*|ppc64*)
		# Prefer accelerated routines where available
		build_options_default="openblas"
		;;
	*) ;;
esac

if [ "$XBPS_TARGET_NO_ATOMIC8" ]; then
	makedepends+=" libatomic-devel"
fi

do_build() {
	make library \
		JOBS=$XBPS_MAKEJOBS \
		CMAKE_OPTIONS="-DBLA_VENDOR=$(vopt_if openblas 'OpenBLAS' 'Generic') \
		               -DCMAKE_INSTALL_PREFIX=$DESTDIR/usr"
}

do_check() {
	make demos \
		JOBS=$XBPS_MAKEJOBS
}

do_install() {
	make install
	vlicense LICENSE.txt
}

SuiteSparse-devel_package() {
	depends="${makedepends} ${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development files"
	# conflict for /usr/lib/libmongoose.{a,so}
	conflicts="mongoose-devel"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/cmake
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
	}
}
