diff --git a/Makefile b/Makefile index 135774a107f6b275cf6c75b60905a41afc497c65..1e968b1ddceced52f87e4e58582fd47c27d0d302 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,12 @@ all: lib: $(MAKE) -C src +install: + $(MAKE) -C src install + +uninstall: + $(MAKE) -C src uninstall + $(SRCDIRS): $(MAKE) -C $@ diff --git a/configure.sh b/configure.sh index c6eb9929374fa37261db8acf646415e020b6a267..f25214fe954f94cba9968361ce3d04fee943f7b3 100755 --- a/configure.sh +++ b/configure.sh @@ -34,7 +34,7 @@ case "$conf" in SOEXT=so esac -echo 'export PATH="$PATH:'"$PWD"'/src/lib/"' >> sourceme.sh +echo 'export PATH="'"$PWD"'/src/lib/:$PATH"' >> sourceme.sh # this is just for mac: echo 'export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:'"$PWD"'/src/lib/"' >> sourceme.sh @@ -42,3 +42,8 @@ cat << EOF >> sourceme.sh export PLUMED_KERNEL="$PWD/src/lib/libplumedKernel.$SOEXT" EOF +echo "PLUMED will be installed using prefix $HOME/opt" +echo "If you wish to change this, set PLUMED_PREFIX environment variable before compiling" +echo "Executable will be named 'plumed'" +echo "To add a suffix to this name, set PLUMED_LIBSUFFIX environment variable before compiling" + diff --git a/src/Makefile b/src/Makefile index 1aab074ef5e6fd118f15de68c5d88fd1e1d27f56..ef179b10dff7f839e196b1fa860b9ad1fec1be84 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ -.PHONY: all clean lib +.PHONY: all clean lib install uninstall # by default we compile the lib directory, which in turn requests all the needeed modules all: lib @@ -7,6 +7,12 @@ all: lib lib: $(MAKE) -C lib +install: + $(MAKE) -C lib install + +uninstall: + $(MAKE) -C lib uninstall + # list of all the contained directories which can be cleaned SUBDIRS =$(subst /Makefile,,$(wildcard */Makefile)) SUBDIRSCLEAN=$(addsuffix .clean,$(SUBDIRS)) diff --git a/src/config/.gitignore b/src/config/.gitignore index 7a4048d2c65675432a373c390d3e23edfeefa345..d5084269337ccfe3ff6748c69e0892e8ba3d172e 100644 --- a/src/config/.gitignore +++ b/src/config/.gitignore @@ -1,2 +1,4 @@ /compile_options.sh /Config.cpp +/ConfigInstall.cpp +/install* diff --git a/src/config/Makefile b/src/config/Makefile index 63cb869d1ccc698a6f62037738648ebc34ae352f..adf2019ff02501826b86af0a09342ef20f64581c 100644 --- a/src/config/Makefile +++ b/src/config/Makefile @@ -4,7 +4,19 @@ # default target .PHONY: all -all: Config.o compile_options.sh +all: + @echo "Updating ConfigInstall.cpp" + @sed "s/@SOEXT@/$(SOEXT)/g" Config.cpp.in | \ + ../maketools/update-plumedroot.sh ConfigInstall.cpp + $(MAKE) do-all + +do-all: Config.o ConfigInstall.o compile_options.sh + make ConfigInstall.o + +ConfigInstall.cpp: + @echo "Updating ConfigInstall.cpp" + @sed "s/@SOEXT@/$(SOEXT)/g" Config.cpp.in | \ + ../maketools/update-plumedroot.sh ConfigInstall.cpp # file to import compilation options inside c++ Config.cpp: Config.cpp.in Config.h @@ -17,6 +29,7 @@ links: Config.o: Config.cpp Makefile.conf.xxd +ConfigInstall.o: ConfigInstall.cpp Makefile.conf.xxd Makefile.conf.xxd: ../../Makefile.conf cat ../../Makefile.conf | xxd -i > Makefile.conf.xxd @@ -32,6 +45,7 @@ compile_options.sh: clean: rm -f Config.cpp compile_options.sh Makefile_conf rm -fr deps + rm -f Config.cpp ConfigInstall.cpp compile_options.sh install.conf rm -f $(CLEANLIST) # generic makefile rules diff --git a/src/lib/Makefile b/src/lib/Makefile index 1be92a2f06e376d5a7505a54842ba6893206239c..1f4f238fa1b46fa927741ee972e825100ef97c88 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -8,6 +8,9 @@ DIRS=$(sort ../config ../wrapper ../main $(KERNEL_MODULES)) # include the machine dependent configuration -include ../../Makefile.conf +# include installation info +-include ../config/install.conf + # if machine dependent configuration has been found: ifdef GCCDEP @@ -23,7 +26,7 @@ SRC_MAIN=../main/main.cpp # source for plumed kernel # everything else -SRC_KERNEL=$(shell for dir in $(KERNEL_MODULES) ; do ls $$dir/*.cpp 2>/dev/null ; ls $$dir/*.c 2>/dev/null ; done) ../config/Config.o +SRC_KERNEL=$(shell for dir in $(KERNEL_MODULES) ; do ls $$dir/*.cpp 2>/dev/null ; ls $$dir/*.c 2>/dev/null ; done) ../config/Config$(PLUMED_INSTALL).o # corresponding objects: OBJ_WRAPPER=../wrapper/PlumedStatic.o @@ -34,15 +37,16 @@ OBJ_KERNEL=$(XXX:.c=.o) ALL_OBJ=$(OBJ_KERNEL) $(OBJ_WRAPPER) $(OBJ_DYNAMIC_WRAPPER) $(OBJ_MAIN) # plumed kernel -PLUMED_KERNEL=libplumedKernel.$(SOEXT) +PLUMED_KERNEL=$(PLUMED_LIBDIR)libplumedKernel.$(SOEXT) # plumed library (kernel + wrapper) -PLUMED_SHARED_OBJ=libplumed.$(SOEXT) +PLUMED_SHARED_OBJ=$(PLUMED_LIBDIR)libplumed.$(SOEXT) # plumed main exec -PLUMED_MAIN_STATIC=plumed -PLUMED_MAIN_SHARED=plumed-shared -PLUMED_MAIN_RUNTIME=plumed-runtime +PLUMED_MAIN_STATIC=$(PLUMED_LIBDIR)plumed +PLUMED_MAIN_SHARED=$(PLUMED_LIBDIR)plumed-shared +PLUMED_MAIN_RUNTIME=$(PLUMED_LIBDIR)plumed-runtime +PLUMED_MAIN_PATCH=$(PLUMED_LIBDIR)plumed-patch .PHONY: all dirs $(DIRS) all-static ifdef SOEXT @@ -58,6 +62,51 @@ all-static: $(MAKE) lib-static +install: + cd ../config ; $(MAKE) +# two steps to be sure that ../config/install.conf is up to date + $(MAKE) install-do + +install-do: + $(MAKE) uninstall + mkdir -p $(PLUMED_INSTALL_PREFIX)/bin + mkdir -p $(PLUMED_INSTALL_ROOT)/src/lib + mkdir -p $(PLUMED_INSTALL_PREFIX)/include/plumed$(PLUMED_INSTALL_LIBSUFFIX) +# rebuild libraries and main using new target dir + $(MAKE) PLUMED_LIBDIR=$(PLUMED_INSTALL_ROOT)/src/lib/ PLUMED_INSTALL=Install all +# copy .h, .cpp .o compile_options.sh and documentation: + cd ../../ ; tar cf - patches scripts src/*/*.h src/*/*.cpp src/*/*.o src/config/compile_options.sh *-doc | tar xf - -C $(PLUMED_INSTALL_ROOT)/ +# also copy .h files into include/ dir + cd ../../src ; tar cf - */*.h $$(find . -type l) | tar xf - -C $(PLUMED_INSTALL_PREFIX)/include/plumed$(PLUMED_INSTALL_LIBSUFFIX)/ +# copy inc files changing the path + for file in Plumed.inc* Plumed.cmake* ; do sed "s| $(realpath ../../)| $(PLUMED_INSTALL_ROOT)/|g" $$file > $(PLUMED_INSTALL_ROOT)/src/lib/$$file ; done +# install links + ln -s $(PLUMED_INSTALL_ROOT)/src/lib/plumed $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX) + ln -s $(PLUMED_INSTALL_ROOT)/src/lib/plumed-patch $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX)-patch +ifdef SOEXT + ln -s $(PLUMED_INSTALL_ROOT)/src/lib/libplumed.$(SOEXT) $(PLUMED_INSTALL_PREFIX)/lib/libplumed$(PLUMED_INSTALL_LIBSUFFIX).$(SOEXT) + ln -s $(PLUMED_INSTALL_ROOT)/src/lib/libplumedKernel.$(SOEXT) $(PLUMED_INSTALL_PREFIX)/lib/libplumed$(PLUMED_INSTALL_LIBSUFFIX)Kernel.$(SOEXT) +endif + @echo "To uninstall, remove the following files and directories:" + @echo $(PLUMED_INSTALL_ROOT) + @echo $(PLUMED_INSTALL_PREFIX)/include/plumed$(PLUMED_INSTALL_LIBSUFFIX) + @echo $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX) + @echo $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX)-patch +ifdef SOEXT + @echo $(PLUMED_INSTALL_PREFIX)/lib/libplumed$(PLUMED_INSTALL_LIBSUFFIX).$(SOEXT) + @echo $(PLUMED_INSTALL_PREFIX)/lib/libplumed$(PLUMED_INSTALL_LIBSUFFIX)Kernel.$(SOEXT) +endif + +uninstall: + rm -fr $(PLUMED_INSTALL_ROOT) + rm -fr $(PLUMED_INSTALL_PREFIX)/include/plumed$(PLUMED_INSTALL_LIBSUFFIX) + rm -f $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX) + rm -f $(PLUMED_INSTALL_PREFIX)/bin/plumed$(PLUMED_INSTALL_LIBSUFFIX)-patch +ifdef SOEXT + rm -f $(PLUMED_INSTALL_PREFIX)/lib/libplumed$(PLUMED_INSTALL_LIBSUFFIX).$(SOEXT) + rm -f $(PLUMED_INSTALL_PREFIX)/lib/libplumed$(PLUMED_INSTALL_LIBSUFFIX)Kernel.$(SOEXT) +endif + dirs: $(DIRS) $(DIRS): @@ -69,18 +118,18 @@ $(DIRS): lib: lib-static lib-shared -lib-static: $(PLUMED_MAIN_STATIC) $(OBJ_WRAPPER) Plumed.inc.static Plumed.cmake.static plumed-patch +lib-static: $(PLUMED_MAIN_STATIC) $(OBJ_WRAPPER) Plumed.inc.static Plumed.cmake.static $(PLUMED_MAIN_PATCH) lib-shared: $(PLUMED_KERNEL) $(PLUMED_SHARED_OBJ) $(PLUMED_MAIN_SHARED) $(PLUMED_MAIN_RUNTIME) \ Plumed.inc Plumed.inc.runtime Plumed.inc.shared \ Plumed.cmake Plumed.cmake.runtime Plumed.cmake.shared -plumed-patch: - @echo "#! /bin/bash" > plumed-patch - @echo "echo 'NOTE: shell only version of path, useful for cross compiling'" >> plumed-patch - @echo "export PLUMED_ROOT=\"$(realpath ../../)\"" >> plumed-patch - @echo "source \"$(realpath ../../scripts/patch.sh)\"" >> plumed-patch - chmod a+x plumed-patch +$(PLUMED_MAIN_PATCH): + @echo "#! /bin/bash" > $(PLUMED_MAIN_PATCH) + @echo "echo 'NOTE: shell only version of path, useful for cross compiling'" >> $(PLUMED_MAIN_PATCH) + @echo "export PLUMED_ROOT=\"$(realpath $(PLUMED_LIBDIR)../../)\"" >> $(PLUMED_MAIN_PATCH) + @echo "source \"\$$PLUMED_ROOT\"/scripts/patch.sh" >> $(PLUMED_MAIN_PATCH) + chmod a+x $(PLUMED_MAIN_PATCH) $(PLUMED_KERNEL):$(OBJ_KERNEL) $(LDSO) -o $@ $^ $(DYNAMIC_LIBS) diff --git a/src/maketools/update-plumedroot.sh b/src/maketools/update-plumedroot.sh new file mode 100755 index 0000000000000000000000000000000000000000..ee28d12b49b908c4bdc70ff1902db7b58cae36fa --- /dev/null +++ b/src/maketools/update-plumedroot.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +test -n "$1" || { + echo "Usage: $0 outfile" + exit 1 +} + +PLUMED_PREFIX="${PLUMED_PREFIX:=$HOME/opt}" +PLUMED_LIBSUFFIX="${PLUMED_LIBSUFFIX:=}" +test -n "$PLUMED_LIBSUFFIX" && PLUMED_LIBSUFFIX="-${PLUMED_LIBSUFFIX}" +PLUMED_ROOT="${PLUMED_PREFIX}/lib/plumed${PLUMED_LIBSUFFIX}/" + +{ +echo "PLUMED_INSTALL_ROOT=${PLUMED_ROOT}" +echo "PLUMED_INSTALL_PREFIX=${PLUMED_PREFIX}" +echo "PLUMED_INSTALL_LIBSUFFIX=${PLUMED_LIBSUFFIX}" +} > install.conf + +sed "s|@PLUMED_ROOT@|${PLUMED_ROOT}|g" > $1~ + +cmp -s $1~ $1 || cp $1~ $1 +rm $1~ + + +