From 50a2ddfcc7eab564e3a78d7171b63cdd870e6307 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Wed, 22 Oct 2008 14:33:59 +0200
Subject: [PATCH] bin/ wmake/ script updates

  - send error messages to stderr
  - added -h/-help options where some were missing
  - changed 3-space to 4-space indentation
  - where possible, allow multiple directories from the command-line
---
 bin/foamNew                         |  25 +++---
 bin/foamPack                        |  16 ++--
 bin/foamPackDoxygen                 |  41 ++++-----
 bin/foamUpdateCaseFileHeader        |  77 +++++++++--------
 bin/foamUpgradeTurbulenceProperties |  58 ++++++-------
 bin/rmclassall                      |  23 ++---
 bin/rmcore                          |  24 +++---
 bin/rmdepall                        |  14 +--
 bin/rmoall                          |  23 ++---
 bin/rm~all                          |  23 ++---
 wmake/wclean                        |  76 ++++++++---------
 wmake/wcleanAll                     |  23 +++--
 wmake/wcleanAlmostAll               |  17 ++--
 wmake/wcleanLnIncludeAll            |  24 +++++-
 wmake/wcleanMachine                 |  38 +++++----
 wmake/wmake                         | 128 +++++++++++++---------------
 wmake/wmakeDerivedFiles             |   6 +-
 wmake/wmakeFilesAndOptions          |  23 +++--
 wmake/wmakeLnInclude                |  90 +++++++++----------
 19 files changed, 392 insertions(+), 357 deletions(-)

diff --git a/bin/foamNew b/bin/foamNew
index 15005c5c838..2c4fa6f7513 100755
--- a/bin/foamNew
+++ b/bin/foamNew
@@ -36,7 +36,7 @@ usage() {
 
 usage: ${0##*/} <type> {args}
 
-* create a new standard OpenFOAM source file
+* create a new standard OpenFOAM source or template file
 
 type: (source|template)
 
@@ -46,25 +46,24 @@ USAGE
 
 if [ "$#" -lt 2 ]
 then
-   usage "wrong number of arguments, expected 2 (or more)"
+    usage "wrong number of arguments, expected 2 (or more)"
 fi
 
 case "$1" in
 -h | -help)
-   usage
-   ;;
+    usage
+    ;;
 source)
-   shift
-   $WM_PROJECT_DIR/bin/foamTemplates/source/newSource $*
-   ;;
+    shift
+    $WM_PROJECT_DIR/bin/foamTemplates/source/newSource $*
+    ;;
 template)
-   shift
-   $WM_PROJECT_DIR/bin/foamTemplates/sourceTemplate/newSourceTemplate $*
-   ;;
+    shift
+    $WM_PROJECT_DIR/bin/foamTemplates/sourceTemplate/newSourceTemplate $*
+    ;;
 *)
-   usage "unknown type"
-   ;;
+    usage "unknown type"
+    ;;
 esac
 
-
 #------------------------------------------------------------------------------
diff --git a/bin/foamPack b/bin/foamPack
index 8166714c6b7..3691b49add2 100755
--- a/bin/foamPack
+++ b/bin/foamPack
@@ -38,20 +38,20 @@ packFile=${packDir}_${timeStamp}.gtgz
 
 if [ ! -d $packDir ]
 then
-   echo "Error: directory $packDir does not exist"
-   exit 1
+    echo "Error: directory $packDir does not exist" 1>&2
+    exit 1
 fi
 
 # add optional output directory
 if [ -d "$1" ]
 then
-   packFile="$1/$packFile"
+    packFile="$1/$packFile"
 fi
 
 if [ -f $packFile ]
 then
-   echo "Error: $packFile already exists"
-   exit 1
+    echo "Error: $packFile already exists" 1>&2
+    exit 1
 fi
 
 # Create time stamp file
@@ -102,10 +102,10 @@ tar czpf $packFile --files-from $tmpFile
 
 if [ $? = 0 ]
 then
-   echo "Finished packing and compressing $packDir into file $packFile"
+    echo "Finished packing and compressing $packDir into file $packFile"
 else
-   echo "Error: failure packing $packDir into file $packFile"
-   rm -f $packFile 2>/dev/null
+    echo "Error: failure packing $packDir into file $packFile" 1>&2
+    rm -f $packFile 2>/dev/null
 fi
 
 #------------------------------------------------------------------------------
diff --git a/bin/foamPackDoxygen b/bin/foamPackDoxygen
index 239c87c740a..52976452ca1 100755
--- a/bin/foamPackDoxygen
+++ b/bin/foamPackDoxygen
@@ -34,6 +34,7 @@ packDir=$WM_PROJECT-$WM_PROJECT_VERSION
 packTag=_Doxygen.gtgz
 
 usage() {
+    while [ $# -gt 0 ]; do echo "$1" 1>&2; shift; done
 cat <<USAGE 1>&2
 Usage: ${0##*/} [-prefix DIR] [-o outputDir]
 
@@ -47,38 +48,38 @@ unset prefix outputDir
 
 while [ "$#" -gt 0 ]
 do
-   case $1 in
-   -prefix | --prefix )
-      prefix=${2%%/}
-      shift 2
-      ;;
-   -o | -output )
-      outputDir=${2%%/}
-      shift 2
-      ;;
-   -h | -help )
-      usage
-      ;;
-   -*)
-      usage "unknown option: '$*'"
-      ;;
-   esac
+    case $1 in
+    -prefix | --prefix )
+        prefix=${2%%/}
+        shift 2
+        ;;
+    -o | -output )
+        outputDir=${2%%/}
+        shift 2
+        ;;
+    -h | -help )
+        usage
+        ;;
+    -*)
+        usage "unknown option: '$*'"
+        ;;
+    esac
 done
 
 # if packing from within the directory, use -prefix form
 if [ "${PWD##*/}" = "$packDir" ]
 then
