From 973a9400285c431bf3353577b67176139ce48d63 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 22 Nov 2018 09:35:17 +0100
Subject: [PATCH] COMP: provide Allmake script for wmake tools

- convenient when bootstrapping some systems
---
 Allwmake                     |  4 +--
 wmake/scripts/makeFiles      | 18 +++++++++++---
 wmake/scripts/makeOptions    | 16 ++++++++++--
 wmake/scripts/wmakeFunctions |  2 +-
 wmake/src/Allmake            |  9 +++++++
 wmake/wmakeFilesAndOptions   | 47 ++++++++++++------------------------
 6 files changed, 57 insertions(+), 39 deletions(-)
 create mode 100755 wmake/src/Allmake

diff --git a/Allwmake b/Allwmake
index 702d3c3ff05..fd6c8acc2c2 100755
--- a/Allwmake
+++ b/Allwmake
@@ -30,8 +30,8 @@ echo "  ${WM_OPTIONS}, with ${WM_MPLIB} ${FOAM_MPI}"
 echo "========================================"
 echo
 
-# Compile wmake tools
-(cd "${WM_DIR:-wmake}/src" && make)
+# Compile tools for wmake
+"${WM_DIR:?}"/src/Allmake
 
 # Compile ThirdParty libraries and applications
 if [ -d "$WM_THIRD_PARTY_DIR" ]
diff --git a/wmake/scripts/makeFiles b/wmake/scripts/makeFiles
index 6cea689aac6..07806c92387 100755
--- a/wmake/scripts/makeFiles
+++ b/wmake/scripts/makeFiles
@@ -7,8 +7,20 @@
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM.
+#
+#     OpenFOAM is free software: you can redistribute it and/or modify it
+#     under the terms of the GNU General Public License as published by
+#     the Free Software Foundation, either version 3 of the License, or
+#     (at your option) any later version.
+#
+#     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+#     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+#     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+#     for more details.
+#
+#     You should have received a copy of the GNU General Public License
+#     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 #
 # Script
 #     makeFiles
@@ -19,7 +31,7 @@
 #     Usage : makeFiles
 #
 #------------------------------------------------------------------------------
-dirToString=$WM_DIR/platforms/$WM_ARCH$WM_COMPILER/dirToString
+dirToString="$WM_DIR/platforms/$WM_ARCH$WM_COMPILER"/dirToString
 
 if [ -r Make/files ]
 then
diff --git a/wmake/scripts/makeOptions b/wmake/scripts/makeOptions
index 6101889ec5a..db1585485dd 100755
--- a/wmake/scripts/makeOptions
+++ b/wmake/scripts/makeOptions
@@ -7,8 +7,20 @@
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM.
+#
+#     OpenFOAM is free software: you can redistribute it and/or modify it
+#     under the terms of the GNU General Public License as published by
+#     the Free Software Foundation, either version 3 of the License, or
+#     (at your option) any later version.
+#
+#     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+#     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+#     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+#     for more details.
+#
+#     You should have received a copy of the GNU General Public License
+#     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 #
 # Script
 #     makeOptions
diff --git a/wmake/scripts/wmakeFunctions b/wmake/scripts/wmakeFunctions
index d25a8811673..b4800baeaf9 100644
--- a/wmake/scripts/wmakeFunctions
+++ b/wmake/scripts/wmakeFunctions
@@ -30,7 +30,7 @@ checkEnv()
     for check in WM_PROJECT_DIR WM_OPTIONS WM_DIR
     do
         eval test "\$$check" || {
-            echo "$Script error: environment variable \$$check not set" 1>&2
+            echo "$Script error: Environment variable \$$check not set" 1>&2
             exit 1
         }
     done
diff --git a/wmake/src/Allmake b/wmake/src/Allmake
new file mode 100755
index 00000000000..2505c3c414b
--- /dev/null
+++ b/wmake/src/Allmake
@@ -0,0 +1,9 @@
+#!/bin/sh
+cd "${0%/*}" || exit 1                      # Run from this directory
+[ -d "${WM_DIR:?}" ] || exit 1              # Require WM_DIR
+
+# Compile tools for wmake
+
+make
+
+#------------------------------------------------------------------------------
diff --git a/wmake/wmakeFilesAndOptions b/wmake/wmakeFilesAndOptions
index 488a80add9c..19bb5858064 100755
--- a/wmake/wmakeFilesAndOptions
+++ b/wmake/wmakeFilesAndOptions
@@ -26,7 +26,7 @@
 #     wmakeFilesAndOptions
 #
 # Usage
-#     wmakeFilesAndOptions
+#     wmakeFilesAndOptions [-help]
 #
 # Description
 #     Scan current directory for directories and source files
@@ -39,32 +39,28 @@ usage() {
     while [ "$#" -ge 1 ]; do echo "$1"; shift; done
     cat<<USAGE
 
-Usage: $Script
+Usage: $Script [-help]
 
-    Scan current directory for directories and source files
-    and construct 'Make/files' and 'Make/options'
+Scans current directory for directories and source files and constructs
+the 'Make/files' and 'Make/options' files.
 
 USAGE
     exit 1
 }
 
+# Find -help anywhere
+for i
+do
+    case "$i" in (-h | -help*) usage ;; esac
+done
 
-#------------------------------------------------------------------------------
-# Parse arguments and options
 #------------------------------------------------------------------------------
 
-while [ "$#" -gt 0 ]
-do
-    case "$1" in
-    -h | -help*)   # Provide immediate help
-        usage
-        ;;
-    *)
-        # No options/arguments
-        usage "unexpected options/arguments: $*"
-        ;;
-    esac
-done
+# No options/arguments
+[ "$#" -eq 0 ] || {
+    echo "$Script error: Unexpected options/arguments: $*" 1>&2
+    exit 1
+}
 
 if [ -e Make ]
 then
@@ -72,20 +68,9 @@ then
     exit 1
 fi
 
-#------------------------------------------------------------------------------
-# Check environment variables
-#------------------------------------------------------------------------------
-for check in WM_DIR WM_ARCH WM_COMPILER
-do
-    eval test "\$$check" || {
-        echo "$Script error: environment variable \$$check not set" 1>&2
-        exit 1
-    }
-done
-
 mkdir Make
-[ -e Make/files ]   || $WM_DIR/scripts/makeFiles
-[ -e Make/options ] || $WM_DIR/scripts/makeOptions
+[ -e Make/files ]   || "${0%/*}"/scripts/makeFiles
+[ -e Make/options ] || "${0%/*}"/scripts/makeOptions
 
 exit 0 # clean exit
 
-- 
GitLab