From dfe0657e3b7d2b00b18f7cc09ae621c4f0c65b62 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi Date: Mon, 13 May 2024 15:11:54 +0200 Subject: [PATCH] Force rebuild of library when using mklib directly With this commit: - when using plumed mklib the library is always built, even if already present - when using LOAD FILE=file.cpp, the library is only built if missing I think this would avoid version mistake in users calling plumed mklib directly. In addition, it makes plumed mklib work as in v2.9. The only exception is when called via LOAD, where we force the use of a versioned name --- scripts/mklib.sh | 17 ++++++++++++++--- src/core/PlumedMain.cpp | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/mklib.sh b/scripts/mklib.sh index b3e2ffcd7a..de3454949c 100755 --- a/scripts/mklib.sh +++ b/scripts/mklib.sh @@ -12,7 +12,7 @@ if [ "$1" = --help ] ; then fi if [ "$1" = --options ] ; then - echo "--description --options --help -o" + echo "--description --options --help -o -n" exit 0 fi @@ -27,6 +27,7 @@ source "$PLUMED_ROOT"/src/config/compile_options.sh prefix="" lib="" +no_clobber="" files=() # empty array for opt do @@ -37,6 +38,8 @@ do prefix="--out=";; (--out=*) lib="${prefixopt#--out=}";; + (-n) + no_clobber=yes;; (-*) echo "ERROR: Unknown option $opt. Use --help for help." exit 1 ;; @@ -66,6 +69,10 @@ do fi done +if test -z "$no_clobber" ; then + recompile=yes +fi + if test $recompile = no ; then echo "$lib is already up to date" exit 0 @@ -148,5 +155,9 @@ fi eval "$link_command" "$PLUMED_MKLIB_LDFLAGS" $objs -o "$tmpdir/$lib" -# || true is necessary with recent coreutils -mv -n "$tmpdir/$lib" $lib || true +if test -n "$no_clobber" ; then + # || true is necessary with recent coreutils + mv -n "$tmpdir/$lib" $lib || true +else + mv "$tmpdir/$lib" $lib +fi diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index c16f7b1bb8..b34a2ae78a 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -1261,7 +1261,7 @@ void PlumedMain::load(const std::string& fileName) { // full path command, including environment setup // this will work even if plumed is not in the execution path or if it has been // installed with a name different from "plumed" - std::string cmd=config::getEnvCommand()+" \""+config::getPlumedRoot()+"\"/scripts/mklib.sh -o "+libName+" "+fileName; + std::string cmd=config::getEnvCommand()+" \""+config::getPlumedRoot()+"\"/scripts/mklib.sh -n -o "+libName+" "+fileName; if(std::getenv("PLUMED_LOAD_ACTION_DEBUG")) log<<"Executing: "<