-   : ${prefix:=$packDir}
+    : ${prefix:=$packDir}
 fi
 
 # pack the directories directly and add prefix afterwards
 if [ -n "$prefix" ]
 then
-   packDir="$prefix"
+    packDir="$prefix"
 elif [ ! -d $packDir ]
 then
-   echo "Error: directory $packDir does not exist"
-   exit 1
+    echo "Error: directory $packDir does not exist" 1>&2
+    exit 1
 fi
 
 #
diff --git a/bin/foamUpdateCaseFileHeader b/bin/foamUpdateCaseFileHeader
index 805f4e128a7..f4340fc53c7 100755
--- a/bin/foamUpdateCaseFileHeader
+++ b/bin/foamUpdateCaseFileHeader
@@ -36,26 +36,25 @@
 foamVersion=$WM_PROJECT_VERSION
 
 usage() {
-   cat<<USAGE
+    cat<<USAGE
 
 usage: ${0##*/} [OPTION] <file1> ... <fileN>
 
 options:
-  -v "<version>"  specifies the version to be written in the header
-  -h              help
+  -v VER  specifies the version to be written in the header
+  -h      help
 
-  Updates the header of application files.
+  Updates the header of application files and removes consecutive blank lines.
   By default, writes current version in the header.
-  Alternatively version can be specified with -v option.
-  Also removes consecutive blank lines from file.
+  An alternative version can be specified with -v option.
 
 USAGE
-   exit 1
+    exit 1
 }
 
 
 printHeader() {
-   cat<<HEADER
+    cat<<HEADER
 /*--------------------------------*- C++ -*----------------------------------*\\
 | =========                 |                                                 |
 | \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
@@ -78,7 +77,7 @@ HEADER
 # extract attribute '$1' from file '$2'
 #
 FoamFileAttribute() {
-   sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
+    sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
 }
 
 
@@ -88,22 +87,22 @@ FoamFileAttribute() {
 OPTS=`getopt hv: $*`
 if [ $? -ne 0 ]
 then
-   echo "Aborting due to invalid option"
-   usage
+    echo "Aborting due to invalid option"
+    usage
 fi
 eval set -- '$OPTS'
 while [ "$1" != "--" ]
 do
-   case $1 in
-   -v)
-      foamVersion=$2
-      shift
-      ;;
-   -h)
-      usage
-      ;;
-   esac
-   shift
+    case $1 in
+    -v)
+        foamVersion=$2
+        shift
+        ;;
+    -h)
+        usage
+        ;;
+    esac
+    shift
 done
 shift
 
@@ -118,24 +117,24 @@ foamVersion=`printf %-36s $foamVersion`
 #
 for caseFile
 do
-   if grep FoamFile $caseFile >/dev/null 2>&1
-   then
-      echo "Updating case file: $caseFile"
-      sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
-
-      CLASS=`FoamFileAttribute class FoamFile.tmp`
-      OBJECT=`FoamFileAttribute object FoamFile.tmp`
-      FORMAT=`FoamFileAttribute format FoamFile.tmp`
-
-      printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
-      sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
-
-      # use cat to avoid removing/replace soft-links
-      [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
-      rm FoamFile.tmp
-   else
-      echo " Invalid case file: $caseFile"
-   fi
+    if grep FoamFile $caseFile >/dev/null 2>&1
+    then
+        echo "Updating case file: $caseFile"
+        sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
+
+        CLASS=`FoamFileAttribute class FoamFile.tmp`
+        OBJECT=`FoamFileAttribute object FoamFile.tmp`
+        FORMAT=`FoamFileAttribute format FoamFile.tmp`
+
+        printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
+        sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
+
+        # use cat to avoid removing/replace soft-links
+        [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
+        rm FoamFile.tmp
+    else
+        echo " Invalid case file: $caseFile" 1>&2
+    fi
 done
 
 #------------------------------------------------------------------------------
diff --git a/bin/foamUpgradeTurbulenceProperties b/bin/foamUpgradeTurbulenceProperties
index 297b7e4e635..9d542ca0e24 100755
--- a/bin/foamUpgradeTurbulenceProperties
+++ b/bin/foamUpgradeTurbulenceProperties
@@ -37,7 +37,7 @@
 #------------------------------------------------------------------------------
 
 usage() {
-   cat<<USAGE
+    cat<<USAGE
 
 usage: ${0##*/} <turbulenceProperties>
 
@@ -57,42 +57,42 @@ USAGE
 #
 convertDict()
 {
-   echo "Identified $1 turbulence model in '$3'"
-   outputPath=`dirname $3`
+    echo "Identified $1 turbulence model in '$3'"
+    outputPath=`dirname $3`
 
-   if [ -e "$outputPath/$1Properties" ]
-   then
-      echo "Error: file already exists $outputPath/$1Properties'"
-   else
-      sed -e "s/turbulenceProperties/$1Properties/" \
-          -e "s/$2/$1Model/" \
-          -e "s/[a-zA-Z0-9]* [ ]*\[[0-9 ]*\]//" \
-          $3 > "$outputPath/$1Properties"
+    if [ -e "$outputPath/$1Properties" ]
+    then
+        echo "Error: file already exists $outputPath/$1Properties'" 1>&2
+    else
+        sed -e "s/turbulenceProperties/$1Properties/" \
+            -e "s/$2/$1Model/" \
+            -e "s/[a-zA-Z0-9]* [ ]*\[[0-9 ]*\]//" \
+            $3 > "$outputPath/$1Properties"
 
-      echo "    wrote $outputPath/$1Properties"
-   fi
+        echo "    wrote $outputPath/$1Properties"
+    fi
 }
 
 [ $# -ge 1 ] || usage
 
 for turbDict
 do
-   # Identify type of turbulence model and convert
-   if [ -f $turbDict ]
-   then
-      if grep turbulenceModel $turbDict >/dev/null 2>&1
-      then
-          convertDict RAS turbulenceModel $turbDict
-      elif grep LESmodel $turbDict >/dev/null 2>&1
-      then
-          convertDict LES LESmodel $turbDict
-      else
-          echo "Unable to determine turbulence model type in '$turbDict'"
-          echo "    - nothing changed"
-      fi
-   else
-      echo "Error: file '$turbDict' does not exist"
-   fi
+    # Identify type of turbulence model and convert
+    if [ -f $turbDict ]
+    then
+        if grep turbulenceModel $turbDict >/dev/null 2>&1
+        then
+            convertDict RAS turbulenceModel $turbDict
+        elif grep LESmodel $turbDict >/dev/null 2>&1
+        then
+            convertDict LES LESmodel $turbDict
+        else
+            echo "Unable to determine turbulence model type in '$turbDict'" 1>&2
+            echo "    - nothing changed" 1>&2
+        fi
+    else
+        echo "Error: file '$turbDict' does not exist" 1>&2
+    fi
 done
 
 #------------------------------------------------------------------------------
diff --git a/bin/rmclassall b/bin/rmclassall
index 059306bee51..de45bb2b2b7 100755
--- a/bin/rmclassall
+++ b/bin/rmclassall
@@ -3,22 +3,23 @@
 # default is pwd
 if [ "$#" -eq 0 ]
 then
-   set -- .
+    set -- .
 elif [ "$1" = "-h" -o "$1" = "-help" ]
 then
-   echo "Usage: ${0##*/} [dir1] .. [dirN]"
-   echo "    remove all .class files"
-   exit 1
+    echo "Usage: ${0##*/} [dir1] .. [dirN]"
+    echo "    remove all .class files"
+    exit 1
 fi
 
 for i
 do
-   if [ -d "$i" ]
-   then
-      echo "removing all .class files"
-      find $i -name '*.class' -print | xargs -t rm
-   else
-      echo "no directory: $i"
-   fi
+    if [ -d "$i" ]
+    then
+        echo "removing all .class files: $i"
+        find $i -name '*.class' -print | xargs -t rm 2>/dev/null
+    else
+        echo "no directory: $i" 1>&2
+    fi
 done
+
 #------------------------------------------------------------------------------
diff --git a/bin/rmcore b/bin/rmcore
index f34cae57a5c..dddf09406c7 100755
--- a/bin/rmcore
+++ b/bin/rmcore
@@ -3,23 +3,23 @@
 # default is pwd
 if [ "$#" -eq 0 ]
 then
-   set -- .
+    set -- .
 elif [ "$1" = "-h" -o "$1" = "-help" ]
 then
-   echo "Usage: ${0##*/} [dir1] .. [dirN]"
-   echo "    remove all core files"
-   exit 1
+    echo "Usage: ${0##*/} [dir1] .. [dirN]"
+    echo "    remove all core files"
+    exit 1
 fi
 
 for i
 do
-   if [ -d "$i" ]
-   then
-      echo "removing all core files"
-      find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm
-   else
-      echo "no directory: $i"
-   fi
+    if [ -d "$i" ]
+    then
+        echo "removing all core files: $i"
+        find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm 2>/dev/null
+    else
+        echo "no directory: $i" 1>&2
+    fi
 done
-#------------------------------------------------------------------------------
 
+#------------------------------------------------------------------------------
diff --git a/bin/rmdepall b/bin/rmdepall
index 4cfa1ad6801..b0f1876b456 100755
--- a/bin/rmdepall
+++ b/bin/rmdepall
@@ -2,18 +2,18 @@
 
 if [ "$1" = "-h" -o "$1" = "-help" -o "$#" -gt 1 ]
 then
-   echo "Usage: ${0##*/}         : remove all .dep files"
-   echo "       ${0##*/} <file>  : remove all .dep files referring to <file>"
-   exit 1
+    echo "Usage: ${0##*/}         : remove all .dep files"
+    echo "       ${0##*/} <file>  : remove all .dep files referring to <file>"
+    exit 1
 fi
 
 if [ "$#" -eq 0 ]
 then
-   echo "removing all .dep files"
-   find . -name '*.dep' -print | xargs -t rm
+    echo "removing all .dep files"
+    find . -name '*.dep' -print | xargs -t rm 2>/dev/null
 else
-   echo "removing all .dep files containing $1..."
-   find . -name '*.dep' -exec grep "$1" '{}' \; -exec rm '{}' \;
+    echo "removing all .dep files containing $1..."
+    find . -name '*.dep' -exec grep "$1" '{}' \; -exec rm '{}' \;
 fi
 
 #------------------------------------------------------------------------------
diff --git a/bin/rmoall b/bin/rmoall
index 32bd8047889..d49a6f4a05e 100755
--- a/bin/rmoall
+++ b/bin/rmoall
@@ -3,22 +3,23 @@
 # default is pwd
 if [ "$#" -eq 0 ]
 then
-   set -- .
+    set -- .
 elif [ "$1" = "-h" -o "$1" = "-help" ]
 then
-   echo "Usage: ${0##*/} [dir1] .. [dirN]"
-   echo "    remove all .o files"
-   exit 1
+    echo "Usage: ${0##*/} [dir1] .. [dirN]"
+    echo "    remove all .o files"
+    exit 1
 fi
 
 for i
 do
-   if [ -d "$i" ]
-   then
-      echo "removing all .o files: $i"
-      find $i -name '*.o' -print | xargs -t rm
-   else
-      echo "no directory: $i"
-   fi
+    if [ -d "$i" ]
+    then
+        echo "removing all .o files: $i"
+        find $i -name '*.o' -print | xargs -t rm 2>/dev/null
+    else
+        echo "no directory: $i" 1>&2
+    fi
 done
+
 #------------------------------------------------------------------------------
diff --git a/bin/rm~all b/bin/rm~all
index 0725382447a..ab8b4b17c7a 100755
--- a/bin/rm~all
+++ b/bin/rm~all
@@ -3,22 +3,23 @@
 # default is pwd
 if [ "$#" -eq 0 ]
 then
-   set -- .
+    set -- .
 elif [ "$1" = "-h" -o "$1" = "-help" ]
 then
-   echo "Usage: ${0##*/} [dir1] .. [dirN]"
-   echo "    remove all *~ files"
-   exit 1
+    echo "Usage: ${0##*/} [dir1] .. [dirN]"
+    echo "    remove all *~ files"
+    exit 1
 fi
 
 for i
 do
-   if [ -d "$i" ]
-   then
-      echo "removing all *~ files"
-      find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm
-   else
-      echo "no directory: $i"
-   fi
+    if [ -d "$i" ]
+    then
+        echo "removing all *~ files: $i"
+        find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm 2>/dev/null
+    else
+       echo "no directory: $i" 1>&2
+    fi
 done
+
 #------------------------------------------------------------------------------
diff --git a/wmake/wclean b/wmake/wclean
index 1ea917eec52..8d75088397a 100755
--- a/wmake/wclean
+++ b/wmake/wclean
@@ -34,8 +34,8 @@
 Script=${0##*/}
 
 usage() {
-   while [ "$#" -ge 1 ]; do echo "$1"; shift; done
-   cat<<USAGE
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
 usage: $Script [dir]
        $Script target [dir [MakeDir]]
 
@@ -56,7 +56,7 @@ USAGE
 # provide immediate help
 if [ "$1" = "-h" -o "$1" = "-help" ]
 then
-   usage
+    usage
 fi
 
 
@@ -70,35 +70,34 @@ MakeDir=Make
 if [ $# -ge 1 ]
 then
 
-   if [ -d "$1" ]
-   then
-      dir=$1
-   else
-      makeOption=$1
-   fi
-
-   if [ $# -ge 2 ]
-   then
-      dir=$2
-   fi
-
-   # alternative name for the Make sub-directory
-   if [ $# -ge 3 ]
-   then
-      MakeDir=$3
-   fi
-
-   if [ "$dir" ]
-   then
-      cd $dir 2>/dev/null || {
-         echo "$Script error"
-         echo "    could not change to directory '$dir'"
-         exit 1
-      }
-   fi
-
-   # provide some feedback
-   echo "$Script ${dir:-./}"
+    if [ -d "$1" ]
+    then
+        dir=$1
+    else
+        makeOption=$1
+    fi
+
+    if [ $# -ge 2 ]
+    then
+        dir=$2
+    fi
+
+    # alternative name for the Make sub-directory
+    if [ $# -ge 3 ]
+    then
+        MakeDir=$3
+    fi
+
+    if [ "$dir" ]
+    then
+        cd $dir 2>/dev/null || {
+            echo "$Script error: could not change to directory '$dir'" 1>&2
+            exit 1
+        }
+    fi
+
+    # provide some feedback
+    echo "$Script ${dir:-./}"
 fi
 
 #------------------------------------------------------------------------------
@@ -113,9 +112,9 @@ then
         exit $?
     elif [ ! -d $MakeDir ]
     then
-        for dir in `find . \( -type d -a -name "Make" \) -printf "%h "`
+        for dir in `find . \( -type d -a -name Make \) -printf "%h "`
         do
-           $0 $dir
+            $0 $dir
         done
         exit 0
     fi
@@ -131,9 +130,8 @@ fi
 
 if [ ! -d $MakeDir ]
 then
-   echo "$Script error"
-   echo "    '$MakeDir' directory does not exist"
-   exit 1
+    echo "$Script error: '$MakeDir' directory does not exist" 1>&2
+    exit 1
 fi
 
 # -----------------------------------------------------------------------------
@@ -144,8 +142,8 @@ find . -name "*.dep" -exec rm {} \;
 
 case "$makeOption" in
 lib | libso | libo )
-   rm -rf lnInclude 2>/dev/null
-   ;;
+    rm -rf lnInclude 2>/dev/null
+    ;;
 esac
 
 rm -rf ii_files Templates.DB 2>/dev/null
diff --git a/wmake/wcleanAll b/wmake/wcleanAll
index e9b36bc3756..5e388d4ec59 100755
--- a/wmake/wcleanAll
+++ b/wmake/wcleanAll
@@ -27,20 +27,27 @@
 #     wcleanAll
 #
 # Description
-#     script that searches all the directories below the current for the
-#     object file directories of all machines and then deletes them.
+#     search all the directories below the current for the object file
+#     directories of all machines and delete them.
 #
 #------------------------------------------------------------------------------
+if [ "$1" = "-h" -o "$1" = "-help" ]
+then
+    echo "Usage: ${0##*/}"
+    echo
+    echo "    Remove all object files and *.dep files"
+    exit 1
+fi
 
 [ -d bin -a -d src ] || {
-   echo "${0##*/}: not in the project top level directory"
-   exit 1
+    echo "${0##*/}: not in the project top level directory"
+    exit 1
 }
 
 for dir in lib applications/bin
 do
-   echo "Removing $dir/"
-   [ -d $dir ] && rm -rf $dir/*
+    echo "Removing $dir/"
+    [ -d $dir ] && rm -rf $dir/*
 done
 
 echo "Removing *~ backup files"
@@ -50,7 +57,7 @@ echo "Removing .dep files"
 find . -name '*.dep' -exec rm {} \;
 
 echo "Cleaning Make subdirectories"
-find `find . -depth \( -name "Make.[A-Za-z]*" -o -name "Make" \) -type d -print` -depth \( -type d ! -name "*Make.[A-Za-z]*" ! -name "*Make" \) -exec rm -rf {} \;
+find `find . -depth \( -name "Make.[A-Za-z]*" -o -name Make \) -type d -print` -depth \( -type d ! -name "*Make.[A-Za-z]*" ! -name "*Make" \) -exec rm -rf {} \;
 
 echo "Removing lnInclude and intermediate directories"
 find . -depth -type d \( -name lnInclude -o -name ii_files -o -name Templates.DB \) -exec rm -rf {} \;
@@ -58,8 +65,6 @@ find . -depth -type d \( -name lnInclude -o -name ii_files -o -name Templates.DB
 echo "Removing misc files"
 find . \( -name exe -o -name log -o -name so_locations \) -exec rm {} \;
 
-# rm -rf src/mpich-${MPICH_VERSION}/platforms
-
 ( cd tutorials && ./Allclean )
 
 #------------------------------------------------------------------------------
diff --git a/wmake/wcleanAlmostAll b/wmake/wcleanAlmostAll
index 8bd52916008..85b0368457f 100755
--- a/wmake/wcleanAlmostAll
+++ b/wmake/wcleanAlmostAll
@@ -30,16 +30,23 @@
 #     as per wcleanAll, but retains "*~" backup files
 #
 #------------------------------------------------------------------------------
+if [ "$1" = "-h" -o "$1" = "-help" ]
+then
+    echo "Usage: ${0##*/}"
+    echo
+    echo "    Remove all object files and *.dep files"
+    exit 1
+fi
 
 [ -d bin -a -d src ] || {
-   echo "${0##*/}: not in the project top level directory"
-   exit 1
+    echo "${0##*/}: not in the project top level directory"
+    exit 1
 }
 
 for dir in lib applications/bin
 do
-   echo "Removing $dir/"
-   [ -d $dir ] && rm -rf $dir/*
+    echo "Removing $dir/"
+    [ -d $dir ] && rm -rf $dir/*
 done
 
 echo "Retaining *~ backup files"
@@ -49,7 +56,7 @@ echo "Removing .dep files"
 find . -name '*.dep' -exec rm {} \;
 
 echo "Cleaning Make subdirectories"
-find `find . -depth \( -name "Make.[A-Za-z]*" -o -name "Make" \) -type d -print` -depth \( -type d ! -name "*Make.[A-Za-z]*" ! -name "*Make" \) -exec rm -rf {} \;
+find `find . -depth \( -name "Make.[A-Za-z]*" -o -name Make \) -type d -print` -depth \( -type d ! -name "*Make.[A-Za-z]*" ! -name "*Make" \) -exec rm -rf {} \;
 
 echo "Removing lnInclude and intermediate directories"
 find . -depth -type d \( -name lnInclude -o -name ii_files -o -name Templates.DB \) -exec rm -rf {} \;
diff --git a/wmake/wcleanLnIncludeAll b/wmake/wcleanLnIncludeAll
index 67da4d0bb0c..2cd830e8557 100755
--- a/wmake/wcleanLnIncludeAll
+++ b/wmake/wcleanLnIncludeAll
@@ -31,6 +31,28 @@
 #
 #------------------------------------------------------------------------------
 
-find . -depth -type d -name lnInclude -exec rm -rf {} \;
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+    set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+    echo "Usage: ${0##*/} [dir1] .. [dirN]"
+    echo
+    echo "    Delete all the lnInclude directories in the tree"
+    exit 1
+fi
+
+
+for i
+do
+    if [ -d "$i" ]
+    then
+        echo "removing lnInclude directories: $i"
+        find $i -depth -type d -name lnInclude -exec rm -rf {} \;
+    else
+        echo "no directory: $i" 1>&2
+    fi
+done
 
 #------------------------------------------------------------------------------
diff --git a/wmake/wcleanMachine b/wmake/wcleanMachine
index a3deba2322c..9dacf643eab 100755
--- a/wmake/wcleanMachine
+++ b/wmake/wcleanMachine
@@ -33,32 +33,40 @@
 #     Usage: wcleanMachine <machineType> [ .. <machineTypeN> ]
 #
 #------------------------------------------------------------------------------
+usage() {
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
+usage: ${0##*/} machineType [... machineTypeN]
 
-if [ $# -eq 0 ]
+  Searches the directories below the current directory for the object file
+  directories of the specified machine type(s) and deletes them
+
+USAGE
+    exit 1
+}
+
+# needs some machine types ... or provide immediate help
+if [ "$#" -lt 1 -o "$1" = "-h" -o "$1" = "-help" ]
 then
-   echo "${0##*/}: Machine type(s) expected, exiting !"
-   exit 1
+    usage
 fi
 
-[ -d lib -a -d src ] || {
-   echo "${0##*/}: not in the project top level directory !"
-   exit 1
-}
+[ -d lib -a -d src ] || usage "not in the project top level directory"
 
 
 for machType
 do
-   echo "Cleaning machine type: $machType"
+    echo "Cleaning machine type: $machType"
 
-   find `find . -depth \( -name "Make.[A-Za-z]*" -o -name "Make" \) -type d -print` \
-       -depth \( -type d -name "*$machType" -o -name "*$machType$WM_MPLIB" \) -exec rm -r {} \;
+    find `find . -depth \( -name "Make.[A-Za-z]*" -o -name Make \) -type d -print` \
+        -depth \( -type d -name "*$machType" -o -name "*$machType$WM_MPLIB" \) -exec rm -r {} \;
 
-   # find . -depth -type d \( -name ii_files -o -name Templates.DB \) -exec rm -rf {} \;
+    # find . -depth -type d \( -name ii_files -o -name Templates.DB \) -exec rm -rf {} \;
 
-   for dir in lib/$machType applications/bin/$machType
-   do
-      [ -d $dir ] && rm -r $dir
-   done
+    for dir in lib/$machType applications/bin/$machType
+    do
+        [ -d $dir ] && rm -rf $dir
+    done
 
 done
 
diff --git a/wmake/wmake b/wmake/wmake
index 1290fd556d4..92dc42a9f3f 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -33,8 +33,8 @@
 Script=${0##*/}
 
 usage() {
-   while [ "$#" -ge 1 ]; do echo "$1"; shift; done
-   cat<<USAGE
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
 usage: $Script [dir]
        $Script target [dir [MakeDir]]
 
@@ -52,12 +52,13 @@ The 'target' is a Makefile target:
     jar       build Java jar
 
 USAGE
-   exit 1
+    exit 1
 }
 
 # provide immediate help
-if [ "$1" = "-h" -o "$1" = "-help" ]; then
-   usage
+if [ "$1" = "-h" -o "$1" = "-help" ]
+then
+    usage
 fi
 
 
@@ -66,20 +67,19 @@ fi
 #
 for check in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
 do
-   eval test "\$$check" || {
-      echo "$Script error"
-      echo "    environment variable \$$check not set"
-      exit 1
-   }
+    eval test "\$$check" || {
+        echo "$Script error: environment variable \$$check not set" 1>&2
+        exit 1
+    }
 done
 
 # when compiling anything but a standalone exe,
 # WM_PROJECT and WM_PROJECT_DIR must be set
 [ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || {
-   echo "$Script error"
-   echo "    environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set"
-   echo  "   while building project library or executable"
-   exit 1
+    echo "$Script error:" 1>&2
+    echo "    environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set" 1>&2
+    echo  "   while building project library" 1>&2
+    exit 1
 }
 
 
@@ -92,8 +92,8 @@ make="make"
 # set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
 if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
 then
-   WM_NCOMPPROCS=$(wmakeScheduler -count)
-   [ $? -eq 0 ] || unset WM_NCOMPPROCS
+    WM_NCOMPPROCS=$(wmakeScheduler -count)
+    [ $? -eq 0 ] || unset WM_NCOMPPROCS
 fi
 
 if [ "$WM_NCOMPPROCS" ]
@@ -123,32 +123,31 @@ MakeDir=Make
 
 if [ $# -ge 1 ]
 then
-   if [ -d "$1" ]
-   then
-      dir=$1
-   else
-      makeOption=$1
-   fi
-
-   if [ $# -ge 2 ]
-   then
-      dir=$2
-   fi
-
-   # alternative name for the Make sub-directory
-   if [ $# -ge 3 ]
-   then
-      MakeDir=$3
-   fi
-
-   if [ "$dir" ]
-   then
-      cd $dir 2>/dev/null || {
-         echo "$Script error"
-         echo "    could not change to directory '$dir'"
-         exit 1
-      }
-   fi
+    if [ -d "$1" ]
+    then
+        dir=$1
+    else
+        makeOption=$1
+    fi
+
+    if [ $# -ge 2 ]
+    then
+        dir=$2
+    fi
+
+    # alternative name for the Make sub-directory
+    if [ $# -ge 3 ]
+    then
+        MakeDir=$3
+    fi
+
+    if [ "$dir" ]
+    then
+        cd $dir 2>/dev/null || {
+            echo "$Script error: could not change to directory '$dir'" 1>&2
+            exit 1
+        }
+    fi
 fi
 
 
@@ -180,27 +179,23 @@ fi
 # If both exist make the wmake derived files
 #------------------------------------------------------------------------------
 
-if [ ! -d $MakeDir ]
-then
-   echo "$Script error"
-   echo "    '$MakeDir' directory does not exist"
-   exit 1
-fi
+[ -d $MakeDir ] || {
+    echo "$Script error: '$MakeDir' directory does not exist" 1>&2
+    exit 1
+}
 
-if [ ! -r $MakeDir/files ]
-then
-   echo "$Script error"
-   echo "    file '$MakeDir/files' does not exist"
-   exit 1
-fi
+[ -r $MakeDir/files ] || {
+    echo "$Script error: file '$MakeDir/files' does not exist" 1>&2
+    exit 1
+}
 
 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
 # files and options being built in parallel
 (
-   cd $MakeDir
-   unset MAKEFLAGS
-   make -s -f $WM_DIR/MakefileOptions
-   make -s -f $WM_DIR/MakefileFiles allFiles
+    cd $MakeDir
+    unset MAKEFLAGS
+    make -s -f $WM_DIR/MakefileOptions
+    make -s -f $WM_DIR/MakefileFiles allFiles
 )
 
 
@@ -211,12 +206,10 @@ fi
 
 OBJECTS_DIR=$MakeDir/$WM_OPTIONS
 
-if [ ! -r $OBJECTS_DIR/objectFiles ]
-then
-   echo "$Script error"
-   echo "    file '$OBJECTS_DIR/objectFiles' was not created successfully"
-   exit 1
-fi
+[ -r $OBJECTS_DIR/objectFiles ] || {
+    echo "$Script error: file '$OBJECTS_DIR/objectFiles' could not be created" 1>&2
+    exit 1
+}
 
 
 #------------------------------------------------------------------------------
@@ -227,14 +220,15 @@ touch $OBJECTS_DIR/dontIncludeDeps
 
 case "$makeOption" in
 lib | libso | libo )
-   $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps lnInclude/uptodate
-   ;;
+    $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps lnInclude/uptodate
+    ;;
 esac
 
 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps $OBJECTS_DIR/dependencies
 
 retVal=$?
-if [ $retVal -ne 0 ]; then
+if [ $retVal -ne 0 ]
+then
     exit $retVal
 fi
 
diff --git a/wmake/wmakeDerivedFiles b/wmake/wmakeDerivedFiles
index e4fd037a257..9f2aa1543a9 100755
--- a/wmake/wmakeDerivedFiles
+++ b/wmake/wmakeDerivedFiles
@@ -34,14 +34,14 @@
 
 if [ ! -d "$WM_OPTIONS" ]
 then
-    echo "The $WM_OPTIONS directory does not exist, exiting"
+    echo "The $WM_OPTIONS directory does not exist, exiting" 1>&2
     exit 1
 fi
 
 # change to the $WM_OPTIONS directory
 cd $WM_OPTIONS 2>/dev/null || {
-   echo "Could not change to directory '$WM_OPTIONS'"
-   exit 1
+    echo "Could not change to directory '$WM_OPTIONS'" 1>&2
+    exit 1
 }
 
 # Find and keep macro definitions in files list
diff --git a/wmake/wmakeFilesAndOptions b/wmake/wmakeFilesAndOptions
index f65b7c435e1..b26a45bf41b 100755
--- a/wmake/wmakeFilesAndOptions
+++ b/wmake/wmakeFilesAndOptions
@@ -40,29 +40,28 @@ Script=${0##*/}
 #
 for check in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
 do
-   eval test "\$$check" || {
-      echo "$Script error"
-      echo "    environment variable \$$check not set"
-      exit 1
-   }
+    eval test "\$$check" || {
+        echo "$Script error: environment variable \$$check not set" 1>&2
+        exit 1
+    }
 done
 
 if [ -d Make ]
 then
-   echo "$Script: Make directory already exists"
-   exit 1
+    echo "$Script error: Make directory already exists" 1>&2
+    exit 1
 else
-   mkdir Make
+    mkdir Make
 fi
 
 [ -e Make/files ] || {
-   echo "$Script: Creating files"
-   $WM_DIR/scripts/makeFiles
+    echo "$Script: Creating files"
+    $WM_DIR/scripts/makeFiles
 }
 
 [ -e Make/options ] || {
-   echo "$Script: Creating options"
-   $WM_DIR/scripts/makeOptions
+    echo "$Script: Creating options"
+    $WM_DIR/scripts/makeOptions
 }
 
 #------------------------------------------------------------------------------
diff --git a/wmake/wmakeLnInclude b/wmake/wmakeLnInclude
index ad63d6bca94..066b6346fd0 100755
--- a/wmake/wmakeLnInclude
+++ b/wmake/wmakeLnInclude
@@ -41,8 +41,8 @@
 Script=${0##*/}
 
 usage() {
-   while [ "$#" -ge 1 ]; do echo "$1"; shift; done
-   cat<<USAGE
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
 
 usage: $Script [-f] <dir> [-lnOption]
 
@@ -62,68 +62,68 @@ unset findOpt
 # simple parse options
 while [ "$#" -gt 0 ]
 do
-   case "$1" in
-   -h | -help)   # provide immediate help
-      usage
-      ;;
-   -f)
-      shift
-      forceUpdate=1
-      ;;
-   -*)
-      usage "unknown option/argument: '$*'"
-      ;;
-   *)
-      break
-      ;;
-   esac
+    case "$1" in
+    -h | -help)   # provide immediate help
+        usage
+        ;;
+    -f)
+        shift
+        forceUpdate=1
+        ;;
+    -*)
+        usage "unknown option/argument: '$*'"
+        ;;
+    *)
+        break
+        ;;
+    esac
 done
 
 baseDir=$1
 # convert incorrect path/dir/lnInclude to something sensible
 while [ "${baseDir##*/}" = lnInclude ]
 do
-   baseDir="${baseDir%/*}"
-   if [ "$baseDir" = lnInclude ]
-   then
-      baseDir="."
-   fi
+    baseDir="${baseDir%/*}"
+    if [ "$baseDir" = lnInclude ]
+    then
+        baseDir="."
+    fi
 done
 incDir=$baseDir/lnInclude
 
 
 if [ $# -eq 1 ]
 then
-   lnOpt="-s"
+    lnOpt="-s"
 elif [ $# -eq 2 ]
 then
-   lnOpt="$2"
+    lnOpt="$2"
 else
-   usage "ERROR: incorrect number of arguments"
+    usage "ERROR: incorrect number of arguments"
 fi
 
 
 if [ ! -d $baseDir ]
 then
-   echo $Script: Base directory $baseDir does not exist, exiting.
-   exit 2
+    echo "$Script error: base directory $baseDir does not exist" 1>&2
+    exit 2
 fi
 
 if [ -d $incDir ]
 then
-   if [ ! "$forceUpdate" ]
-   then
-      # echo $Script: include directory $incDir already exists, exiting.
-      exit 0
-   fi
+    if [ ! "$forceUpdate" ]
+    then
+       # echo "$Script error: include directory $incDir already exists" 1>&2
+       exit 0
+    fi
 else
-   mkdir $incDir
+    mkdir $incDir
 fi
 
 if [ ! -d $incDir ]
 then
-   echo $Script: failed to create include directory $incDir
-   exit 0
+    echo "$Script error: failed to create include directory $incDir" 1>&2
+    exit 0
 fi
 
 cd $incDir || exit 1
@@ -131,7 +131,7 @@ cd $incDir || exit 1
 
 # Link include files
 # ~~~~~~~~~~~~~~~~~~
-echo $Script: linking include files to $incDir
+echo "$Script: linking include files to $incDir"
 
 #
 # remove any broken links first (this helps when file locations have moved)
@@ -146,14 +146,14 @@ find .. $findOpt \
  -o \( -name '*.[CHh]' -o -name '*.[ch]xx' -o -name '*.[ch]pp' -o -name '*.type' \)  \
  -a ! -name ".#*" \
  -print | \
-   while read src
-   do
-      link=$(readlink ${src##*/})
-      if [ "$link" != "$src" ]
-      then
-         rm $link 2>/dev/null
-         ln $lnOpt $src .
-      fi
-   done
+    while read src
+    do
+        link=$(readlink ${src##*/})
+        if [ "$link" != "$src" ]
+        then
+            rm $link 2>/dev/null
+            ln $lnOpt $src .
+        fi
+    done
 
 #------------------------------------------------------------------------------
-- 
GitLab