# -*- 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 107233 2013-06-23 22:06:03Z cal@macports.org $

PortSystem          1.0
PortGroup           active_variants 1.1

name                octopus
version             4.1.0
categories          science
platforms           darwin
license             GPL-2+
maintainers         gmail.com:dstrubbe

description         A real-space (time-dependent) density-functional theory code.
long_description    Octopus is a scientific program aimed at ab initio virtual experimentation \
                    on a hopefully ever-increasing range of system types. \
                    Electrons are described quantum-mechanically within density-functional \
                    theory (DFT), in its time-dependent form (TDDFT) when doing simulations \
                    in time. Nuclei are described classically as point particles. Electron-nucleus \
                    interaction is described within the pseudopotential approximation.
homepage            http://www.tddft.org/programs/octopus
master_sites        ${homepage}/download/${version}

checksums           rmd160  636cf345f53a8d558a79258a257ed68a17488b76 \
                    sha256  e367b2e594d8344085c8c424c8a31b4a7210b80e83c2d331ee602cc6fc7c838a

depends_lib         port:atlas port:libxc port:fftw-3 port:gsl

configure.args      --with-libxc-prefix=${prefix} --with-blas=-lsatlas \
                    --disable-gdlib --without-sparskit --with-netcdf-prefix=no \
                    --with-etsf-io-prefix=no --with-berkeleygw-prefix=no \
                    --with-arpack=no --with-libfm=no --with-pfft-prefix=no \
                    --with-pspio-prefix=no --with-nfft=no
# configure will find and use these other libraries unless they are explicitly disabled

pre-configure {
    configure.args-append  FCCPP="${configure.cpp} -ansi"

    # use of the same Fortran compiler as the one being used here does not seem necessary
    if { ![active_variants fftw-3 gcc43] && ![active_variants fftw-3 gcc44] && \
         ![active_variants fftw-3 gcc45] && ![active_variants fftw-3 gcc46] && \
         ![active_variants fftw-3 gcc47] && ![active_variants fftw-3 gcc48] && \
         ![active_variants fftw-3 g95] } {
        ui_error "fftw-3 must be built with a Fortran variant"
        return -code error "fftw-3 needs Fortran variant"
    }
}
configure.optflags  -O3

# More options that could be added:
# variants: berkeleygw, openmp, openmpi, mpich, threads (for fftw, atlas?), scalapack, arpack
# with MPI would need to disable zoltan, scalapack explicitly. no way to turn off PAPI.

# libxc does not have universal variant, so octopus cannot either
universal_variant   no

test.run            yes
test.target         check-full

variant gcc46 conflicts gcc47 description {Build with GCC 4.6} {
    configure.compiler  macports-gcc-4.6
    depends_lib-append  port:gcc46
    require_active_variants libxc gcc46
}

variant gcc47 conflicts gcc46 description {Build with GCC 4.7} {
    configure.compiler  macports-gcc-4.7
    depends_lib-append  port:gcc47
    require_active_variants libxc gcc47
}

default_variants +newuoa
if {![variant_isset gcc46]} {
    default_variants    +gcc47
}

variant newuoa description {Build with internal newuoa library for optimal control} {
    configure.args-append --enable-newuoa
}

variant netcdf description {Build with support for NetCDF output} {
    configure.args-delete   --with-netcdf-prefix=no
    configure.args-append   --with-netcdf-prefix=${prefix}
    depends_lib-append      port:netcdf-fortran

    require_active_variants netcdf-fortran {} universal
    if {[variant_isset gcc46]} {
        require_active_variants netcdf-fortran gcc46
    } else {
        require_active_variants netcdf-fortran gcc47
    }
}

variant etsf_io requires netcdf description {Build with support for ETSF_IO output} {
    configure.args-delete   --with-etsf-io-prefix=no
    configure.args-append   --with-etsf-io-prefix=${prefix}
    depends_lib-append      port:etsf_io

    if {[variant_isset gcc46]} {
        require_active_variants etsf_io gcc46
    } else {
        require_active_variants etsf_io gcc47
    }
}

variant sparskit description {Build with support for SPARSKIT propagators} {
    configure.args-delete   --without-sparskit
    depends_lib-append      port:sparskit
}

variant gdlib description {Build with support for definition of domain by 2D image} {
    configure.args-delete   --disable-gdlib
    depends_lib-append      port:gd2
}

livecheck.type      regex
livecheck.url       ${homepage}/wiki/index.php/Main_Page
livecheck.regex     ${name} (\[0-9.\]+)
