Skip to content

Commit

Permalink
Added possibility to plumed mklib multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBussi committed Oct 13, 2023
1 parent fff0fa5 commit db70ebf
Showing 1 changed file with 49 additions and 28 deletions.
77 changes: 49 additions & 28 deletions scripts/mklib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,66 @@ fi

source "$PLUMED_ROOT"/src/config/compile_options.sh

if [ $# != 1 ] || [[ "$1" != *.cpp ]] ;
if [ $# == 0 ]
then
echo "ERROR"
echo "type 'plumed mklib file.cpp'"
echo "type 'plumed mklib file1.cpp [file2.cpp etc]'"
exit 1
fi

lib="${1%%.cpp}".$soext
rm -f "$lib"

file="$1"
obj="${file%%.cpp}".o
lib="${file%%.cpp}".$soext
objs=""

if [ ! -f "$file" ]
then
echo "ERROR: I cannot find file $file"
exit 1
fi
#adding a simple tmpfile, to preprocess "in place" the input file,
#this assumes the user has write permission in the current directory
#which should be true since we are going to compile and output something here
tmpfile=$(mktemp ${file%.cpp}.XXXXXX.cpp)
cp "${file}" "${tmpfile}"

if grep -q '^#include "\(bias\|colvar\|function\|sasa\|vatom\)\/ActionRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy ActionRegister.h include path, please use <<#include "core/ActionRegister.h">>'
sed -i.bak 's%^#include ".*/ActionRegister.h"%#include "core/ActionRegister.h"%g' "${tmpfile}"
fi
for file
do

if grep -q '^#include "\(cltools\)\/CLToolRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy CLToolRegister.h include path, please use <<#include "core/CLToolRegister.h">>'
sed -i.bak 's%^#include ".*/CLToolRegister.h"%#include "core/CLToolRegister.h"%g' "${tmpfile}"
fi
if [[ "$file" != *.cpp ]] ;
then
echo "ERROR"
echo "type 'plumed mklib file1.cpp [file2.cpp etc]'"
exit 1
fi

obj="${file%%.cpp}".o

if [ ! -f "$file" ]
then
echo "ERROR: I cannot find file $file"
exit 1
fi
#adding a simple tmpfile, to preprocess "in place" the input file,
#this assumes the user has write permission in the current directory
#which should be true since we are going to compile and output something here
tmpfile=$(mktemp ${file%.cpp}.XXXXXX).cpp
cp "${file}" "${tmpfile}"

if grep -q '^#include "\(bias\|colvar\|function\|sasa\|vatom\)\/ActionRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy ActionRegister.h include path, please use <<#include "core/ActionRegister.h">>'
sed -i.bak 's%^#include ".*/ActionRegister.h"%#include "core/ActionRegister.h"%g' "${tmpfile}"
fi

if grep -q '^#include "\(cltools\)\/CLToolRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy CLToolRegister.h include path, please use <<#include "core/CLToolRegister.h">>'
sed -i.bak 's%^#include ".*/CLToolRegister.h"%#include "core/CLToolRegister.h"%g' "${tmpfile}"
fi

rm -f "$obj"

eval "$compile" "$PLUMED_MKLIB_CFLAGS" "$obj" "$tmpfile" || {
echo "ERROR: compiling $file"
exit 1
}

rm -f ${tmpfile} ${tmpfile}.bak
objs="$objs $obj"

rm -f "$obj" "$lib"
done

if test "$PLUMED_IS_INSTALLED" = yes ; then
eval "$compile" "$obj" "$tmpfile" && eval "$link_installed" "$lib" "$obj"
eval "$link_installed" "$PLUMED_MKLIB_LDFLAGS" "$lib" "$objs"
else
eval "$compile" "$obj" "$tmpfile" && eval "$link_uninstalled" "$lib" "$obj"
eval "$link_uninstalled" "$PLUMED_MKLIB_LDFLAGS" "$lib" "$objs"
fi

rm -f ${tmpfile} ${tmpfile}.bak

0 comments on commit db70ebf

Please sign in to comment.