# $Id: Portfile 84527 2011-09-27 18:05:29Z jmr@macports.org $

PortSystem 1.0

name			metis
version			4.0.3
revision		1
categories		math
# Included license is for "evaluation purposes" only (whatever that means) if
# you're not a non-profit or US government agency.
license			Restrictive
platforms		darwin
maintainers		nomaintainer
description		A package for unstructured graph partitioning
long_description	\
METIS is a set of programs for partitioning graphs and for producing fill \
reducing orderings for sparse matrices. The algorithms implemented by METIS \
are based on the multilevel graph partitioning scheme described in \[KK95a\] \
and \[KK95e\]. METIS provides high quality partitions, is extremely fast, and \
produces low fill orderings.

homepage		http://glaros.dtc.umn.edu/gkhome/metis/metis/overview
master_sites		http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/ freebsd

# 4.0.3 was stealth-updated (#28930)
dist_subdir		${name}/${version}_${revision}

checksums		sha1    63303786414a857eaeea2b2a006521401bccda5e \
			rmd160  9d67c92a2a90ece012443fa623442027c0c21297

patchfiles		patch-Makefile.diff

build.target

# Prevent -lmetis from finding library ${prefix}/lib
configure.ldflags-delete   -L${prefix}/lib

set ver0 [join [lrange [split ${version} .] 0 0] .]
set ver1 [join [lrange [split ${version} .] 0 1] .]

configure {
	# ensure that the correct compiler and compiler options are used.
	set optflags ${configure.cflags}
	set ldflags ${configure.ldflags}
	
	if {[variant_isset universal]} {
		append optflags " " ${configure.universal_cflags}
		append ldflags " " ${configure.universal_ldflags}
	} else {
                append optflags " " ${configure.cc_archflags}
		append ldflags " " ${configure.cc_archflags}
        }
	
	reinplace "s|CC = .*|CC = ${configure.cc}|" ${worksrcpath}/Makefile.in
	reinplace "s|OPTFLAGS = .*|OPTFLAGS = ${optflags}|" ${worksrcpath}/Makefile.in
	if { [info exists ldflags] } {
		reinplace "s|LDOPTIONS = .*|LDOPTIONS = ${ldflags}|" ${worksrcpath}/Makefile.in
	}

	reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/Lib/Makefile
	reinplace "s|__VERSION__|${version}|g" ${worksrcpath}/Lib/Makefile
	reinplace "s|__COMPAT_VER__|${ver0}|g" ${worksrcpath}/Lib/Makefile
}

destroot {
	xinstall -m 755 -d ${destroot}${prefix}/include/metis \
		${destroot}${prefix}/share/doc/${name}
	xinstall -m 755 -W ${worksrcpath} graphchk kmetis mesh2dual mesh2nodal \
		oemetis onmetis partdmesh partnmesh pmetis ${destroot}${prefix}/bin
	xinstall -W ${worksrcpath}/Lib -m 644 defs.h macros.h metis.h proto.h rename.h \
		struct.h ${destroot}${prefix}/include/metis
	reinplace "s,#include <defs.h>,#include <metis/defs.h>," ${destroot}${prefix}/include/metis/metis.h
	reinplace "s,#include <struct.h>,#include <metis/struct.h>," ${destroot}${prefix}/include/metis/metis.h
	reinplace "s,#include <macros.h>,#include <metis/macros.h>," ${destroot}${prefix}/include/metis/metis.h
	reinplace "s,#include <rename.h>,#include <metis/rename.h>," ${destroot}${prefix}/include/metis/metis.h
	reinplace "s,#include <proto.h>,#include <metis/proto.h>," ${destroot}${prefix}/include/metis/metis.h
	xinstall -m 644 ${worksrcpath}/libmetis.a ${destroot}${prefix}/lib
	xinstall -m 644 ${worksrcpath}/Doc/manual.ps \
		${destroot}${prefix}/share/doc/${name}

	xinstall -m 0755 ${worksrcpath}/libmetis.dylib ${destroot}${prefix}/lib/libmetis.${version}.dylib
	ln -s libmetis.${version}.dylib ${destroot}${prefix}/lib/libmetis.dylib
	ln -s libmetis.${version}.dylib ${destroot}${prefix}/lib/libmetis.${ver0}.dylib
	ln -s libmetis.${version}.dylib ${destroot}${prefix}/lib/libmetis.${ver1}.dylib
}

livecheck.type  regex
livecheck.url   http://glaros.dtc.umn.edu/gkhome/metis/metis/changes
livecheck.regex {Ver: ([0-9.]+),}
