# $Id: Portfile 105139 2013-04-11 21:31:30Z mmoll@macports.org $

PortSystem	1.0
PortGroup   conflicts_build 1.0
PortGroup   active_variants 1.1

name		petsc
version     3.3-p6
revision    1
categories  math science
maintainers	mmoll
description	Portable, Extensible Toolkit for Scientific Computation
long_description	PETSc, pronounced PET-see (the S is silent), is a suite \
        of data structures and routines for the scalable (parallel) solution \
        of scientific applications modeled by partial differential equations. \
        It employs the MPI standard for all message-passing communication.

notes       "Add the following line to your .bash_profile if you plan to use\
            the PETSC makefile rules in $prefix/lib/petsc/conf: \n\
            \texport PETSC_DIR=${prefix}/lib/petsc"

platforms	darwin
homepage	http://www.mcs.anl.gov/petsc/petsc-as/
master_sites	ftp://ftp.mcs.anl.gov/pub/petsc/release-snapshots/ \
		http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/
distname	${name}-lite-${version}
worksrcdir	${name}-${version}
universal_variant   no

checksums           rmd160  a0aedc01995d60340e302140293d82dcb1ca356c \
                    sha256  09e03c1d871a44e4322d61b007bbefd0a3e0cea5f5568b8ce243b4ef7c19b0b0

depends_build-append  port:cmake
depends_lib-append  port:hdf5-18 \
                    port:libyaml

require_active_variants hdf5-18 fortran

configure.args      --prefix=${prefix}/lib/petsc \
                    --with-mpi=1 \
                    --with-clanguage=C++ \
                    --download-ml \
                    --download-metis \
                    --download-parmetis \
                    --download-blacs \
                    --download-scalapack \
                    --download-mumps \
                    --download-ptscotch \
                    --with-hdf5-dir=${prefix} \
                    --with-yaml-dir=${prefix}

pre-configure {
    if {![file exists ${prefix}/lib/libhdf5_fortran.a]} {
        return -code error "Please install hdf5-18 with the +fortran variant enabled first."
    }
    configure.args-append \
        --COPTFLAGS="${configure.optflags}" \
        --CXXOPTFLAGS="${configure.optflags}" \
        --FOPTFLAGS="${configure.optflags}" \
        --LDFLAGS="${configure.ldflags}" \
        --CFLAGS="${configure.cflags}" \
        --CXXFLAGS="${configure.cxxflags}"
}

conflicts_build     petsc

variant openmpi description {Build using the OpenMPI compiler} conflicts mpich {
    depends_lib-append port:openmpi
    configure.args-append \
        --with-cc=${prefix}/bin/openmpicc \
        --with-cxx=${prefix}/bin/openmpicxx \
        --with-fc=${prefix}/bin/openmpif90 \
        --with-mpiexec=${prefix}/bin/openmpiexec
}

variant mpich description {Build using the MPICH compiler} conflicts openmpi {
    depends_lib-append path:bin/mpicc:mpich
    configure.args-append \
        --with-cc=${prefix}/bin/mpicc \
        --with-cxx=${prefix}/bin/mpicxx \
        --with-fc=${prefix}/bin/mpif90 \
        --with-mpiexec=${prefix}/bin/mpiexec
}

variant accelerate description {Use Accelerate framework for LAPACK} conflicts atlas {
    configure.args-append \
        --with-blas-lib=/usr/lib/libblas.dylib \
        --with-lapack-lib=/usr/lib/liblapack.dylib
    post-configure {
        reinplace "s|-L/usr/lib -llapack -lblas|-Wl,-framework -Wl,Accelerate|g" ${worksrcpath}/arch-darwin-cxx-debug/conf/petscvariables
    }
}

variant atlas description {Use Atlas for LAPACK} conflicts accelerate {
    configure.args-append \
        --with-blas-lapack-lib=${prefix}/lib/libtatlas.dylib
}

if {![variant_isset mpich]} {
    default_variants +openmpi
}
if {![variant_isset atlas]} {
    default_variants +accelerate
}

destroot.destdir DESTDIR=${destroot}${prefix}/lib/petsc

livecheck.type  regex
livecheck.url   http://www.mcs.anl.gov/petsc/petsc-2/download/index.html
livecheck.regex petsc-lite-(\[0-9.\]+(-p\[0-9\]+))\\.tar\\.gz

variant mpich2 requires mpich description {Legacy compatibility variant} {}
