# -*- 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 113583 2013-11-20 03:35:57Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           muniversal 1.0

name                gromacs
version             4.5.6
categories          science math
license             gpl
maintainers         nomaintainer
description         The World's fastest Molecular Dynamics package
long_description    GROMACS is a versatile package to perform molecular \
                    dynamics, i.e. simulate the Newtonian equations of motion for \
                    systems with hundreds to millions of particles. It is primarily \
                    designed for biochemical molecules like proteins and lipids that \
                    have a lot of complicated bonded interactions, but since GROMACS is \
                    extremely fast at calculating the nonbonded interactions (that \
                    usually dominate simulations) many groups are also using it for \
                    research on non-biological systems, e.g. polymers
platforms           darwin

homepage            http://www.gromacs.org/
master_sites        ftp://ftp.gromacs.org/pub/gromacs \
                    http://cluster.earlham.edu/detail/home/charliep/packages

checksums           rmd160  7337bad702f452a976b5852644b7e3809c35f3f9 \
                    sha256  eaebebcee3e93b2014b17090171f78c045017c62e58678096e126af0033a5b84

depends_build       port:pkgconfig

depends_lib         port:libxml2

configure.args      --bindir=${prefix}/lib/${name}/bin \
                    --enable-shared \
                    --without-x

variant x11 conflicts no_x11 description {enable the openmotif interface} {
    depends_lib-append      port:openmotif
    configure.args-delete   --without-x
    configure.args-append   --with-x
}

# remove this in August 2014
variant no_x11 conflicts x11 description {legacy compatibility variant} {}
if {[variant_isset no_x11]} {
    default_variants        -x11
} else {
    default_variants        +x11
}

variant gsl description {enable extra analyses via the GNU scientific library} {
    depends_lib-append      port:gsl
    configure.args-append   --with-gsl
}

variant openmpi description {build using openmpi parallelization} {
    depends_lib-append      port:openmpi
    configure.args-append   --enable-mpi
}

variant gcc43 conflicts gcc44 gcc45 gcc46 gcc47 gcc48 description {build with macports-gcc-4.3} {
    configure.compiler  macports-gcc-4.3
}

variant gcc44 conflicts gcc43 gcc45 gcc46 gcc47 gcc48 description {build with macports-gcc-4.4} {
    configure.compiler  macports-gcc-4.4
}

variant gcc45 conflicts gcc43 gcc44 gcc46 gcc47 gcc48 description {build with macports-gcc-4.5} {
    configure.compiler  macports-gcc-4.5
}

variant gcc46 conflicts gcc43 gcc44 gcc45 gcc47 gcc48 description {build with macports-gcc-4.6} {
    configure.compiler  macports-gcc-4.6
}

variant gcc47 conflicts gcc43 gcc44 gcc45 gcc46 gcc48 description {build with macports-gcc-4.7} {
    configure.compiler  macports-gcc-4.7
}

variant gcc48 conflicts gcc43 gcc44 gcc45 gcc46 gcc47 description {build with macports-gcc-4.8} {
    configure.compiler      macports-gcc-4.8
}

if {![variant_isset gcc43] && ![variant_isset gcc44] && ![variant_isset gcc45] && ![variant_isset gcc46] && ![variant_isset gcc47] && ![variant_isset gcc48]} {
    default_variants        +gcc48
}

if {${name} eq ${subport}} {
    depends_lib-append      port:fftw-3-single

    livecheck.type          regex
    livecheck.url           ${homepage}Downloads
    livecheck.regex         ${name}-(\[0-9.\]+)${extract.suffix}
} else {
    livecheck.type          none
}

subport ${name}-double {
    description-append      (double-precision)
    long_description-append (double-precision)

    depends_lib-append      port:${name} \
                            port:fftw-3

    configure.args-append   --enable-double

    post-destroot {
        # All the required files are provided by the single-precision 'gromacs' port. Delete everything that's not required.
        system "find \"${destroot}${prefix}\" -depth 1 -not -name lib -print0 | xargs -0 rm -rf"
        system "find \"${destroot}${prefix}\" -type f -not -iname '*_d' -a -not -name '*_d.*' -print0 | xargs -0 rm -rf"
    }
}
