From 7f9631634d338a20e5887003c47d34e2ff7167d6 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 18 Jul 2008 15:32:10 +0200
Subject: [PATCH] cleanup wmake scripts

  - match comments to names of scripts
  - remove comments about using C-shell (not true anymore)
  - use 'assert' style syntax in places instead of if/then/fi
  - wcleanMachine supports multiple arguments
---
 wmake/MakefileOptions      |  2 +-
 wmake/makeWmake            |  5 +++-
 wmake/scripts/addCompile   |  6 ++--
 wmake/scripts/makeFiles    | 36 +++++++++--------------
 wmake/scripts/makeOptions  | 16 +++-------
 wmake/scripts/mkObjectDir  |  6 ++--
 wmake/wclean               |  5 ++--
 wmake/wcleanAll            | 15 ++++------
 wmake/wcleanAlmostAll      | 12 +++-----
 wmake/wcleanMachine        | 43 ++++++++++++---------------
 wmake/wmakeDerivedFiles    | 10 ++++---
 wmake/wmakeFilesAndOptions | 60 +++++++++++++++-----------------------
 12 files changed, 87 insertions(+), 129 deletions(-)

diff --git a/wmake/MakefileOptions b/wmake/MakefileOptions
index f4da8edd9a5..9cb02871166 100644
--- a/wmake/MakefileOptions
+++ b/wmake/MakefileOptions
@@ -23,7 +23,7 @@
 #     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 #
 # Script
-#     MakefileFiles
+#     MakefileOptions
 #
 # Description
 #     General, easy to use make system for multi-platform development.
diff --git a/wmake/makeWmake b/wmake/makeWmake
index 5b2c4772573..a18f72f009b 100755
--- a/wmake/makeWmake
+++ b/wmake/makeWmake
@@ -27,10 +27,13 @@
 #     makeWmake
 #
 # Description
-#     Script to build all the system specific parts of wmake
+#     Script to build all the system-specific parts of wmake
 #
 #------------------------------------------------------------------------------
 
