# SliTaz package receipt.

PACKAGE="umfpack"
SOURCE="SuiteSparse"
VERSION="4.4.4"
CATEGORY="development"
SHORT_DESC="Multifrontal LU factorization."
MAINTAINER="pascal.bellard@slitaz.org"
LICENSE="GPL2"
TARBALL="$SOURCE-$VERSION.tar.gz"
WEB_SITE="https://faculty.cse.tamu.edu/davis/suitesparse.html"
WGET_URL="https://faculty.cse.tamu.edu/davis/$SOURCE/$TARBALL"

DEPENDS="blas lapack"
BUILD_DEPENDS="blas lapack libgfortran"

# What is the latest version available today?
current_version()
{
	wget -O - https://github.com/DrTimothyAldenDavis/SuiteSparse/releases 2>/dev/null | \
	sed '/archive.*tar/!d;s|.*/[A-Za-z_-]*\(.*\).tar.*|\1|;q'
}

# Rules to configure and make the package.
compile_rules()
{
	cat > dynlink.sh <<EOT
lib=\$1
shift
gcc -shared \$@ -lm -Wl,-soname -Wl,\$(basename \$lib) -o \$lib 
EOT
	for i in */Doc/ChangeLog ; do
		VERSION=$(sed 's/.* version //;q' $i)
		sed -i 's/\(.*cd Lib.*MAKE.\)\(.*\)/\1\2\n\1 -f Makefile.d\2/' \
			${i%%/*}/Makefile
		i=${i%%/*}/Lib
		sed -e "/RANLIB/d;s/\.a/.so.$VERSION/" \
		    -e 's/\.o/.oo/g;s/ -c / -fPIC&/' \
		    -e 's|CC.*/\([^/]*\)c$|& -o \1oo|' -e 's|\$<$|$< -o $@|' \
		    -e "s|\$(AR[A-Z]*)|sh $src/dynlink.sh|" \
			< $i/Makefile > $i/Makefile.d
	done
	mkdir -p $DESTDIR/usr/lib $DESTDIR/usr/include
	sed -i "s/lopenblas/lblas/;s|/usr/local|$DESTDIR/usr|" \
		SuiteSparse_config/*.mk
	sed -i 's|metis-4.0|& 2>/dev/null|' Makefile
	make -j 1 && make install
	for i in */Lib/*.so.* ; do
		cp $i $DESTDIR/usr/lib
		l=$(basename $i)
		ln -s $l $DESTDIR/usr/lib/${l%.*.*}
		ln -s $l $DESTDIR/usr/lib/${l%so*}so
	done
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/lib
	cp -a $install/usr/lib/*.so* $fs/usr/lib
}