From b01c7774929288496e8931bfeea66f8afe505c0d Mon Sep 17 00:00:00 2001
From: Markus Blatt <markus@dr-blatt.de>
Date: Wed, 29 Jan 2014 13:27:56 +0100
Subject: [PATCH] [dunecontrol,bugfix] Fixes issues with posix sed.

---
 bin/dunecontrol            | 42 +++++++++++++++++++++++---------------
 lib/dunecommonam2cmake.lib |  5 ++---
 lib/dunemodules.lib        |  2 +-
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/bin/dunecontrol b/bin/dunecontrol
index 21cd84923..efefe8c06 100755
--- a/bin/dunecontrol
+++ b/bin/dunecontrol
@@ -7,7 +7,7 @@ set -e
 ### check for environment variables
 ###
 
-if test -z $MAKE; then
+if test -z "$MAKE"; then
   MAKE=make
 fi
 
@@ -210,11 +210,14 @@ load_opts() {
 space=" "
 tab="	"
 BLANK="$space$tab"
-NOBLANK="^$space^$tab"
+NOBLANK="^$space$tab"
 
-if test -z $GREP; then
+if test -z "$GREP"; then
   GREP=grep
 fi
+if test -z "$SED"; then
+  SED=sed
+fi
 # Uses the current compiler to extract information about the
 # multiarch triplets and sets the export variable MULTIARCH_LIBDIR
 # according to it.
@@ -226,11 +229,11 @@ extract_multiarch(){
   fi
   if test "x$USE_CMAKE" = "xyes"; then
     load_opts "cmake"
-    my_cxx_compiler=`echo $CMAKE_FLAGS | $GREP CXX | sed "s/.*CXX=[\"']\?\([$NOBLANK^'^\"]*\)[\"']\?.*/\1/"`
+    my_cxx_compiler=`echo $CMAKE_FLAGS | $GREP CXX | $SED "s/.*CXX=[\"']\?\([$BLANK'\"]*\)[\"']\?.*/\1/"`
   fi
   if test "x$my_cxx_compiler" == "x"; then
     load_opts "configure"
-    my_cxx_compiler=`echo $CONFIGURE_FLAGS | $GREP CXX| sed "s/.*CXX=[\"']\?\([$NOBLANK^'^\"]*\)[\"']\?.*/\1/"`
+    my_cxx_compiler=`echo $CONFIGURE_FLAGS | $GREP CXX| $SED "s/.*CXX=[\"']\?\([^$BLANK'\"]*\)[\"']\?.*/\1/"`
   fi
   if test "x$my_cxx_compiler" == "x"; then
     set +e #error in the multiarch detection should not be fatal.
@@ -243,7 +246,7 @@ extract_multiarch(){
   fi
   multiarch=$($my_cxx_compiler --print-multiarch 2>/dev/null)
   if test $? -gt 0; then
-    multiarch=$($my_cxx_compiler -v 2>&1| $GREP target | sed "s/.*target=\([a-z0-9_-]\+\)/\1/")
+    multiarch=$($my_cxx_compiler -v 2>&1| $GREP target | $SED "s/.*target=\([a-z0-9_-]*\)/\1/")
   fi
   set -e # set to old value.
   export MULTIARCH_LIBDIR="lib/$multiarch"
@@ -296,7 +299,7 @@ check_commands() {
 is_command() {
 eval '
 case "$1" in
-  '`echo $COMMANDS | sed -e 's/ / | /g'`')
+  '`echo $COMMANDS | $SED -e 's/ / | /g'`')
     return 0
     ;;
   *)
@@ -444,7 +447,7 @@ run_default_vcsetup() {
 
       if [ -f .git ] ; then
         # submodule -> .git contains a pointer to the repository
-        GITHOOKPATH="$(sed 's/gitdir: //' < .git)/hooks/pre-commit"
+        GITHOOKPATH="$($SED 's/gitdir: //' < .git)/hooks/pre-commit"
       else
         # standard case, .git is the repository
         GITHOOKPATH=.git/hooks/pre-commit
@@ -667,9 +670,14 @@ run_default_configure () {
       # such that they are honored by cmake.
       flags="CXX CC CXXFLAGS CFLAGS CPPFLAGS LDFLAGS F77 FFLAGS FLIBS FC FCFLAGS FCLIBS LIBS"
       for i in  $flags; do
-        cflags=`echo "$PARAMS" | $GREP $i= | sed "s/.*\($i=\"[^\"]\+\"\|$i='[^']\+'\|$i=[$NOBLANK]\+\).*/\1/"`
-        if test -n "$cflags" ; then
+        cflags=`echo "$PARAMS" | $GREP $i= | $SED -e "s/.*\($i=\"[^\"]*\"\).*/\1/" -e "s/.*\($i='[^']*'\).*/\1/"`
+        if test -n "$cflags" && test "$PARAMS" != "$cflags" ; then
+            PREPARAMS="$PREPARAMS $cflags"
+          else
+           cflags=`echo "$PARAMS" | $GREP $i= | $SED -e "s/.*\($i=[^$BLANK]*\).*/\1/"`
+           if test -n "$cflags" && test "$PARAMS" != "$cflags" ; then
             PREPARAMS="$PREPARAMS $cflags"
+           fi
         fi
       done
       # create build directory if requested
@@ -1023,7 +1031,7 @@ case "$command" in
         fi
       fi
     done
-    echo export DUNE_CONTROL_PATH=$(echo $DUNE_CONTROL_PATH | sed -e 's/^://')
+    echo export DUNE_CONTROL_PATH=$(echo $DUNE_CONTROL_PATH | $SED -e 's/^://')
     ;;
   printdeps)
     find_modules_in_path
@@ -1058,13 +1066,13 @@ case "$command" in
     # get dependencies
     eval deps=\$DEPS_$mainmod
     #initially remove leading space
-    deps=`echo "$deps" | sed 's/^ *//'`
+    deps=`echo "$deps" | $SED 's/^ *//'`
     while test -n "$deps"; do
       #the end of the name is marked either by space, opening paren
       #or comma
       depname="${deps%%[ (,]*}"
       #remove the name and adjacent whitespace
-      deps=`echo "$deps" | sed 's/^[^ (,]* *//'`
+      deps=`echo "$deps" | $SED 's/^[^ (,]* *//'`
       #check whether there is a dependency version
       case "$deps" in
       '('*) deps="${deps#(}"
@@ -1075,20 +1083,20 @@ case "$command" in
             ;;
       esac
       #remove any leading whitespace or commas for te next iteration
-      deps=`echo "$deps" | sed 's/^[, ]*//'`
+      deps=`echo "$deps" | $SED 's/^[, ]*//'`
 
       requires="$requires $depname $depver "
     done
     # get suggestions
     eval sugs=\$SUGS_$mainmod
     #initially remove leading space
-    sugs=`echo "$sugs" | sed 's/^ *//'`
+    sugs=`echo "$sugs" | $SED 's/^ *//'`
     while test -n "$sugs"; do
       #the end of the name is marked either by space, opening paren
       #or comma
       sugsname="${sugs%%[ (,]*}"
       #remove the name and adjacent whitespace
-      sugs=`echo "$sugs" | sed 's/^[^ (,]* *//'`
+      sugs=`echo "$sugs" | $SED 's/^[^ (,]* *//'`
       #check whether there is a dependency version
       case "$sugs" in
       '('*) sugs="${sugs#(}"
@@ -1099,7 +1107,7 @@ case "$command" in
             ;;
       esac
       #remove any leading whitespace or commas for te next iteration
-      sugs=`echo "$sugs" | sed 's/^[, ]*//'`
+      sugs=`echo "$sugs" | $SED 's/^[, ]*//'`
 
       suggests="$suggests $sugsname"
       suggestsall="$suggestsall $sugsname $sugsver "
diff --git a/lib/dunecommonam2cmake.lib b/lib/dunecommonam2cmake.lib
index eeaec25f1..06ecfcb7d 100644
--- a/lib/dunecommonam2cmake.lib
+++ b/lib/dunecommonam2cmake.lib
@@ -9,7 +9,6 @@
 space=" "
 tab="	"
 BLANK="$space$tab"
-NOBLANK="^$space^$tab"
 
 dune_common_options_am2cmake()
 {
@@ -42,13 +41,13 @@ dune_common_options_am2cmake()
     fi
 
     # Check for --with-minimal-debug-level
-    local arg=`echo "$PARAMS"| grep \\\\--with-minimal-debug-level= | sed "s/.*--with-minimal-debug-level=\([$NOBLANK]*\).*/\1/"`
+    local arg=`echo "$PARAMS"| grep \\\\--with-minimal-debug-level= | sed "s/.*--with-minimal-debug-level=\([^$BLANK]*\).*/\1/"`
     if test "x$arg" != "x"; then
         CMAKE_PARAMS="$CMAKE_PARAMS -DMINIMAL_DEBUG_LEVEL:String=$arg"
     fi
 
     #Check for --prefix
-    local arg=`echo "$PARAMS"| grep \\\\--prefix= | sed "s/.*--prefix=\([$NOBLANK]*\).*/\1/"`
+    local arg=`echo "$PARAMS"| grep \\\\--prefix= | sed "s/.*--prefix=\([^$BLANK]*\).*/\1/"`
     if test "x$arg" != "x"; then
         CMAKE_PARAMS="$CMAKE_PARAMS -DCMAKE_INSTALL_PREFIX=$arg"
     fi
diff --git a/lib/dunemodules.lib b/lib/dunemodules.lib
index 7b9a6b464..63cc0e826 100644
--- a/lib/dunemodules.lib
+++ b/lib/dunemodules.lib
@@ -36,7 +36,7 @@ vtab=""
 # embedded newline.  Instead one can often get away with using $BLANK
 SPACE="$space$formfeed$newline$cr$tab$vtab"
 BLANK="$space$tab"
-NOBLANK="^$space^$tab"
+NOBLANK="^$space$tab"
 
 #
 # read paramters from a $CONTROL file
-- 
GitLab