--- Portfile.orig	2007-04-17 05:08:34.000000000 -0400
+++ Portfile	2008-10-22 11:54:17.000000000 -0400
@@ -1,10 +1,11 @@
 # $Id: Portfile 24134 2007-04-17 09:08:34Z ryandesign@macports.org $
 
 PortSystem 1.0
+
 name		SuiteSparse
-version		2.4.0
+version		3.2.0
 categories	math science
-maintainers     stechert@macports.org
+maintainers     stechert
 platforms	darwin
 description	Sparse matrix routines
 long_description \
@@ -18,113 +19,82 @@
 
 depends_build	port:metis
 
-checksums	md5 30233f0b42e9ea12e47a287f0f50fe47
+checksums	md5 d1be7abb6227568fec94179cb1300303 \
+		sha1 ba39ba94a4069f2667ae5a4208866f7119a36ae8 \
+		rmd160 88db01d4b5f7532553809051fab305ebbc28d624
 
-patchfiles	patch-config \
-		patch-macports-metis \
-		patch-cholmod-headers
+# cflags recommended for Macs in ${worksrcpath}/UFconfig/UFconfig.mk
+configure.cflags -O3 -fno-common -no-cpp-precomp -fexceptions
 
 use_configure	no
+build.target
 
-pre-configure	{
-		reinplace "s,METIS_PATH = ../../metis-4.0,METIS_PATH = ${prefix}/include," ${worksrcpath}/UFconfig/UFconfig.mk
-		reinplace "s,METIS = ../../metis-4.0/libmetis.a,METIS = ${prefix}/lib/libmetis.a," ${worksrcpath}/UFconfig/UFconfig.mk
+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
 }
 
-build.target	default
+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
+	reinplace -E \
+		"s|^CFLAGS = .*$|CFLAGS = ${configure.cflags}|g" \
+		${worksrcpath}/UFconfig/UFconfig.mk
+	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	{
-	xinstall -m 644 ${worksrcpath}/AMD/Lib/libamd.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/BTF/Lib/libbtf.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/CAMD/Lib/libcamd.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/CCOLAMD/libccolamd.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/CHOLMOD/Lib/libcholmod.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/COLAMD/libcolamd.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/CXSparse/Source/libcxsparse.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/KLU/Lib/libklu.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/KLU/User/libklu_cholmod.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/LDL/libldl.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/UFconfig/xerbla/libcerbla.a ${destroot}${prefix}/lib
-	xinstall -m 644 ${worksrcpath}/UMFPACK/Lib/libumfpack.a ${destroot}${prefix}/lib
-
+	# 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
-
-	xinstall -m 644 ${worksrcpath}/AMD/Include/amd.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/BTF/Include/btf.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/CAMD/Include/camd.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/CCOLAMD/ccolamd.h ${destroot}${prefix}/include/ufsparse
-
-	xinstall -m 644 -W ${worksrcpath}/CHOLMOD/Include \
-		cholmod.h \
-		cholmod_blas.h \
-		cholmod_check.h \
-		cholmod_cholesky.h \
-		cholmod_complexity.h \
-		cholmod_config.h \
-		cholmod_core.h \
-		cholmod_internal.h \
-		cholmod_io64.h \
-		cholmod_matrixops.h \
-		cholmod_modify.h \
-		cholmod_partition.h \
-		cholmod_supernodal.h \
-		cholmod_template.h \
- 		${destroot}${prefix}/include/ufsparse
-
-	xinstall -m 644 ${worksrcpath}/COLAMD/colamd.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/CXSparse/Source/cs.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/KLU/Include/klu.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/LDL/ldl.h ${destroot}${prefix}/include/ufsparse
-	xinstall -m 644 ${worksrcpath}/UFconfig/UFconfig.h ${destroot}${prefix}/include/ufsparse
-
-        xinstall -m 644 -W ${worksrcpath}/UMFPACK/Include \
-		umfpack.h \
-		umfpack_col_to_triplet.h \
-		umfpack_defaults.h \
-		umfpack_free_numeric.h \
-		umfpack_free_symbolic.h \
-		umfpack_get_determinant.h \
-		umfpack_get_lunz.h \
-		umfpack_get_numeric.h \
-		umfpack_get_symbolic.h \
-		umfpack_global.h \
-		umfpack_load_numeric.h \
-		umfpack_load_symbolic.h \
-		umfpack_numeric.h \
-		umfpack_qsymbolic.h \
-		umfpack_report_control.h \
-		umfpack_report_info.h \
-		umfpack_report_matrix.h \
-		umfpack_report_numeric.h \
-		umfpack_report_perm.h \
-		umfpack_report_status.h \
-		umfpack_report_symbolic.h \
-		umfpack_report_triplet.h \
-		umfpack_report_vector.h \
-		umfpack_save_numeric.h \
-		umfpack_save_symbolic.h \
-		umfpack_scale.h \
-		umfpack_solve.h \
-		umfpack_symbolic.h \
-		umfpack_tictoc.h \
-		umfpack_timer.h \
-		umfpack_transpose.h \
-		umfpack_triplet_to_col.h \
-		umfpack_wsolve.h \
+	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}
 }
 
-post-destroot {
-        system "ranlib ${destroot}${prefix}/lib/libamd.a"
-        system "ranlib ${destroot}${prefix}/lib/libbtf.a"
-        system "ranlib ${destroot}${prefix}/lib/libcamd.a"
-        system "ranlib ${destroot}${prefix}/lib/libccolamd.a"
-        system "ranlib ${destroot}${prefix}/lib/libcholmod.a"
-        system "ranlib ${destroot}${prefix}/lib/libcolamd.a"
-        system "ranlib ${destroot}${prefix}/lib/libcxsparse.a"
-        system "ranlib ${destroot}${prefix}/lib/libklu.a"
-        system "ranlib ${destroot}${prefix}/lib/libklu_cholmod.a"
-        system "ranlib ${destroot}${prefix}/lib/libldl.a"
-        system "ranlib ${destroot}${prefix}/lib/libcerbla.a"
-        system "ranlib ${destroot}${prefix}/lib/libumfpack.a"
-}
+livecheck.check	regex
+livecheck.regex	${name}-(\\d+(\\.\\d+)*)${extract.suffix}
