# $Id: Portfile 57375 2009-09-10 08:16:41Z ryandesign@macports.org $

PortSystem 1.0

name		SuiteSparse
version     3.4.0
categories	math science
maintainers     stechert
platforms	darwin
description	Sparse matrix routines
long_description \
		SuiteSparse is a single archive that contains all packages \
		authored by Tim Davis.

homepage	http://www.cise.ufl.edu/research/sparse/SuiteSparse/
master_sites	http://www.cise.ufl.edu/research/sparse/SuiteSparse/
distname	SuiteSparse-$version
worksrcdir	${name}

depends_build	port:metis

use_parallel_build	no

# cflags recommended for Macs in ${worksrcpath}/UFconfig/UFconfig.mk
configure.cflags -O3 -fno-common -no-cpp-precomp -fexceptions

use_configure	no
build.target

checksums           md5     e59dcabc9173b1ba1b3659ae147006b8 \
                    sha1    6de027d48a573659b40ddf57c10e32b39ab034c6 \
                    rmd160  77ff7376691d2bc8581de6ae89f246cb289b2708

post-patch {
	# Metis is included with SuiteSparse, but we want to use
	#   the MacPorts version
	
	# -I$(METIS_PATH)/Lib -> -I$(METIS_PATH)/include
	reinplace \
		"s|-I\$(METIS_PATH)/Lib|-I\$(METIS_PATH)/include|g" \
		${worksrcpath}/CHOLMOD/Lib/Makefile
	
	# #include "metis.h" -> #include <metis/metis.h>
	reinplace \
		"s|#include \"metis.h\"|#include <metis/metis.h>|g" \
		${worksrcpath}/CHOLMOD/Partition/cholmod_metis.c
	
	# klu_version.h defines Real and Imag which conflicts with math.h on ppc
	reinplace -E \
		"s|(\[^a-zA-Z\])Real(\[^a-zA-Z\])|\\1RealPart\\2|g" \
		${worksrcpath}/KLU/Include/klu_version.h
	reinplace -E \
		"s|(\[^a-zA-Z\])Imag(\[^a-zA-Z\])|\\1ImagPart\\2|g" \
		${worksrcpath}/KLU/Include/klu_version.h
}

post-configure	{
	# SuiteSparse does not use configure, so the variables must be
	#    set manually.
	# This is done in post-configure so that ${configure.cc} is
	#    set to its default value.
	reinplace -E \
		"s|^CC = .*$|CC = ${configure.cc}|g" \
		${worksrcpath}/UFconfig/UFconfig.mk \
		${worksrcpath}/CSparse/Demo/Makefile \
		${worksrcpath}/CSparse/Lib/Makefile
	reinplace -E \
		"s|^CPLUSPLUS = .*$|CPLUSPLUS = ${configure.cxx}|g" \
		${worksrcpath}/UFconfig/UFconfig.mk
	reinplace -E \
		"s|^CFLAGS = .*$|CFLAGS = ${configure.cflags}|g" \
		${worksrcpath}/UFconfig/UFconfig.mk
	reinplace -E \
		"s|^CFLAGS = -O|CFLAGS = -O3|g" \
		${worksrcpath}/CSparse/Demo/Makefile \
		${worksrcpath}/CSparse/Lib/Makefile
	reinplace -E \
		"s|^BLAS = .*$|BLAS = -framework Accelerate|g" \
		${worksrcpath}/UFconfig/UFconfig.mk
	reinplace -E \
		"s|^LAPACK = .*$|LAPACK = -framework Accelerate|g" \
		${worksrcpath}/UFconfig/UFconfig.mk
	reinplace -E \
		"s|^METIS_PATH = .*$|METIS_PATH = ${prefix}|g" \
		${worksrcpath}/UFconfig/UFconfig.mk
	reinplace -E \
		"s|^METIS = .*$|METIS = ${prefix}/lib/libmetis.a|g" \
		${worksrcpath}/UFconfig/UFconfig.mk
}

destroot	{
	# SuiteSparse does not support "make install"
	
	eval xinstall -m 644 \
		[glob ${worksrcpath}/*/Lib/*.a] \
		${destroot}${prefix}/lib
	
	xinstall -m 755 -d ${destroot}${prefix}/include/ufsparse
	eval xinstall -m 644 \
		[glob ${worksrcpath}/*/Include/*.h] \
		${worksrcpath}/UFconfig/UFconfig.h \
		${destroot}${prefix}/include/ufsparse
	
	xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
	eval xinstall -m 644 \
		[glob ${worksrcpath}/*/Doc/*.pdf] \
		${destroot}${prefix}/share/doc/${name}
}

livecheck.type	regex
livecheck.regex	${name}-(\\d+(\\.\\d+)*)${extract.suffix}