+# run from this directory only
+cd ${0%/*} || exit 1
+
 ( cd src && make )
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/addCompile b/wmake/scripts/addCompile
index c56f4043b99..f5d70d2c80a 100755
--- a/wmake/scripts/addCompile
+++ b/wmake/scripts/addCompile
@@ -28,8 +28,6 @@
 #
 # Description
 #     Cleans up the dependency list and add the compilation statement.
-#     It has to be written in the C-shell rather than the Bourne shell
-#     because it uses file name manipulators.
 #
 #     Usage: wmkdep <fileName> | addCompile <fileName>
 #
@@ -52,11 +50,11 @@ if [ "$WM_PROJECT_DIR" ]
 then
     sed -e s%$WM_PROJECT_DIR%'$(WM_PROJECT_DIR)'% > $depName
 else
-	cat > $depName
+    cat > $depName
 fi
 
 
-if [ "$sub" = "java" ]
+if [ "$sub" = java ]
 then
 
     sed -e s%"\(.*\).class.*:"%'$(CLASSES_DIR)/'"\1.class\:"%   \
diff --git a/wmake/scripts/makeFiles b/wmake/scripts/makeFiles
index f0423240c37..acda08ccaf7 100755
--- a/wmake/scripts/makeFiles
+++ b/wmake/scripts/makeFiles
@@ -28,43 +28,36 @@
 #
 # Description
 #     Scan the current directory for source files and construct Make/files
-#     It has to be written in the C-shell rather than the Bourne shell
-#     because it uses file name manipulators.
 #
 #     Usage : makeFiles
 #
 #------------------------------------------------------------------------------
 
-if [ -r "Make/files" ]
+if [ -r Make/files ]
 then
-    echo "makeFiles: Make/files already exists, exiting"
-    exit 1
-fi
-
-
-if [ ! -d "Make" ]
-then
-    mkdir Make
+   echo "makeFiles: Make/files already exists, exiting"
+   exit 1
 fi
 
 rulesPath=$WM_DIR/rules/$WM_ARCH$WM_COMPILER
 
+[ -d Make ] || mkdir Make
 rm -f Make/files
 
 dirs=`find . -name "*" -type d -print`
 
 for dir in $dirs
 do
-	if [ $dir != "." ]
-	then
-        baseDirName=`echo $dir | sed 's%^\./%%' | $rulesPath/dirToString`
-        baseDir=`echo $dir | sed 's%^\./%%'`
+   if [ $dir != . ]
+   then
+      baseDirName=`echo $dir | sed 's%^\./%%' | $rulesPath/dirToString`
+      baseDir=`echo $dir | sed 's%^\./%%'`
 
-        if [ $baseDirName != "Make" ]
-        then
-            echo $baseDirName " = " $baseDir >> Make/files
-        fi
-	fi
+      if [ $baseDirName != Make ]
+      then
+         echo $baseDirName " = " $baseDir >> Make/files
+      fi
+   fi
 done
 
 echo >> Make/files
@@ -86,7 +79,6 @@ done
 
 echo >> Make/files
 
-pwd=`pwd`
-echo 'EXE = $(FOAM_APPBIN)/'${pwd##*/} >> Make/files
+echo 'EXE = $(FOAM_APPBIN)/'${PWD##*/} >> Make/files
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/makeOptions b/wmake/scripts/makeOptions
index 6847125ab92..774df991177 100755
--- a/wmake/scripts/makeOptions
+++ b/wmake/scripts/makeOptions
@@ -28,26 +28,18 @@
 #
 # Description
 #     Scan the current directory for options and construct Make/options
-#     It has to be written in the C-shell rather than the Bourne shell
-#     because it uses file name manipulators.
 #
 #     Usage : makeOptions
 #
 #------------------------------------------------------------------------------
 
-if [ -r "Make/options" ]
+if [ -r Make/options ]
 then
-    echo "makeOptions: Make/options already exists, exiting"
-    exit 1
+   echo "makeOptions: Make/options already exists, exiting"
+   exit 1
 fi
 
-
-if [ ! -d "Make" ]
-then
-    mkdir Make
-fi
-
-rulesPath=$WM_DIR/rules/$WM_ARCH
+[ -d Make ] || mkdir Make
 
 rm -f Make/options
 
diff --git a/wmake/scripts/mkObjectDir b/wmake/scripts/mkObjectDir
index f4a281c6f37..c367a5322f6 100755
--- a/wmake/scripts/mkObjectDir
+++ b/wmake/scripts/mkObjectDir
@@ -27,15 +27,13 @@
 #     mkObjectDir
 #
 # Description
-#     Makes a directory hierachy for the given object file
-#     It has to be written in the C-shell rather than the Bourne shell
-#     because it uses file name manipulators.
+#     Makes a directory hierarchy for the given object file
 #
 #     Usage: mkObjectDir <directory>
 #
 #------------------------------------------------------------------------------
 
-if [ $# = 1 ]
+if [ $# -eq 1 ]
 then
     if [ ! -d ${1%/*} -a $1 != ${1%/*} ]
     then
diff --git a/wmake/wclean b/wmake/wclean
index d9b932bebb4..1ea917eec52 100755
--- a/wmake/wclean
+++ b/wmake/wclean
@@ -54,7 +54,8 @@ USAGE
 }
 
 # provide immediate help
-if [ "$1" = "-h" -o "$1" = "-help" ]; then
+if [ "$1" = "-h" -o "$1" = "-help" ]
+then
    usage
 fi
 
@@ -93,7 +94,7 @@ then
          echo "$Script error"
          echo "    could not change to directory '$dir'"
          exit 1
-      }      
+      }
    fi
 
    # provide some feedback
diff --git a/wmake/wcleanAll b/wmake/wcleanAll
index 4b8fc3cbb03..e7d3477cb7d 100755
--- a/wmake/wcleanAll
+++ b/wmake/wcleanAll
@@ -24,7 +24,7 @@
 #     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 #
 # Script
-#     wmakeAll
+#     wcleanAll
 #
 # Description
 #     script that searches all the directories below the current for the
@@ -32,19 +32,14 @@
 #
 #------------------------------------------------------------------------------
 
-if [ ! -d bin -o ! -d src ]
-then
-   echo $0: not in the project top level directory !
+[ -d bin -a -d src ] || {
+   echo "${0##*/}: not in the project top level directory"
    exit 1
-fi
-
+}
 
 for dir in lib applications/bin
 do
-   if [ -d $dir ]
-   then
-      rm -rf $dir/*
-   fi
+   [ -d $dir ] && rm -rf $dir/*
 done
 
 ( cd tutorials && ./Allclean )
diff --git a/wmake/wcleanAlmostAll b/wmake/wcleanAlmostAll
index 8ceaaf7865b..515c3110d85 100755
--- a/wmake/wcleanAlmostAll
+++ b/wmake/wcleanAlmostAll
@@ -32,18 +32,14 @@
 #
 #------------------------------------------------------------------------------
 
-if [ ! -d bin -o ! -d src ]
-then
-   echo $0: not in the project top level directory !
+[ -d bin -a -d src ] || {
+   echo "${0##*/}: not in the project top level directory"
    exit 1
-fi
-
+}
 
 for dir in lib applications/bin
 do
-   if [ -d $dir ]
-      rm -rf $dir/*
-   fi
+   [ -d $dir ] && rm -rf $dir/*
 done
 
 ( cd tutorials && ./Allclean )
diff --git a/wmake/wcleanMachine b/wmake/wcleanMachine
index d3fcfc0c168..a3deba2322c 100755
--- a/wmake/wcleanMachine
+++ b/wmake/wcleanMachine
@@ -27,44 +27,39 @@
 #     wcleanMachine
 #
 # Description
-#     Searches all the directories below the current for the
-#     object file directories of the specified machine and then deletes them.
+#     Searches the directories below the current directory for the object
+#     file directories of the specified machine type(s) and deletes them
 #
-#     Usage: wcleanMachine <machineType>
+#     Usage: wcleanMachine <machineType> [ .. <machineTypeN> ]
 #
 #------------------------------------------------------------------------------
 
-if [ $# = 0 ]
+if [ $# -eq 0 ]
 then
-   echo $0: wcleanMachine : Machine type expected, exiting !
+   echo "${0##*/}: Machine type(s) expected, exiting !"
    exit 1
 fi
 
