diff --git a/.travis.yml b/.travis.yml
index 35b220f2b3261a54a4b776a45de970c7a42d4eae..37285760aadba6f306eac562b58f626edb7c7112 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -48,6 +48,13 @@ matrix:
 # osx parallel
   - os: osx
     env: PLUMED_CC=mpicc PLUMED_CXX=mpic++  PLUMED_CXXFLAGS=-O3
+# osx serial macports
+  - os: osx
+    env: PLUMED_MACPORTS="plumed"
+# osx serial macports debug variant
+  - os: osx
+    env: PLUMED_MACPORTS="plumed +crystallization +manyrestraints"
+# I don't put any mpi variant with macports since it takes too long to compile
   allow_failures:
 # I allow this to fail temporarily
     - env: CPPCHECK=yes CPPCHECK_VERSION=1.74
@@ -65,7 +72,7 @@ install:
   - ./.travis/check.log makedoc  || MAKEDOC=no
   - ./.travis/check.log valgrind || VALGRIND=no
 # update packages
-  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update > /dev/null ; fi
+  - if [[ "$TRAVIS_OS_NAME" == "osx" ]] && test -z "$PLUMED_MACPORTS" ; then brew update > /dev/null ; fi
   - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq ; fi
 # install some package - these are fast, we install them anyway
   - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y libmatheval-dev libfftw3-dev gsl-bin libgsl0-dev ; fi
@@ -89,6 +96,15 @@ install:
 # moreover, we hardcode path to dynamic library, required for xdrfile to link properly
 # I do it only when LD_LIBRARY_PATH is non blank, since otherwise clang gives problems
   - if test -n "$LD_LIBRARY_PATH" ; then PLUMED_LDFLAGS="-Wl,-rpath,$LD_LIBRARY_PATH" ; fi
+# macports related stuff
+  - if test -n "$PLUMED_MACPORTS" ; then stty rows 40 columns 80 ; fi
+  - if test -n "$PLUMED_MACPORTS" ; then wget https://distfiles.macports.org/MacPorts/MacPorts-2.3.4.tar.bz2 && tar xvfj MacPorts-2.3.4.tar.bz2 ; fi
+  - if test -n "$PLUMED_MACPORTS" ; then cd MacPorts-2.3.4 && ./configure && sudo make install && cd - && sudo rm -fr MacPorts-2.3.4 ; fi
+  - if test -n "$PLUMED_MACPORTS" ; then export PATH=/opt/local/bin:$PATH ; fi
+  - if test -n "$PLUMED_MACPORTS" ; then sudo port -v selfupdate ; fi
+  - if test -n "$PLUMED_MACPORTS" ; then make macports ; fi
+  - if test -n "$PLUMED_MACPORTS" ; then ./.travis/config.macports.sh ; fi
+
 script:
 # we enable crystallization and manyrestraints modules
   - CONFIG_FLAGS="$CONFIG_FLAGS --enable-modules=crystallization:manyrestraints:adjmat"
@@ -104,12 +120,15 @@ script:
 # we install plumed so that it is in the path
   - if test "$PLUMED_CXX" ; then make install prefix="$HOME/opt" ; fi
 
+# build using macports
+  - if test -n "$PLUMED_MACPORTS" ; then sudo port install $PLUMED_MACPORTS ; fi
+
 # TEST:
   - if test "$VALGRIND" == yes ; then OPT=valgrind ; else OPT="" ; fi
-  - if test "$PLUMED_CXX" ; then make -C regtest $OPT ; fi
+  - if test "$PLUMED_CXX" || test -n "$PLUMED_MACPORTS" ; then make -C regtest $OPT ; fi
   - if test "$MAKEDOC" == yes ; then make -C regtest copytodoc ; fi
   - if test "$MAKEDOC" == yes ; then make doc >/dev/null ; fi
-  - if test "$PLUMED_CXX" ; then make -C regtest checkfail ; fi
+  - if test "$PLUMED_CXX" || test -n "$PLUMED_MACPORTS" ; then make -C regtest checkfail ; fi
 
 # CPPCHECK:
 # this is required so as to have all the include files inplace:
