Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deal with empty args.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 14 Nov 2013 12:24:06 +0000 (13:24 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 14 Nov 2013 14:31:07 +0000 (15:31 +0100)
src/smpi/smpicc.in
src/smpi/smpif90.in
src/smpi/smpiff.in
src/smpi/smpitools.sh

index 5e9eec4..5c465c7 100755 (executable)
@@ -17,7 +17,8 @@ else
     list_add LINKARGS "@libdir@\libsimgrid.dll"
 fi
 
-list_set CMDLINE
+list_set CMDLINE "${CC}"
+list_add_not_empty CMDLINE "${CFLAGS}"
 while [ $# -gt 0 ]; do
     ARG="$1"
     shift
@@ -40,7 +41,9 @@ while [ $# -gt 0 ]; do
   esac
 done
 
-list_set CMDLINE "${CFLAGS}" "${CMDLINE}" ${INCLUDEARGS} ${CMAKE_LINKARGS} "${LINKARGS}"
-eval $(list_get CMDLINE)
+list_add_not_empty CMDLINE ${INCLUDEARGS}
+list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
+list_add_not_empty CMDLINE "${LINKARGS}"
 
-"${CC}" "$@"
+eval $(list_get CMDLINE)
+"$@"
index 60d8d59..25c88b3 100644 (file)
@@ -18,7 +18,8 @@ cleanup () {
 }
 trap 'cleanup' EXIT
 
-list_set CMDLINE
+list_set CMDLINE "${F90}"
+list_add_not_empty CMDLINE "${FFLAGS}"
 while [ $# -gt 0 ]; do
     ARG="$1"
     shift
@@ -42,7 +43,9 @@ while [ $# -gt 0 ]; do
     esac
 done
 
-list_set CMDLINE "${FFLAGS}" "${CMDLINE}" ${INCLUDEARGS} ${CMAKE_LINKARGS} "${LINKARGS}"
-eval $(list_get CMDLINE)
+list_add_not_empty CMDLINE ${INCLUDEARGS}
+list_add_not_empty CMDLINE ${CMAKE_LINKARGS}
+list_add_not_empty CMDLINE "${LINKARGS}"
 
-"${F90}" "$@"
+eval $(list_get CMDLINE)
+"$@"
index bcb376f..ab01b6d 100644 (file)
@@ -29,7 +29,7 @@ while [ $# -gt 0 ]; do
             ;;
     esac
 done
-list_add ARGS "${LINKARGS}"
+list_add_not_empty ARGS "${LINKARGS}"
 
 build () {
     local SRCFILE
index 835cd59..17eb6f4 100644 (file)
@@ -27,18 +27,28 @@ mymktemp () {
 # Add a word to the end of a list (words separated by LISTSEP)
 # $1: list, $2...: words to add
 list_add () {
-    local list content
+    local list content newcontent
     list="$1"
     shift
-    eval content=\"\${$list}\"
-    IFS="$LISTSEP"
-    if [ -z "$content" ]; then
-        content="$*"
-    else
-        content="$content${LISTSEP}$*"
+    if [ $# -gt 0 ]; then
+        eval content=\"\${$list}\"
+        IFS="$LISTSEP"
+        newcontent="$*"
+        IFS="$SAVEIFS"
+        if [ -z "$content" ]; then
+            content="$newcontent"
+        else
+            content="$content${LISTSEP}$newcontent"
+        fi
+        eval $list=\"\${content}\"
+    fi
+}
+
+# Like list_add, but only if first word to add ($2) is not empty
+list_add_not_empty () {
+    if [ -n "$2" ]; then
+        list_add "$@"
     fi
-    IFS="$SAVEIFS"
-    eval $list=\"\${content}\"
 }
 
 # Set contents of a list (words separated by LISTSEP)