From 1dedccb8ea8dbcbbd49a52ee75feae81a9d14e7c Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Thu, 2 Jul 2015 08:15:17 +0200
Subject: [PATCH] Allow space in build directory

Now plumed should work if built on a directory which has a space in the path.
Notice that install directory should still not contain spaces.
This is because of some difficulties in making the
src/lib/Makefile rules compatible with names with spaces.

Addresses #157
---
 patches/patch.sh        | 2 +-
 scripts/mklib.sh        | 2 +-
 scripts/newcv.sh        | 2 +-
 scripts/patch.sh        | 2 +-
 src/config/Makefile     | 2 +-
 src/core/CLToolMain.cpp | 4 ++--
 src/lib/Makefile        | 2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/patches/patch.sh b/patches/patch.sh
index 775bd6d5d..dafd2525f 100755
--- a/patches/patch.sh
+++ b/patches/patch.sh
@@ -259,7 +259,7 @@ case "$action" in
     fi
 
     echo ""
-    if grep -q "D__PLUMED_MPI=1" $PLUMED_ROOT/src/config/compile_options.sh ; then
+    if grep -q "D__PLUMED_MPI=1" "$PLUMED_ROOT"/src/config/compile_options.sh ; then
       echo "PLUMED is compiled with MPI support so you can configure $engine with MPI" 
     else
       echo "PLUMED is compiled WITHOUT MPI support so you CANNOT configure $engine with MPI"
diff --git a/scripts/mklib.sh b/scripts/mklib.sh
index 742aa3765..2612a488a 100755
--- a/scripts/mklib.sh
+++ b/scripts/mklib.sh
@@ -1,6 +1,6 @@
 #! /bin/bash
 
-source $PLUMED_ROOT/src/config/compile_options.sh
+source "$PLUMED_ROOT"/src/config/compile_options.sh
 
 if [ "$1" = --description ] ; then
   echo "compile a .cpp file into a shared library"
diff --git a/scripts/newcv.sh b/scripts/newcv.sh
index d0c99d070..b3b573739 100755
--- a/scripts/newcv.sh
+++ b/scripts/newcv.sh
@@ -17,5 +17,5 @@ directive=$1
 classname=$2
 
 sed "s/TEMPLATE/$directive/g
-     s/Template/$classname/g" $PLUMED_ROOT/src/colvar/Template.cpp > ${classname}.cpp
+     s/Template/$classname/g" "$PLUMED_ROOT"/src/colvar/Template.cpp > ${classname}.cpp
 
diff --git a/scripts/patch.sh b/scripts/patch.sh
index b3b00e052..d9bfe5d30 100755
--- a/scripts/patch.sh
+++ b/scripts/patch.sh
@@ -1,4 +1,4 @@
 #! /bin/bash
 
-${PLUMED_ROOT}/patches/patch.sh "$@"
+"${PLUMED_ROOT}"/patches/patch.sh "$@"
 
diff --git a/src/config/Makefile b/src/config/Makefile
index a4b9d0dbd..fae0e2748 100644
--- a/src/config/Makefile
+++ b/src/config/Makefile
@@ -51,7 +51,7 @@ Makefile.conf.xxd: ../../Makefile.conf
 # file to import compilation options inside a bash script
 compile_options.sh:
 	@echo Building compile_options.sh, a sourceable bash script with some compilation options
-	@echo "compile='"$(CXX) -c -I'$$PLUMED_ROOT'/src $(CPPFLAGS) $(CXXFLAGS) -o"'" > $@
+	@echo "compile='"$(CXX) -c -I'"$$PLUMED_ROOT"'/src $(CPPFLAGS) $(CXXFLAGS) -o"'" > $@
 	@echo "link='"$(LDSO) -o"'" >> $@
 	@echo "soext='"$(SOEXT)"'" >> $@
 
diff --git a/src/core/CLToolMain.cpp b/src/core/CLToolMain.cpp
index a77e2b1cc..891920ea7 100644
--- a/src/core/CLToolMain.cpp
+++ b/src/core/CLToolMain.cpp
@@ -210,7 +210,7 @@ int CLToolMain::run(int argc, char **argv,FILE*in,FILE*out,Communicator& pc){
       fprintf(out,"  plumed %s\n", manual.c_str());
     }
     for(unsigned j=0;j<availableShell.size();++j){
-      string cmd="env PLUMED_ROOT="+root+" "+root+"/scripts/"+availableShell[j]+".sh --description";
+      string cmd="env PLUMED_ROOT=\""+root+"\" \""+root+"/scripts/"+availableShell[j]+".sh\" --description";
       FILE *fp=popen(cmd.c_str(),"r");
       string line,manual;
       while(Tools::getline(fp,line))manual+=line;
@@ -241,7 +241,7 @@ int CLToolMain::run(int argc, char **argv,FILE*in,FILE*out,Communicator& pc){
   if(find(availableShell.begin(),availableShell.end(),command)!=availableShell.end()){
     plumed_massert(in==stdin,"shell tools can only work on stdin");
     plumed_massert(out==stdout,"shell tools can only work on stdin");
-    string cmd="env PLUMED_ROOT="+root+" "+root+"/scripts/"+command+".sh";
+    string cmd="env PLUMED_ROOT=\""+root+"\" \""+root+"/scripts/"+command+".sh\"";
     for(int j=i+1;j<argc;j++) cmd+=string(" ")+argv[j];
     system(cmd.c_str());
     return 0;
diff --git a/src/lib/Makefile b/src/lib/Makefile
index eaf552227..6ae35c704 100644
--- a/src/lib/Makefile
+++ b/src/lib/Makefile
@@ -206,7 +206,7 @@ $(PLUMED_MAIN_STATIC): $(OBJ_MAIN) $(OBJ_KERNEL) $(OBJ_WRAPPER)
 	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS) $(DYNAMIC_LIBS)
 	
 $(PLUMED_MAIN_SHARED): $(OBJ_MAIN) $(PLUMED_SHARED_OBJ)
-	$(LD) $(LDFLAGS) $(OBJ_MAIN) $(realpath $(PLUMED_SHARED_OBJ)) -o $@ $(LIBS)
+	$(LD) $(LDFLAGS) $(OBJ_MAIN) "$(realpath $(PLUMED_SHARED_OBJ))" -o $@ $(LIBS)
 
 $(PLUMED_MAIN_RUNTIME): $(OBJ_MAIN) $(OBJ_DYNAMIC_WRAPPER)
 	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS)
-- 
GitLab