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

PortSystem          1.0
PortGroup           mpi 1.0

mpi.setup

name                sundials
version             2.5.0
revision            1
categories          math devel
license             bsd
platforms           darwin
maintainers         sean openmaintainer

description         SUite of Nonlinear and DIfferential/ALgebraic equation Solvers

long_description    SUNDIALS consists of the following five solvers: CVODE\
                    solves initial value problems for ordinary differential\
                    equation (ODE) systems.  CVODES solves ODE systems and\
                    includes sensitivity analysis capabilities (forward and\
                    adjoint).  IDA solves initial value problems for\
                    differential-algebraic equation (DAE) systems.  IDAS solves\
                    DAE systems and includes sensitivity analysis capabilities\
                    (forward and adjoint).  KINSOL solves nonlinear algebraic\
                    systems.

homepage            http://computation.llnl.gov/casc/sundials/main.html
master_sites        http://computation.llnl.gov/casc/sundials/download/code/

checksums           rmd160  c489fcb114f6846c7d5aef2d0eb096cb96f3fbc9 \
                    sha256  9935760931fa6539edd0741acbcf4986770426fd5ea40e50ad4ebed0fc77b0d3

patchfiles          sundials-2.5.0_destdir.patch
patch.pre_args      -p1

configure.args      --enable-shared \
                    --disable-mpi \
                    --without-blas \
                    --without-lapack

if {![mpi_variant_isset]} {
    default_variants      +mpich
}

if {![fortran_variant_isset] && ![mpi_variant_isset]} {
    if {[variant_isset atlas]} {
        ui_error "Atlas requires a fortran compiler"
        return -code error "no fortran compiler selected"
    }

    # ensure that sundials doesn't try to find a fortran compiler in the user's
    # path
    pre-configure {
        configure.f77
        configure.f90
        configure.fc
    }
} else {
    configure.args-delete --without-blas --without-lapack
    if {![variant_isset atlas]} {
        configure.args-append --with-blas="-framework Accelerate" \
                              --with-lapack="-framework Accelerate"
    }
}

pre-configure {
    if {[mpi_variant_isset]} {
        configure.args-delete --disable-mpi
        configure.args-append --enable-mpi \
                              --with-mpicc=${mpi.cc} \
                              --with-mpif77=${mpi.fc}
    }
}

# gcc is hardcoded in libtool, so we change it to use the CC it found from
# configure
post-configure {
    reinplace "s,`gcc,`\$CC," ${worksrcpath}/libtool
}

variant atlas description {build with atlas (requires a fortran compiler)} {
    depends_lib-append port:atlas
    configure.args-append --with-blas=${prefix}/lib/libtatlas.dylib
    configure.args-append --with-lapack=${prefix}/lib/libtatlas.dylib
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} LICENSE README ${destroot}${prefix}/share/doc/${name}
}

variant doc description {install pdf documentation} {
    post-destroot {
        eval copy [glob ${worksrcpath}/doc/*] ${destroot}${prefix}/share/doc/${name}
        system "find ${destroot}${prefix}/share/doc -type f -exec chmod 644 {} \\;"
    }
}

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