-
-if [ ! -d lib -o ! -d src ]
-then
-   echo $0: not in the project top level directory !
+[ -d lib -a -d src ] || {
+   echo "${0##*/}: not in the project top level directory !"
    exit 1
-fi
+}
 
-find `find . -depth \( -name "Make.[A-Za-z]*" -o -name "Make" \) -type d -print` \
-    -depth \( -type d -name "*$1" -o -name "*$1$WM_MPLIB" \) -exec rm -r {} \;
 
-#find . -depth -type d \( -name ii_files -o -name Templates.DB \) -exec rm -rf {} \;
+for machType
+do
+   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 {} \;
 
-if [ -d lib/$1 ]
-then
-    rm -r lib/$1
-fi
+   # find . -depth -type d \( -name ii_files -o -name Templates.DB \) -exec rm -rf {} \;
 
-if [ applications/bin ]
-then
-    if [ -d applications/bin/$1 ]
-    then
-       rm -r applications/bin/$1
-    fi
-fi
+   for dir in lib/$machType applications/bin/$machType
+   do
+      [ -d $dir ] && rm -r $dir
+   done
 
+done
 
 #------------------------------------------------------------------------------
diff --git a/wmake/wmakeDerivedFiles b/wmake/wmakeDerivedFiles
index a88c85900e9..e4fd037a257 100755
--- a/wmake/wmakeDerivedFiles
+++ b/wmake/wmakeDerivedFiles
@@ -32,14 +32,17 @@
 #
 #------------------------------------------------------------------------------
 
-if [ ! -d $WM_OPTIONS ]
+if [ ! -d "$WM_OPTIONS" ]
 then
-    echo The $WM_OPTIONS directory does not exist, exiting \!
+    echo "The $WM_OPTIONS directory does not exist, exiting"
     exit 1
 fi
 
 # change to the $WM_OPTIONS directory
-cd $WM_OPTIONS
+cd $WM_OPTIONS 2>/dev/null || {
+   echo "Could not change to directory '$WM_OPTIONS'"
+   exit 1
+}
 
 # Find and keep macro definitions in files list
 grep "=" files > filesMacros
@@ -141,5 +144,4 @@ rm files.$$
 
 cd ..
 
-
 #------------------------------------------------------------------------------
diff --git a/wmake/wmakeFilesAndOptions b/wmake/wmakeFilesAndOptions
index 54ced8b28d7..f65b7c435e1 100755
--- a/wmake/wmakeFilesAndOptions
+++ b/wmake/wmakeFilesAndOptions
@@ -35,48 +35,34 @@
 #------------------------------------------------------------------------------
 Script=${0##*/}
 
-if [ ! "$WM_OPTIONS" ]
-then
-    echo "$Script: environment variable $WM_OPTIONS not set, exiting!"
-    exit 1
-fi
-
-
-if [ ! "$WM_DIR" ]
-then
-    echo "$Script: environment variable $WM_DIR not set"
-    exit 1
-fi
-
-
-if [ ! "$WM_LINK_LANGUAGE" ]
-then
-    echo "$Script: environment variable $WM_LINK_LANGUAGE not set"
-    exit 1
-fi
-
+#
+# check environment variables
+#
+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
+   }
+done
 
-if [ -d "Make" ]
+if [ -d Make ]
 then
-    echo "$Script: Make directory already exists"
-    exit 1
+   echo "$Script: Make directory already exists"
+   exit 1
 else
-    mkdir Make
-fi
-
-
-if [ ! -e "Make/files"  ]
-then
-    echo "$Script: Creating files"
-    $WM_DIR/scripts/makeFiles
+   mkdir Make
 fi
 
+[ -e Make/files ] || {
+   echo "$Script: Creating files"
+   $WM_DIR/scripts/makeFiles
+}
 
-if [ ! -e "Make/options"  ]
-then
-    echo "$Script: Creating options"
-    $WM_DIR/scripts/makeOptions
-fi
-
+[ -e Make/options ] || {
+   echo "$Script: Creating options"
+   $WM_DIR/scripts/makeOptions
+}
 
 #------------------------------------------------------------------------------
-- 
GitLab