# -*- 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

name                superlu
version             4.3
categories          math
platforms           darwin
maintainers         sean openmaintainer
description         A package for solving linear equations
long_description    SuperLU is a general purpose library for the direct \
                    solution of large, sparse, nonsymmetric systems of \
                    linear equations on high performance machines.

homepage            http://crd.lbl.gov/~xiaoye/SuperLU
master_sites        ${homepage}

checksums           rmd160  36e59ed230071561d2a8003e6588c128edae5187 \
                    sha256  169920322eb9b9c6a334674231479d04df72440257c17870aaa0139d74416781

distname            ${name}_${version}
worksrcdir          SuperLU_${version}

use_configure       no
use_parallel_build  no

configure.cflags    -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -O3 -mtune=native

build.target        lib LAAUX="" SLASRC="" DLASRC="" CLASRC="" ZLASRC="" SCLAUX="" DZLAUX=""

post-extract {
    reinplace "s|^SuperLUroot.*$|SuperLUroot = ${worksrcpath}|" ${worksrcpath}/make.inc
    reinplace "s|^SUPERLULIB.*$|SUPERLULIB = \$(SuperLUroot)/lib/libsuperlu_${version}.a|" ${worksrcpath}/make.inc
    reinplace "s|^BLASLIB.*$|BLASLIB = -framework Accelerate|" ${worksrcpath}/make.inc
    reinplace "s|^CC.*$|CC = ${configure.cc}|" ${worksrcpath}/make.inc
    reinplace "s|^LOADER.*$|LOADER = ${configure.cc}|" ${worksrcpath}/make.inc
    reinplace "s|^CFLAGS.*$|CFLAGS = ${configure.cflags}|" ${worksrcpath}/make.inc
    reinplace "s|^MATLAB.*$||" ${worksrcpath}/make.inc
    reinplace "s|^PLAT.*$||" ${worksrcpath}/make.inc
    reinplace "s|^RANLIB.*$|RANLIB = ranlib -c|" ${worksrcpath}/make.inc
    reinplace "s|^TMGLIB.*$|TMGLIB = tmglib.a|" ${worksrcpath}/make.inc

    # Prefixing a namespace so that colamd doesn't conflict with itself (used in
    # other packages
    reinplace "s|^#include \"colamd\.h\"|#include \"slu_colamd\.h\"|" ${worksrcpath}/SRC/colamd.c
    reinplace "s|^#include \"colamd\.h\"|#include \"slu_colamd\.h\"|" ${worksrcpath}/SRC/get_perm_c.c
    move ${worksrcpath}/SRC/colamd.h ${worksrcpath}/SRC/slu_colamd.h
}

destroot {
    # make shared libraries
    system -W ${worksrcpath}/SRC "${configure.cc} *.o -framework Accelerate -dynamiclib -Wl,-headerpad_max_install_names,-multiply_defined,suppress,-commons,use_dylibs,-search_paths_first -install_name ${prefix}/lib/lib${distname}.dylib -o lib${distname}.dylib"

    xinstall -W ${worksrcpath}/SRC -m 644 slu_colamd.h slu_Cnames.h slu_dcomplex.h slu_scomplex.h superlu_enum_consts.h \
        slu_util.h supermatrix.h html_mainpage.h slu_cdefs.h slu_ddefs.h slu_sdefs.h slu_zdefs.h \
        ${destroot}${prefix}/include
    xinstall -m 644 ${worksrcpath}/SRC/libsuperlu_${version}.dylib ${destroot}${prefix}/lib
}

livecheck.type      regex
livecheck.regex     ${name}_(\[0-9.\]+)${extract.suffix}
