# -*- 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           mpi 1.0
PortGroup           linear_algebra 1.0
PortGroup           debug 1.0

version             @_VERSION_@
revision            @_REVISION_@
name                plumed
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/

@_FETCH_@

### This is required so that patch made with "git format-patch" work correctly
# patch.pre_args -p1
### In case patches from github should be included to fix behavior on macports one should
### - put patch files (as obtained with git format-patch) in files/ directory
### - list their name here:
# patchfiles file1 \
#            file2
### etc

# Enable optional features.
# --enable-asmjit:        Compile internal asmjit. Notice that internal asmjit is protected in
#                         PLUMED namespace so will not collide with other asmjit implementations.
# 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 \
                    --enable-asmjit \
                    --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 \
                    -lxdrfile -lz -lgsl
depends_lib-append  port:gawk \
                    port:gsl \
                    port:xdrfile \
                    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.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}
}

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


