From: Arnaud Giersch Date: Thu, 14 Nov 2013 12:24:06 +0000 (+0100) Subject: Deal with empty args. X-Git-Tag: v3_11_beta~309 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d12267992aceee77113c7cef4251b30ee1c9ea19 Deal with empty args. --- diff --git a/src/smpi/smpicc.in b/src/smpi/smpicc.in index 5e9eec4271..5c465c70d4 100755 --- a/src/smpi/smpicc.in +++ b/src/smpi/smpicc.in @@ -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) +"$@" diff --git a/src/smpi/smpif90.in b/src/smpi/smpif90.in index 60d8d59b9a..25c88b3d89 100644 --- a/src/smpi/smpif90.in +++ b/src/smpi/smpif90.in @@ -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) +"$@" diff --git a/src/smpi/smpiff.in b/src/smpi/smpiff.in index bcb376fa78..ab01b6d37a 100644 --- a/src/smpi/smpiff.in +++ b/src/smpi/smpiff.in @@ -29,7 +29,7 @@ while [ $# -gt 0 ]; do ;; esac done -list_add ARGS "${LINKARGS}" +list_add_not_empty ARGS "${LINKARGS}" build () { local SRCFILE diff --git a/src/smpi/smpitools.sh b/src/smpi/smpitools.sh index 835cd595d0..17eb6f4acf 100644 --- a/src/smpi/smpitools.sh +++ b/src/smpi/smpitools.sh @@ -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)