Skip to content
Snippets Groups Projects
Commit f98f64eb authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Configuration with autoconf

One can now produce a Makefile.conf and a sourceme.sh
using autoconf. Just type:

./configure

Or maybe

./configure CXX=icpc

In case you want to use mpi, just use:

./configure CXX=mpic++

Everything should be smooth. I took care that the generated Makefile.conf
is compatible with those stored in configurations/. In this way,
one can always resort to a saved configuration file. Moreover,
jumping between git branches (without need of reconfiguring) will be
easier.

More info on the manual page (no need to use autoconf to compile
the manual and see that page)

Closes #46
parent a6716b51
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
Includes all fixes in branch 2.0 (see \ref CHANGES-2-0) up to 2.0.1
Changes from version 2.0 which are relevant for users:
- New configuration system based on autoconf (use ./configure from root directory)
- Added option PRECISION to set number of digits in DUMPATOMS
- Added NDX_FILE and NDX_GROUP to action GROUP, allowing to import atom lists from ndx files
- Several optimizations in the following actions: WHOLEMOLECULES, ...
......
......@@ -57,6 +57,10 @@ fullclean:
make clean
rm -f Makefile.conf
rm -f sourceme.sh
rm -fr autoconf/auto*
rm -f autoconf/Makefile.conf
rm -f autoconf/sourceme.sh
rm -f autoconf/config.*
docclean:
......
......@@ -7,7 +7,7 @@ PEOPLE : list of authors
README : this file
README.git : quick reference for git
configurations/ : template configuration files
configure.sh : configuration script
configure : configuration script
developer-doc : developer documentation
patches : set of diff and patch scripts, needed to embed plumed in MD programs
regtest : extensive set of regression tests, including reference results
......@@ -34,7 +34,7 @@ Needed software:
Quick compilation instructions:
* configure for your system:
> ./configure.sh
> ./configure
* if necessary, edit Makefile.conf
* configure your environment
> source ./sourceme.sh
......
config.*
autom4*
Makefile.conf
sourceme.sh
test*
CC=@CC@
FC=@FC@
LDF90=@FC@
CFLAGS=@CFLAGS@
CXX=@CXX@
CXXFLAGS=@CXXFLAGS@
CPPFLAGS=@CPPFLAGS@ @DEFS@
LDFLAGS=
DYNAMIC_LIBS=@LIBS@ @LDFLAGS@
LIBS=@STATIC_LIBS@
SOEXT=@SOEXT@
LD=@LD@
LDSO=@LDSO@
GCCDEP=@CXX@
prefix=@prefix@
DO NOT EDIT configure FILE
One should edit configure.ac and the run autoconf in this
directory. Also the resulting "configure" is stored on the git,
so as to allow people not to install a recent autoconf on their
system.
If you modify configure.ac, remember to run
autoconf and then commit both files to the git repository.
This diff is collapsed.
# we require a recent version
# notice that autoconf is not necessary on user's machine, but only
# if one has to update configure.ac
AC_PREREQ([2.69])
AC_INIT([PLUMED], [2])
##################################################################
# Here we define a few useful macros
# PLUMED_CONFIG_ENABLE(variablename,optionname,doc,default)
# notice that variablename and optionname are likely identical,
# they just need to be different with optionname contains a "-"
# (not allowed in shell variable names)
AC_DEFUN([PLUMED_CONFIG_ENABLE], [
$1=
AC_ARG_ENABLE([$2],
AS_HELP_STRING([--enable-$2], [enable $3, default: $4]),
[case "${enableval}" in
(yes) $1=true ;;
(no) $1=false ;;
(*) AC_MSG_ERROR([wrong argument to --enable-$2]) ;;
esac],
[case "$4" in
(yes) $1=true ;;
(no) $1=false ;;
esac]
)
])
# PLUMED_CHECK_CXXFLAG(flag)
# use it to check if a flag is available on this compiler
AC_DEFUN([PLUMED_CHECK_CXXFLAG], [
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
AC_MSG_CHECKING([whether $CXX accepts $1])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no]); CXXFLAGS="$save_CXXFLAGS"]
)
])
# PLUMED_CHECK_PACKAGE(header,function,define[,library])
# first we check if the header is present. if so, we check if the given function can be found.
# if it cannot be found and the fourth argument (library) has been supplied, we look for it
# in the library. finally, we set the define flag
AC_DEFUN([PLUMED_CHECK_PACKAGE], [
found=ko
AC_CHECK_HEADER( [$1],[
AC_CHECK_FUNC( [$2], [found=ok],
m4_ifnblank([$4],[AC_CHECK_LIB( [$4], [$2], [LIBS="-l$4 $LIBS" && found=ok]) ])
)
])
if test $found == ok ; then
AC_DEFINE([$3])
fi
])
##################################################################
# set enable flags for ./configure
PLUMED_CONFIG_ENABLE([debug],[debug],[debugging],[no])
PLUMED_CONFIG_ENABLE([fussy],[fussy],[fussy warnings],[no])
PLUMED_CONFIG_ENABLE([debug_glibcxx],[debug-glibcxx],[enable boundary check],[no])
PLUMED_CONFIG_ENABLE([shared],[shared],[shared libs],[yes])
PLUMED_CONFIG_ENABLE([cxx_exceptions],[cxx-exceptions],[c++ exceptions],[no])
# by default use -O flag
# we override the autoconf default (-g) because in release build we do not want to
# include symbol information (obj files are huge)
if test -z "$CXXFLAGS"
then
CXXFLAGS=-O
fi
# setup C/C++ compilers
AC_PROG_CXX
AC_PROG_CC
# also setup Fortran compiler
# this is optional, and can be used in the late part of this
# script to verify that fortran can indeed link properly the
# a c++ library
AC_PROG_FC
# we use C++ for all the autoconf tests
AC_LANG(C++)
# log the initial flags
LD="$CXX"
LDSO="$CXX"
AC_MSG_NOTICE([Initial CXX: $CXX])
AC_MSG_NOTICE([Initial CXXFLAGS: $CXXFLAGS])
AC_MSG_NOTICE([Initial CPPFLAGS: $CPPFLAGS])
AC_MSG_NOTICE([Initial LDFLAGS: $LDFLAGS])
AC_MSG_NOTICE([Initial LIBS: $LDFLAGS])
AC_MSG_NOTICE([Initial LD: $LD])
AC_MSG_NOTICE([Initial LDSO: $LDSO])
AC_MSG_NOTICE([Initial SOEXT: $SOEXT])
# check C++ flags
PLUMED_CHECK_CXXFLAG([-fPIC])
PLUMED_CHECK_CXXFLAG([-Wall])
PLUMED_CHECK_CXXFLAG([-pedantic])
PLUMED_CHECK_CXXFLAG([-ansi])
if test $debug == true
then
PLUMED_CHECK_CXXFLAG([-g])
fi
if test $fussy == true
then
PLUMED_CHECK_CXXFLAG([-Wextra])
PLUMED_CHECK_CXXFLAG([-Wfloat-equal])
PLUMED_CHECK_CXXFLAG([-Wwrite-strings])
PLUMED_CHECK_CXXFLAG([-Wpointer-arith])
PLUMED_CHECK_CXXFLAG([-Wcast-qual])
PLUMED_CHECK_CXXFLAG([-Wcast-align])
PLUMED_CHECK_CXXFLAG([-Wconversion])
PLUMED_CHECK_CXXFLAG([-Wredundant-delcs])
PLUMED_CHECK_CXXFLAG([-Wvariadic-macros])
PLUMED_CHECK_CXXFLAG([-Wold-style-cast])
fi
#### Compulsory libraries ####
# some of them might be made optional if we find that are not available in some system
AC_MSG_NOTICE([Now we will check compulsory headers and libraries])
AC_CHECK_HEADER([sys/time.h], [ ], [AC_MSG_ERROR([compulsory header not found])] )
AC_CHECK_FUNC( [gettimeofday], [ ], [AC_MSG_ERROR([compulsory function not found])] )
AC_CHECK_HEADER([dirent.h], [ ], [AC_MSG_ERROR([compulsory header not found])] )
AC_CHECK_FUNC( [readdir], [ ], [AC_MSG_ERROR([compulsory function not found])] )
# Then check for blas. This is a bit complicated because we want to allow
# either the version with underscore or the one without
# If they are not found in the normal search path, we repeat the search with -lblas
blas_found=
AC_CHECK_FUNC( [dgemv], [blas_found=nounderscore], [
AC_CHECK_FUNC( [dgemv_],[blas_found=underscore], [
AC_CHECK_LIB( [blas],[dgemv], [LIBS="-lblas $LIBS"] [blas_found=nounderscore], [
AC_CHECK_LIB( [blas],[dgemv_], [LIBS="-lblas $LIBS"] [blas_found=underscore], [
AC_MSG_ERROR([blas not found - please set your LDFLAGS and LIBS so that they can be found])
]) ]) ]) ])
# Then we look for lapack using same underscoring
case "$blas_found" in
(underscore) search_for=dsyevr_ ;;
(nounderscore) search_for=dsyevr ;;
esac
AC_CHECK_FUNC( [$search_for], [lapack_found=$blas_found], [
AC_CHECK_LIB( [lapack],[$search_for], [LIBS="-llapack $LIBS"], [
AC_MSG_ERROR([lapack not found - please set your LDFLAGS and LIBS so that they can be found])
])
])
#### End of compulsory libraries ####
#### Optional libraries ####
AC_MSG_NOTICE([Now we will check for optional headers and libraries])
# this is special and is also attached to STATIC_LIBS
# this flag should be used also when linking MD engines to allow plumed
# to be loaded later
AC_CHECK_LIB([dl],dlopen, [STATIC_LIBS="-ldl $STATIC_LIBS"] [LIBS="-ldl $LIBS"])
# optional libraries follow
PLUMED_CHECK_PACKAGE([matheval.h],[evaluator_create],[__PLUMED_HAS_MATHEVAL],[matheval])
PLUMED_CHECK_PACKAGE([time.h],[clock_gettime],[__PLUMED_HAS_CLOCK_GETTIME],[rt])
PLUMED_CHECK_PACKAGE([mpi.h],[MPI_Init],[__PLUMED_HAS_MPI])
PLUMED_CHECK_PACKAGE([regex.h],[regcomp],[__PLUMED_HAS_REGEX])
PLUMED_CHECK_PACKAGE([dlfcn.h],[dlopen],[__PLUMED_HAS_DLOPEN])
PLUMED_CHECK_PACKAGE([execinfo.h],[backtrace],[__PLUMED_HAS_EXECINFO])
# check for zlib
# PLUMED_CHECK_PACKAGE([zlib.h],[gzopen],[__PLUMED_HAS_ZLIB],[z])
# this can be used to enable openmp:
# AC_OPENMP
# CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
#### End of optional libraries ####
# in non-debug mode, add -DNDEBUG
if test "$debug" == false ; then
AC_MSG_NOTICE([Release mode, adding -DNDEBUG])
AC_DEFINE([NDEBUG])
fi
# in debug-glibcxx mode, add -D_GLIBCXX_DEBUG
if test "$debug_glibcxx" == true ; then
AC_MSG_NOTICE([Check boundaries, adding -D_GLIBCXX_DEBUG])
AC_DEFINE([_GLIBCXX_DEBUG])
fi
if test "$cxx_exceptions" == true ; then
AC_MSG_NOTICE([Enabling c++ exceptions -D__PLUMED_HAS_EXCEPTIONS])
AC_DEFINE([__PLUMED_HAS_EXCEPTIONS])
fi
# this is necessary in many MPI implementations
# I leave it by default, since it seems harmless
AC_DEFINE([_REENTRANT])
#### Options for dynamic library to work properly ####
AC_SUBST(SOEXT)
AC_SUBST(LD)
AC_SUBST(LDSO)
# these are libraries that should be linked also to MD engines
AC_SUBST(STATIC_LIBS)
if test "$shared" == true ; then
case `(uname)` in
(Darwin)
AC_MSG_NOTICE([*** Special settings for dynamic libraries on OSX ***])
AC_MSG_NOTICE([Dynamic library extension is 'dylib'])
AC_MSG_NOTICE([LDSO needs special flags])
SOEXT=dylib
LDSO="$LDSO -undefined suppress -flat_namespace -dynamiclib"
;;
(Linux)
AC_MSG_NOTICE([*** Special settings for dynamic libraries on Linux ***])
AC_MSG_NOTICE([Dynamic library extension is 'so'])
AC_MSG_NOTICE([LDSO and LDFLAGS need special flags])
SOEXT=so
LDSO="$LDSO -shared"
LDFLAGS="$LDFLAGS -rdynamic"
;;
(*)
AC_MSG_NOTICE([*** Dynamic library only enabled on OSX and Linux ***])
esac
fi
# check linking of runtime library
if test -n "$SOEXT"
then
AC_MSG_NOTICE([Using LDSO='$LDSO'])
AC_MSG_NOTICE([Using LDFLAGS='$LDFLAGS'])
AC_MSG_CHECKING([whether LDSO can create dynamic libraries])
rm -f test.*
echo "void f(void){ return;}" > test.cpp
$CXX $CXXFLAGS $CPPFLAGS -c test.cpp 1>/dev/null 2>/dev/null
$LDSO $LDFLAGS test.o -o test.$SOEXT 1>/dev/null 2>/dev/null
if test -f test.$SOEXT
then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([yes])
AC_MSG_WARN([dynamic library will be disabled])
SOEXT=
fi
rm -f test.*
fi
#### Options for dynamic library to work properly ####
### Look for doxygen
AC_CHECK_PROG([doxygen],[doxygen],[found])
if test "$doxygen" == found
then
doxygen_version=`doxygen --version | awk 'BEGIN{FS="."}{if($1>1 || ($1==1 && $2>=8)) print "ok"}'`
if test "$doxygen_version" == ok
then
AC_MSG_NOTICE([Doxygen version is fine])
else
AC_MSG_WARN([Doxygen version is <1.8. You might have problems in generating manuals])
fi
AC_CHECK_PROG([dot],[dot],[found])
if test "$dot" != found
then
AC_MSG_WARN([You will not be able to see diagrams in the manual])
fi
fi
### Look for xxd
AC_CHECK_PROG([xxd],[xxd],[found])
if test "$xxd" != found
then
AC_MSG_ERROR([xxd should be installed for PLUMED to compile properly])
fi
#### This further tests are required to allow linking with non c++ compiler
AC_MSG_NOTICE([PLUMED seems to be configured properly!])
AC_MSG_NOTICE([**************************])
AC_MSG_NOTICE([I will now check if C++ objects can be linked by C/Fortran compilers])
AC_MSG_NOTICE([This is relevant if you want to use plumed patch --static on a non-C++ code])
for compiler in CC FC
do
rm -f test.* test-main.*
eval compexe=\$$compiler
if test -n "$compexe" ; then
case $compiler in
(CC)
name=C
cat << EOF > test-main.c
int main(int argc,char**argv){
return 0;
}
EOF
$CC -c test-main.c
;;
(FC)
name=FORTRAN
cat << EOF > test-main.f90
program main
integer i
end program main
EOF
$FC -c test-main.f90
;;
esac
cat << EOF > test.cpp
#include <iostream>
void f(void){
std::cout<<"ciao";return;
}
EOF
$CXX $CXXFLAGS -c test.cpp
# start search:
found=
for testlib in "" -lstdc++ -lc++ ; do
comment=
test -n "$testlib" && comment=" with library $testlib"
AC_MSG_CHECKING([whether $name can link a C++ object$comment])
$compexe $LDFLAGS $testlib $LIBS test.o test-main.o -o test.exe 1>/dev/null 2>/dev/null
if test -f test.exe
then
found=yes
AC_MSG_RESULT([yes])
LIBS="$testlib $LIBS"
break
else
AC_MSG_RESULT([no])
fi
done
if test -z "$found" ; then
AC_MSG_WARN([You might have problems linking $name programs.])
AC_MSG_WARN([Please add c++ library to LIBS - e.g. LIBS=-lstdc++])
fi
else
AC_MSG_NOTICE([$compiler compiler not configured])
fi
rm -f test.* test-main.*
done
if test "$prefix" == NONE
then
prefix=/usr/local
fi
AC_MSG_NOTICE([**** PLUMED will be installed using prefix $prefix])
AC_MSG_NOTICE([**** You can change this later setting PLUMED_PREFIX environment variable before installing])
AC_MSG_NOTICE([**** Executable will be named 'plumed'])
AC_MSG_NOTICE([**** To add a suffix to this name, set PLUMED_LIBSUFFIX environment variable before installing])
AC_SUBST(build_dir)
build_dir=`cd ../; pwd`
# This is to replace tags in Makefile.conf.in
# saving the result to Makefile.conf
AC_CONFIG_FILES([Makefile.conf sourceme.sh])
AC_OUTPUT
export PATH="@build_dir@/src/lib/:$PATH"
export DYLD_LIBRARY_PATH="@build_dir@/src/lib/:$DYLD_LIBRARY_PATH"
export PLUMED_KERNEL="@build_dir@/src/lib/libplumedKernel.@SOEXT@"
#! /bin/bash
rm -f sourceme.sh Makefile.conf
cd autoconf
./configure "${@}"
cp Makefile.conf ../
cp sourceme.sh ../
......@@ -8,7 +8,7 @@ all:
@echo "Updating ConfigInstall.cpp"
@sed "s/@SOEXT@/$(SOEXT)/g" Config.cpp.in | \
sed "s/@ISINSTALLED@/true/g" | \
../maketools/update-plumedroot.sh ConfigInstall.cpp
env prefix="${prefix}" ../maketools/update-plumedroot.sh ConfigInstall.cpp
$(MAKE) do-all
do-all: Config.o ConfigInstall.o compile_options.sh
......
......@@ -234,7 +234,7 @@ else
.PHONY: error
error:
@echo No configuration available
@echo First run ./configure.sh in the root directory
@echo First run ./configure in the root directory
endif
# this target is available anyway
......
......@@ -59,7 +59,7 @@ else
.PHONY: error
error:
@echo No configuration available
@echo First run ./configure.sh in the root directory
@echo First run ./configure in the root directory
endif
# this target is available anyway
......
......@@ -5,7 +5,14 @@ test -n "$1" || {
exit 1
}
PLUMED_PREFIX="${PLUMED_PREFIX:=/usr/local}"
# if environment variable "prefix" is set, use it.
# otherwise defaults to /usr/local
prefix="${prefix:=/usr/local}"
# if environment variable PLUMED_PREFIX is set,
# override the present prefix
PLUMED_PREFIX="${PLUMED_PREFIX:=$prefix}"
PLUMED_LIBSUFFIX="${PLUMED_LIBSUFFIX:=}"
test -n "$PLUMED_LIBSUFFIX" && PLUMED_LIBSUFFIX="-${PLUMED_LIBSUFFIX}"
PLUMED_ROOT="${PLUMED_PREFIX}/lib/plumed${PLUMED_LIBSUFFIX}/"
......
......@@ -41,7 +41,7 @@ else
.PHONY: error
error:
@echo No configuration available
@echo First run ./configure.sh in the root directory
@echo First run ./configure in the root directory
endif
# this target is available anyway
......
......@@ -4,21 +4,87 @@
\section CompilingPlumed Compiling PLUMED
PLUMED does not yet have any automatic configuration procedure and most of the
decisions should be taken by the user. As a first step configure with the command:
Since version 2.1, PLUMED can be configured using autoconf. Just type:
\verbatim
> ./configure.sh
> ./configure
\endverbatim
This is going to generate a Makefile.conf file and a sourceme.sh file.
In PLUMED 2.0 these files where pre-prepared and stored in the
directory configurations/. The new ones generated by ./configure
should be compatible with the old ones. In other words, if you find in trouble
with the new procedure, just put in place your old files. However,
it should be easy to enforce a similar setup on autoconf (by passing
the proper arguments on the command line) and we encourage this.
In case you have problems on your architecture, please
report to the mailing list.
You will have to choose among a set of available preconfigured files.
Choose the one closest to your machine, then edit the resulting
Makefile.conf file. Notable variables there:
- LIBS : these are the libraries needed when patching an MD code; typically only "-ldl" (needed to have functions for dynamic loading).
You can provide hints to the configure script. In particular,
you can state which compiler you wish to use, e.g. to use Intel compilers:
\verbatim
> ./configure CXX=icpc CC=icc
\endverbatim
You can also tune the compilation options
\verbatim
> ./configure CXXFLAGS=-O3
\endverbatim
In case you want an MPI build, just use the proper name of the MPI compiler.
\verbatim
> ./configure CXX=mpic++ CC=mpicc
\endverbatim
The configure will figure out that MPI library is available and instruct PLUMED
to use it.
In case you want to build with debug flags so as to do some checking you can use
\verbatim
> ./configure --enable-debug
\endverbatim
This will perform some extra check during execution (possibly slowing down PLUMED a bit)
and write full symbol table in the executable.
Other useful command line options for ./configure can be found typing
\verbatim
> ./configure --help
\endverbatim
The main goal of the automatic configure is to find libraries.
In case they are stored in unconventional places you might have to
suggest their location.
E.g. if your matheval libraries is in /opt/local (this is where MacPorts put it)
use
\verbatim
> ./configure LDFLAGS=-L/opt/local/lib CPPFLAGS=-I/opt/local/include
\endverbatim
Notice that PLUMED will first try to link a routine from say matheval
directly, and then try to add "-lmatheval" to the library. So, if
your matheval library is called /opt/local/lib/libmymatheval.so you can
link it with
\verbatim
> ./configure LDFLAGS=-L/opt/local/lib CPPFLAGS=-I/opt/local/include LIBS=-lmymatheval
\endverbatim
This rule is true for all the libraries, so that you will always be able to link
a specific version of a library by adding it to the LIBS variable.
Notice that PLUMED needs blas and lapack. The configure script
is first looking for them in the standard path, then with option "-lblas" and
"-llapack", respectively. Thus, if you want to use a specific version of them
you can just make them available to configure with
\verbatim
> ./configure LDFLAGS=-L/path/to/blas/lib LIBS=-lnameoflib
\endverbatim
The script is also finding out if function names have the final underscore added,
so this should be completely transparent to the user.
As a final resort, you may also edit the resulting Makefile.conf file.
Notable variables there:
- DYNAMIC_LIB : these are the libraries needed to compile the PLUMED
library (e.g. -L/path/to/matheval -lmatheval etc). Notice that for the
PLUMED shared library to be compiled properly these should be dynamic
libraries. Also notice that PLUMED requires BLAS and LAPACK library;
see \ref BlasAndLapack for further info.
see \ref BlasAndLapack for further info. Notice that the variables
that you supply with `configure LIBS=something` will end up in this
variable. This is a bit misleading but is required to keep the configuration
files compatible with PLUMED 2.0.
- LIBS : these are the libraries needed when patching an MD code; typically only "-ldl" (needed to have functions for dynamic loading).
- CPPFLAGS : add here definition needed to enable specific optional functions;
e.g. use -D__PLUMED_HAS_MATHEVAL to enable matheval library
- SOEXT : this gives the extension for shared libraries in your system, typically
......@@ -29,7 +95,7 @@ Also notice that a new file sourceme.sh
appears in the main PLUMED directory.
This file should be "sourced" (presently only working for bash shell)
if you want to use PLUMED *without installin it* (i.e. from the compilation
directory. It is a good idea to source it now:
directory). It is a good idea to source it now:
\verbatim
> source sourceme.sh
\endverbatim
......@@ -123,7 +189,15 @@ the environment variable PLUMED_PREFIX, then type "make install"
> export PLUMED_PREFIX=$HOME/opt
> make install
\endverbatim
If PLUMED_PREFIX is not set, it will be assumed to be /usr/local.
If PLUMED_PREFIX is not set, it will be assumed to be
the one set when configuring with autoconf. E.g. you could
have used
\verbatim
> ./configure --prefix=$HOME/opt
> make
> make install
\endverbatim
If not set, it defaults to /usr/local.
The install command should be executed with root permissions (e.g. "sudo make install")
in case you want to install PLUMED on a system directory.
An almost full copy of the compilation directory will
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment