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

PortSystem          1.0
PortGroup           github 1.0
PortGroup           mpi 1.0
PortGroup           linear_algebra 1.0
PortGroup           debug 1.0

github.setup        plumed plumed2 2.9.0 v
name                plumed
revision            1

categories          science

# Most of the PLUMED code is L-GPL3. However, PLUMED containts
# molfile plugins from VMD that are released with a BSD-like license
# http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/
license             LGPL-3 BSD
maintainers         {gmail.com:giovanni.bussi @GiovanniBussi} openmaintainer
description         PLUMED is a plugin for molecular dynamics
long_description    PLUMED is a plugin for molecular dynamics that can be used \
                    in combination with popular molecular dynamics codes to perform biased simulations. \
                    Additionally, it can be used as a standalone tool to analyze trajectories.

platforms           darwin

homepage            http://www.plumed.org/

checksums           rmd160  af05bf43a7df583cf21c7cb2374cceea7dfe4066 \
                    sha256  63e01c425c59e4921429fb79d03710b5d115e47fc8025a165477c6807cbf0014 \
                    size    116844795

# Disable additional features.
# --disable-doc:          Do not create documentation, and avoid searching for Doxygen.
# --disable-libsearch:    Avoid searching libraries using their default names.
#                         This forces the libraries names to be explicitly passed (e.g. "-lz").
#                         It has the advantage that during compilation from source it does not
#                         link packages that are not explicitely required.
# --disable-static-patch: Avoid a number of tests that are only required when linking plumed
#                         statically to an MD code.
# --disable-mpi:          Do not search for MPI compiler (replaced when enabling mpi, see below)
# --disable-python:       Python wrappers will be installed with a separate python port
configure.args-append \
                    --disable-doc \
                    --disable-libsearch \
                    --disable-static-patch \
                    --disable-mpi \
                    --disable-python

# install bash completions
configure.args-append BASH_COMPLETION_DIR=${prefix}/share/bash-completion/completions

# Hardcode path for libplumedKernel.dylib.
# This allows to patch MD codes using the --runtime option but using as
# default kernel the installed one. In this way, MacPorts users
# can just use patched MD codes with the installed plumed or replace it
# by setting PLUMED_KERNEL at runtime
configure.cppflags-append "-D__PLUMED_DEFAULT_KERNEL=${prefix}/lib/libplumedKernel.dylib"

compilers.choose    cc cxx
compiler.cxx_standard  2011

mpi.setup

# To enable mpi, replace a configure flag
if {[mpi_variant_isset]} {
    configure.args-replace --disable-mpi --enable-mpi
# command should be included in a pre-configure block to access properly the mpi.exec variable
    pre-configure {
# MPIEXEC is stored so that it can be used to perform tests
        configure.args-append MPIEXEC="${mpi.exec}"
    }
}

# Optimization flags.
# Notice that plumed is computationally heavy and that
# this change has a significant impact in plumed performances
configure.cxxflags-replace -Os -O3

# Libraries.
# Library names are specified here to make sure that
# only requested packages are linked.
configure.ldflags-append \
                    -lz -lgsl -lfftw3
depends_lib-append  port:fftw-3 \
                    port:gawk \
                    port:gsl \
                    port:zlib

# C++ library
# Required in order to use clang with gcc library on old OSX versions.
# See https://github.com/macports/macports-ports/pull/1254
if {[string match *clang* ${configure.compiler}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

# This variant enables optional modules in PLUMED.
# Notice that one of the optional modules (drr) requires boost_serialization
variant allmodules description {Enable all optional modules} {
    configure.args-append --enable-modules=all
    configure.args-append --enable-boost-serialization
    configure.ldflags-append -lboost_serialization-mt
    depends_lib-append port:boost
}

# Link lapack/blas libraries
pre-configure {
    # commands should be included in a pre-configure block to access tcl variables
    configure.ldflags-append ${linalglib}
}

# plumed-devel subport
# This subport installs the developer version
subport plumed-devel {
    github.setup        plumed plumed2 b10067f646c3a957618fd0dfcc3bc0a74c9d45c6
    version             2.10-20230525
    revision            0
    description         ${description} (development version)
    long_description    ${long_description} (development version)
    conflicts plumed
    checksums           rmd160  bc4ef71db62a35b276b2d2fc2aaec03184d825e2 \
                        sha256  df9731de2f755367ebe94cf6f240c940a9a885cd1427734e342b0ca9e635d777 \
                        size    116645604
}

# Allow running tests from MacPorts
test.run yes
test.target check