diff --git a/.travis/config.macports.sh b/.travis/config.macports.sh
new file mode 100755
index 0000000000000000000000000000000000000000..b5cb3db113e931c65912ea1afdf1f5387006a244
--- /dev/null
+++ b/.travis/config.macports.sh
@@ -0,0 +1,16 @@
+#! /bin/bash
+
+set -e
+set -x
+
+cd macports
+
+cp /opt/local/etc/macports/sources.conf $$
+awk -v repo="file://$PWD" '{if($NF=="[default]") print repo; print}' $$ > $$.new
+sudo mv -f $$.new /opt/local/etc/macports/sources.conf
+echo "** NEW SOURCES"
+cat /opt/local/etc/macports/sources.conf
+echo "** END NEW SOURCES"
+rm -f $$
+portindex
+
diff --git a/CHANGES/v2.2.txt b/CHANGES/v2.2.txt
index 71ffd50ad4feb4f806afda5d0ccf014ca5a646d4..312b3556316ac2eaa57d5681627d5fc79e672212 100644
--- a/CHANGES/v2.2.txt
+++ b/CHANGES/v2.2.txt
@@ -173,4 +173,7 @@ For users:
 - GSL library is now treated by `./configure` in the same way as other libraries, that is `-lgsl -lgslcblas` are only
   added if necessary.
 
+For developers:
+- Macports portile is now tested on travis at every plumed push.
+
 */
diff --git a/Makefile b/Makefile
index d9d1476ce4a257b0a562eeb3ee6c2adbe8436700..bc6d0a54c8d2731cbe020c1f82007e7c6cc6c290 100644
--- a/Makefile
+++ b/Makefile
@@ -4,12 +4,12 @@ endif
 
 
 SRCDIRS := src test
-SUBDIRS := $(SRCDIRS) user-doc developer-doc regtest
+SUBDIRS := $(SRCDIRS) user-doc developer-doc regtest macports
 
 SUBDIRSCLEAN:=$(addsuffix .clean,$(SUBDIRS))
 
      
-.PHONY: all lib clean $(SRCDIRS) doc docclean check cppcheck distclean all_plus_docs
+.PHONY: all lib clean $(SRCDIRS) doc docclean check cppcheck distclean all_plus_docs macports
 
 # if machine dependent configuration has been found:
 ifdef GCCDEP
@@ -91,6 +91,9 @@ docclean:
 cppcheck:
 	$(MAKE) -C src cppcheck
 
+macports:
+	$(MAKE) -C macports
+
 # stamp-h file keeps track of when ./configure was last applied
 # the procedure below is taken from:
 # https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Automatic-Remaking.html#Automatic-Remaking
