# $Id: Portfile 89635 2012-02-05 00:22:55Z mmoll@macports.org $

PortSystem      1.0

name            slepc
version         3.2-p3
license         LGPL
categories      math science
maintainers     mmoll
license         LGPL
description     Scalable Library for Eigenvalue Problem Computations
long_description    SLEPc is a software library for the solution of large \
    scale sparse eigenvalue problems on parallel computers. It is an \
    extension of PETSc and can be used for either standard or generalized \
    eigenproblems, with real or complex arithmetic. It can also be used for \
    computing a partial SVD of a large, sparse, rectangular matrix.
notes           "Add the following lines to your .bash_profile if you plan to\
                use the PETSC/SLEPC makefile rules in $prefix/lib/petsc/conf:\n\
                \texport PETSC_DIR=${prefix}/lib/petsc\n\
                \texport SLEPC_DIR=${prefix}/lib/petsc"

platforms       darwin
homepage        http://www.grycap.upv.es/slepc
master_sites    http://www.grycap.upv.es/slepc/download/distrib
distname        ${name}-${version}
universal_variant   no

checksums           md5     db23901779b84362eebb3c100101fff7 \
                    sha1    32a1d58836ceb717bfb61cdf5b3ae57fa214df71 \
                    rmd160  6a7f32a9b5f36438ff4d600ca9c2964f796f4dee

depends_lib-append  port:petsc

configure.args        --prefix=${prefix}/lib/petsc
build.env-append      PETSC_DIR=${prefix}/lib/petsc PETSC_ARCH=arch-installed-petsc SLEPC_DIR=${worksrcpath}
destroot.env-append   PETSC_DIR=${prefix}/lib/petsc PETSC_ARCH=arch-installed-petsc SLEPC_DIR=${worksrcpath}
destroot.cmd-append   SLEPC_DESTDIR=${destroot}${prefix}/lib/petsc

pre-configure { 
    if {[file exists ${prefix}/lib/petsc/lib/libslepc.a]} { 
        ui_error "slepc must be deactivated before upgrade." 
        error "Please run `sudo port deactivate slepc` and try again." 
    } 
}

variant arpack description {compile with ARPACK support} {
    pre-fetch {
        if {![file exists ${prefix}/lib/libparpack.a]} {
            return -code error "Please install the openmpi variant of arpack first."
        }
    }
    # This is a rather fragile way to figure out where the fortran library can be
    # found that is needed to link against libparpack.a:
    if {[file exists ${prefix}/lib/gcc46]} {
        set fortrandir ${prefix}/lib/gcc46
    } else {
        if {[file exists ${prefix}/lib/gcc45]} {
            set fortrandir ${prefix}/lib/gcc45
        } else {
            if {[file exists ${prefix}/lib/gcc44]} {
                set fortrandir ${prefix}/lib/gcc44
            } else {
                if {[file exists ${prefix}/lib/gcc43]} {
                    set fortrandir ${prefix}/lib/gcc43
                } else {
                    if {[file exists ${prefix}/lib/gcc42]} {
                        set fortrandir ${prefix}/lib/gcc42
                    } else {
                        if {[file exists ${prefix}/lib/g95]} {
                            set fortrandir ${prefix}/lib/g95
                        } else {
                            return -code error "Please install a fortran compiler by installing one of the following ports: gcc42, gcc43, gcc44, gcc45, gcc46, or g95."
                        }
                    }
                }
            }
        }
    }
    depends_lib-append      port:arpack
    configure.args-append   --with-arpack-dir=${fortrandir} \
                --with-arpack-flags=-lparpack,-larpack,-lgfortran,-lmpi_f77
}

livecheck.type  regex
livecheck.url   http://www.grycap.upv.es/slepc/download/download.htm
livecheck.regex slepc-(\[0-9.\]+(-p\[0-9\]+))\\.tar.gz
