# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 119604 2014-05-02 09:12:57Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           mpi 1.0

mpi.setup           require require_fortran

mpi.enforce_variant scalapack

name                mumps
version             4.10.0
categories          math
platforms           darwin
maintainers         sean openmaintainer
description         MUltifrontal Massively Parallel sparse direct Solver
long_description    MUMPS: a parallel sparse direct solver
supported_archs     noarch

depends_lib         port:scalapack port:parmetis

homepage            http://mumps.enseeiht.fr/
master_sites        ${homepage}

distname            MUMPS_${version}

checksums           rmd160  19ae1f4773ab1643237f791085d9721932a618fc \
                    sha256  d0f86f91a74c51a17a2ff1be9c9cee2338976f13a6d00896ba5b43a5ca05d933

patch.pre_args      -p1
patchfiles-append   metis.patch \
                    metis-wgts.patch \
                    shared.patch

use_parallel_build  no
use_configure       no

build.target        alllib SHAREDFLAGS="-dynamiclib" PREFIX="${prefix}" SHAREDLIBEXT=".dylib"

configure.cflags    -fPIC -O3 -mtune=native
configure.fflags    -fPIC -O3 -mtune=native
configure.f90flags  -fPIC -O3 -mtune=native

post-extract {
    file copy ${worksrcpath}/Make.inc/Makefile.gfortran.PAR ${worksrcpath}/Makefile.inc
    reinplace "s|^\#LMETISDIR.*$|LMETISDIR = ${prefix}/lib|" ${worksrcpath}/Makefile.inc
    reinplace "s|^\#IMETIS.*$|IMETIS = -I${prefix}/include|" ${worksrcpath}/Makefile.inc
    reinplace "s|^\#LMETIS.*$|LMETIS = ${prefix}/lib/libparmetis.dylib ${prefix}/lib/libmetis.dylib|" ${worksrcpath}/Makefile.inc
    reinplace "s|^ORDERINGSF.*$|ORDERINGSF = -Dpord -Dparmetis|" ${worksrcpath}/Makefile.inc
    reinplace "s|^CC .*$|CC = ${configure.cc}|" ${worksrcpath}/Makefile.inc
    reinplace "s|^FC .*$|FC = ${configure.f90}|" ${worksrcpath}/Makefile.inc
    reinplace "s|^FL .*$|FL = ${configure.f90}|" ${worksrcpath}/Makefile.inc
    reinplace "s|^OPTC .*$|OPTC = ${configure.cflags}|" ${worksrcpath}/Makefile.inc
    reinplace "s|^OPTL .*$|OPTL = ${configure.cflags}|" ${worksrcpath}/Makefile.inc
    reinplace "s|^OPTF .*$|OPTF = ${configure.f90flags}|" ${worksrcpath}/Makefile.inc
    reinplace "s|^AR.*$|AR = ar cr |" ${worksrcpath}/Makefile.inc
    reinplace "s|^RANLIB.*$|RANLIB = ranlib -c|" ${worksrcpath}/Makefile.inc
    reinplace "s|^SCALAP.*$|SCALAP = ${prefix}/lib/libscalapack.dylib|" ${worksrcpath}/Makefile.inc
    reinplace "s|^INCPAR.*$|INCPAR = |" ${worksrcpath}/Makefile.inc
    reinplace "s|^LIBPAR.*$|LIBPAR = \$(SCALAP)|" ${worksrcpath}/Makefile.inc
    reinplace "s|^LIBBLAS.*$|LIBBLAS = -framework Accelerate|" ${worksrcpath}/Makefile.inc
    reinplace "s|inline|static inline|" ${worksrcpath}/include/mumps_compat.h
}

destroot {
  eval xinstall -m 644 [glob ${worksrcpath}/include/*.h] ${destroot}${prefix}/include
  eval xinstall -m 644 [glob ${worksrcpath}/lib/*.a] ${destroot}${prefix}/lib
  eval xinstall -m 644 [glob ${worksrcpath}/lib/*.dylib] ${destroot}${prefix}/lib
}

livecheck.type      regex
livecheck.regex     >(\[0-9.\]+)<