diff --git a/macports/.gitignore b/macports/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..5eb6dfb66390924de5b0142f9ce2295ac8370bbe
--- /dev/null
+++ b/macports/.gitignore
@@ -0,0 +1 @@
+/science
diff --git a/macports/Makefile b/macports/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..85cb6481e8a5e9d6e18f19e5aa5fb614cd20f8d2
--- /dev/null
+++ b/macports/Makefile
@@ -0,0 +1,4 @@
+all:
+	./generate-portfile.sh
+clean:
+	rm -fr science
diff --git a/macports/Portfile.in b/macports/Portfile.in
new file mode 100644
index 0000000000000000000000000000000000000000..0df291c79226451677aadd697d9e327dac040091
--- /dev/null
+++ b/macports/Portfile.in
@@ -0,0 +1,127 @@
+# -*- 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 123374 2014-08-08 21:53:07Z mojca@macports.org $
+
+PortSystem          1.0
+
+name                plumed
+PortGroup           mpi 1.0
+PortGroup           linear_algebra 1.0
+PortGroup           debug 1.0
+
+version             @_VERSION_@
+revision            @_REVISION_@
+categories          science
+license             LGPL-3
+maintainers         gmail.com:giovanni.bussi
+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:
+
+# Disable additional features.
+# they are then re-enabled when selecting proper variants
+# this is important for features that require an additional package to be
+# sure that even if the user has that package already installed plumed is
+# not going to use it.
+configure.args-append \
+               --disable-matheval \
+               --disable-xdrfile \
+               --disable-molfile-plugins \
+               --disable-zlib \
+               --disable-mpi \
+               --disable-gsl
+
+# 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
+mpi.setup
+
+if {[mpi_variant_isset]} {
+  configure.args-replace --disable-mpi --enable-mpi
+}
+
+variant matheval description {Enable libmatheval} {
+  configure.args-replace --disable-matheval --enable-matheval
+  depends_lib-append port:libmatheval
+}
+
+variant xdrfile description {Enable xdrfile} {
+  configure.args-replace --disable-xdrfile --enable-xdrfile
+  depends_lib-append port:xdrfile
+}
+
+variant zlib description {Enable zlib} {
+  configure.args-replace --disable-zlib --enable-zlib
+  depends_lib-append port:zlib
+}
+
+variant gsl description {Enable gsl} {
+  configure.args-replace --disable-gsl --enable-gsl
+  depends_lib-append port:gsl
+}
+
+variant molfile description {Enable molfile - includes some BSD code} {
+  license ${license} BSD
+  configure.args-replace --disable-molfile-plugins --enable-molfile-plugins
+}
+
+variant doc description {Also compile documentation} {
+  depends_build-append port:doxygen
+  depends_build-append port:graphviz
+  build.target all_plus_docs
+}
+
+# this is a tcl variable contains a concatenated list of modules
+# to be activated
+
+set plumed_modules reset
+
+variant crystallization description {Enable crystallization module} {
+  set plumed_modules ${plumed_modules}+crystallization
+}
+
+variant manyrestraints description {Enable manyrestraints module} {
+  set plumed_modules ${plumed_modules}+manyrestraints
+}
+
+#### I leave this out momentarily since it has problems
+# variant imd description {Enable imd module - includes some proprietary code} {
+#   license ${license} Restrictive
+#   set plumed_modules ${plumed_modules}+imd
+# }
+ 
+pre-configure {
+  # commands should be included in a pre-configure block to access tcl variables
+  configure.args-append --enable-modules=${plumed_modules}
+  configure.ldflags-append ${linalglib}
+}
+
+# Default variants include no optional modules.
+# Additionally, the link libraries that are very useful (e.g. matheval of xdrfile)
+# and quick to compile
+default_variants +matheval +xdrfile +zlib +molfile
+
+# This is required since PLUMED installation does not do it explicitly.
+# It might be removed when this will be incorporated upstream
+post-destroot {
+    system "install_name_tool -id ${prefix}/lib/libplumed.dylib ${destroot}${prefix}/lib/libplumed.dylib"
+    system "install_name_tool -id ${prefix}/lib/libplumedKernel.dylib ${destroot}${prefix}/lib/libplumedKernel.dylib"
+}
+
diff --git a/macports/generate-portfile.sh b/macports/generate-portfile.sh
new file mode 100755
index 0000000000000000000000000000000000000000..f061e32a56c214fbe5726b1810110eab6ea1a406
--- /dev/null
+++ b/macports/generate-portfile.sh
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+# This script generates a Portfile in science/plumed
+# Currently the portfile is aimed at testing the currect git hash
+# TODO:
+# - Analyze configure.ac to generate the list of variants
+# - Allow for a proper release port.
+#   This would require a portfile that is based on a tag (e.g. v2.3.0),
+#   optionally including patches, that can be then uploaded to macports
+
+hash=$( git log -1 --format="%h")
+
+mkdir -p science/plumed
+
+# parent directory:
+repository="${PWD%/*}"
+
+cat Portfile.in |
+sed "
+  s/@_VERSION_@/$hash/
+  s/@_REVISION_@/0/
+" | awk '{
+  if($1=="@_FETCH_@"){
+    print "fetch.type          git"
+    print "git.url             '$repository'"
+# notice that if instead of hashtag we want to put a version, then it should be
+# git.branch          v${version}
+    print "git.branch          ${version}"
+  } else print
+}'  > science/plumed/Portfile
+
+
+
+