From b0fafd18fe679ba779e720dcaf26796021dd47ba Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Sat, 26 Jan 2019 11:30:50 +0100
Subject: [PATCH] STYLE: reorganize some legacy and less frequently used
 components

- older emacs tools into legacy
- old process tools

* Less frequently used scripts into bin/tools/

  - findEmptyMake
  - foamAllHC
  - foamUpdateCaseFileHeader

* Infrastructure file (only used by foamNewApp)

  - wmake/wmakeFilesAndOptions -> wmake/scripts/wmakeFilesAndOptions

* Merge wmakeRoot convenience as 'wmake -pwd'
* Remove obsolete wmakePrintBuild (superseded by wmakeBuildInfo)
* Remove unused mergeHistory file
---
 bin/{ => legacy}/foamEbrowse                  |   0
 bin/{ => legacy}/foamProcessInfo              |   0
 bin/{ => legacy}/foamTags                     |   0
 bin/{ => legacy}/org-html                     |   0
 bin/{ => legacy}/org-latex                    |   0
 bin/{ => legacy}/org-pdflatex                 |   0
 bin/{ => legacy}/tools/foamListBinDirs        |   0
 bin/{ => legacy}/tools/foamListSourceFiles    |   0
 .../tools/foamListThirdPartyBinDirs           |   0
 bin/{ => legacy}/tools/gtagsrc                |   0
 bin/{ => legacy}/tools/org-batch              |   0
 bin/{ => tools}/findEmptyMake                 |   0
 bin/{ => tools}/foamAllHC                     |   0
 bin/{ => tools}/foamUpdateCaseFileHeader      |   0
 etc/codeTemplates/source/foamNewSource        |   2 +-
 etc/mergeHistory                              |   2 -
 wmake/{ => scripts}/wmakeFilesAndOptions      |   4 +-
 wmake/wmake                                   |  94 +++++--
 wmake/wmakeLnInclude                          |  16 +-
 wmake/wmakePrintBuild                         | 260 ------------------
 wmake/wmakeRoot                               | 113 --------
 21 files changed, 79 insertions(+), 412 deletions(-)
 rename bin/{ => legacy}/foamEbrowse (100%)
 rename bin/{ => legacy}/foamProcessInfo (100%)
 rename bin/{ => legacy}/foamTags (100%)
 rename bin/{ => legacy}/org-html (100%)
 rename bin/{ => legacy}/org-latex (100%)
 rename bin/{ => legacy}/org-pdflatex (100%)
 rename bin/{ => legacy}/tools/foamListBinDirs (100%)
 rename bin/{ => legacy}/tools/foamListSourceFiles (100%)
 rename bin/{ => legacy}/tools/foamListThirdPartyBinDirs (100%)
 rename bin/{ => legacy}/tools/gtagsrc (100%)
 rename bin/{ => legacy}/tools/org-batch (100%)
 rename bin/{ => tools}/findEmptyMake (100%)
 rename bin/{ => tools}/foamAllHC (100%)
 rename bin/{ => tools}/foamUpdateCaseFileHeader (100%)
 delete mode 100644 etc/mergeHistory
 rename wmake/{ => scripts}/wmakeFilesAndOptions (95%)
 delete mode 100755 wmake/wmakePrintBuild
 delete mode 100755 wmake/wmakeRoot

diff --git a/bin/foamEbrowse b/bin/legacy/foamEbrowse
similarity index 100%
rename from bin/foamEbrowse
rename to bin/legacy/foamEbrowse
diff --git a/bin/foamProcessInfo b/bin/legacy/foamProcessInfo
similarity index 100%
rename from bin/foamProcessInfo
rename to bin/legacy/foamProcessInfo
diff --git a/bin/foamTags b/bin/legacy/foamTags
similarity index 100%
rename from bin/foamTags
rename to bin/legacy/foamTags
diff --git a/bin/org-html b/bin/legacy/org-html
similarity index 100%
rename from bin/org-html
rename to bin/legacy/org-html
diff --git a/bin/org-latex b/bin/legacy/org-latex
similarity index 100%
rename from bin/org-latex
rename to bin/legacy/org-latex
diff --git a/bin/org-pdflatex b/bin/legacy/org-pdflatex
similarity index 100%
rename from bin/org-pdflatex
rename to bin/legacy/org-pdflatex
diff --git a/bin/tools/foamListBinDirs b/bin/legacy/tools/foamListBinDirs
similarity index 100%
rename from bin/tools/foamListBinDirs
rename to bin/legacy/tools/foamListBinDirs
diff --git a/bin/tools/foamListSourceFiles b/bin/legacy/tools/foamListSourceFiles
similarity index 100%
rename from bin/tools/foamListSourceFiles
rename to bin/legacy/tools/foamListSourceFiles
diff --git a/bin/tools/foamListThirdPartyBinDirs b/bin/legacy/tools/foamListThirdPartyBinDirs
similarity index 100%
rename from bin/tools/foamListThirdPartyBinDirs
rename to bin/legacy/tools/foamListThirdPartyBinDirs
diff --git a/bin/tools/gtagsrc b/bin/legacy/tools/gtagsrc
similarity index 100%
rename from bin/tools/gtagsrc
rename to bin/legacy/tools/gtagsrc
diff --git a/bin/tools/org-batch b/bin/legacy/tools/org-batch
similarity index 100%
rename from bin/tools/org-batch
rename to bin/legacy/tools/org-batch
diff --git a/bin/findEmptyMake b/bin/tools/findEmptyMake
similarity index 100%
rename from bin/findEmptyMake
rename to bin/tools/findEmptyMake
diff --git a/bin/foamAllHC b/bin/tools/foamAllHC
similarity index 100%
rename from bin/foamAllHC
rename to bin/tools/foamAllHC
diff --git a/bin/foamUpdateCaseFileHeader b/bin/tools/foamUpdateCaseFileHeader
similarity index 100%
rename from bin/foamUpdateCaseFileHeader
rename to bin/tools/foamUpdateCaseFileHeader
diff --git a/etc/codeTemplates/source/foamNewSource b/etc/codeTemplates/source/foamNewSource
index 0e36c4adb49..d3ecd7aaea9 100755
--- a/etc/codeTemplates/source/foamNewSource
+++ b/etc/codeTemplates/source/foamNewSource
@@ -110,7 +110,7 @@ else
 
     if [ "$subType" = App -a ! -d Make ]
     then
-        "${WM_DIR:-$WM_PROJECT_DIR/wmake}/wmakeFilesAndOptions"
+        "${WM_DIR:-$WM_PROJECT_DIR/wmake}/scripts/wmakeFilesAndOptions"
     fi
 fi
 
diff --git a/etc/mergeHistory b/etc/mergeHistory
deleted file mode 100644
index b825a958efe..00000000000
--- a/etc/mergeHistory
+++ /dev/null
@@ -1,2 +0,0 @@
-Date        SHA1     Commit message
-2015-12-02  9a536b0  fvOptions: Reorganized and updated to simplify use in sub-models and maintenance
diff --git a/wmake/wmakeFilesAndOptions b/wmake/scripts/wmakeFilesAndOptions
similarity index 95%
rename from wmake/wmakeFilesAndOptions
rename to wmake/scripts/wmakeFilesAndOptions
index 19bb5858064..8e311a0f21b 100755
--- a/wmake/wmakeFilesAndOptions
+++ b/wmake/scripts/wmakeFilesAndOptions
@@ -69,8 +69,8 @@ then
 fi
 
 mkdir Make
-[ -e Make/files ]   || "${0%/*}"/scripts/makeFiles
-[ -e Make/options ] || "${0%/*}"/scripts/makeOptions
+[ -e Make/files ]   || "${0%/*}/makeFiles"
+[ -e Make/options ] || "${0%/*}/makeOptions"
 
 exit 0 # clean exit
 
diff --git a/wmake/wmake b/wmake/wmake
index 81b32ab5480..47a1b40327e 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -72,6 +72,7 @@ options:
   -j                Compile using all local cores/hyperthreads
   -jN or -j N       Compile using N cores/hyperthreads
   -no-scheduler     Disable scheduled parallel compilation
+  -pwd              Print root directory containing a Make/ directory and exit
   -update           Update lnInclude directories, dep files, remove deprecated
                     files and directories
   -h | -help        Print the usage
@@ -118,7 +119,7 @@ allCores()
 #------------------------------------------------------------------------------
 
 # Default to compiling the local target only
-unset all update
+unset all update optPrintRootDir
 
 while [ "$#" -gt 0 ]
 do
@@ -159,6 +160,10 @@ do
         -no-scheduler)
             unset WM_SCHEDULER
             ;;
+        # Print root directory containing a Make/ directory and exit
+        -pwd)
+            optPrintRootDir=true
+            ;;
         # Meant to be used following a pull, this will:
         # - remove dep files that depend on deleted files;
         # - remove stale dep files;
@@ -224,42 +229,79 @@ fi
 unset targetType
 MakeDir=Make
 
-if [ $# -ge 1 ]
+unset dir
+
+if [ -n "$optPrintRootDir" ]
 then
-    unset dir
-    if [ -d "$1" ]
+    if [ $# -ge 1 ]
     then
-        dir="${1%/}"
-    elif [ -f "$1" ]
-    then
-        dir="${1%/*}"
-        : "${dir:=.}"
-    else
-        targetType="$1"
-    fi
-
-    # Specified directory name:
-    [ $# -ge 2 ] && dir="${2%/}"
-
-    # Specified alternative name for the Make sub-directory:
-    [ $# -ge 3 ] && MakeDir="${3%/}"
+        if [ -d "$1" ]
+        then
+            dir="${1%/}"
+        elif [ -f "$1" ]
+        then
+            dir="${1%/*}"
+            : "${dir:=.}"
+        else
+            echo "$Script error: not a file or directory" 1>&2
+            exit 1
+        fi
 
-    if [ -n "$dir" ]
-    then
-        cd $dir 2>/dev/null || {
+        cd "$dir" 2>/dev/null || {
             echo "$Script error: could not change to directory '$dir'" 1>&2
             exit 1
         }
-    elif [ -f "$MakeDir/files" ]
+    fi
+
+    # Locate target with Make/ directory
+    if dir="$(findTarget .)"
     then
-        dir="(${PWD##*/})"  # Implicit directory information
+        (cd "$dir" && pwd -L)
+        exit 0
+    else
+        exit 2
     fi
 
-    # Print command
-    echo "$Script $targetType${targetType:+ }$dir"
-    unset dir
+else
+
+    if [ $# -ge 1 ]
+    then
+        if [ -d "$1" ]
+        then
+            dir="${1%/}"
+        elif [ -f "$1" ]
+        then
+            dir="${1%/*}"
+            : "${dir:=.}"
+        else
+            targetType="$1"
+        fi
+
+        # Specified directory name:
+        [ $# -ge 2 ] && dir="${2%/}"
+
+        # Specified alternative name for the Make sub-directory:
+        [ $# -ge 3 ] && MakeDir="${3%/}"
+
+        if [ -n "$dir" ]
+        then
+            cd $dir 2>/dev/null || {
+                echo "$Script error: could not change to directory '$dir'" 1>&2
+                exit 1
+            }
+        elif [ -f "$MakeDir/files" ]
+        then
+            dir="(${PWD##*/})"  # Implicit directory information
+        fi
+
+        # Print command
+        echo "$Script $targetType${targetType:+ }$dir"
+        unset dir
+    fi
 fi
 
+unset dir
+
 
 #------------------------------------------------------------------------------
 # Recurse the source tree to update all
diff --git a/wmake/wmakeLnInclude b/wmake/wmakeLnInclude
index efae4f3a685..02f968bdfd1 100755
--- a/wmake/wmakeLnInclude
+++ b/wmake/wmakeLnInclude
@@ -26,7 +26,7 @@
 #     wmakeLnInclude
 #
 # Usage
-#     wmakeLnInclude [OPTION] [-root | <dir>]
+#     wmakeLnInclude [OPTION] [-pwd | <dir>]
 #
 # Description
 #     Link all the source files in the <dir> directory into <dir>/lnInclude
@@ -46,12 +46,12 @@ usage() {
     while [ "$#" -ge 1 ]; do echo "$1"; shift; done
     cat<<USAGE
 
-Usage: $Script [OPTION] [-root | dir]
+Usage: $Script [OPTION] [-pwd | dir]
 
 options:
   -u | -update      Update
   -s | -silent      Use 'silent' mode (do not echo command)
-  -root             Locate root directory containing a Make/ directory.
+  -pwd              Locate root directory containing a Make/ directory.
   -h | -help        Print the usage
 
 Link all the source files in the <dir> into <dir>/lnInclude
@@ -72,7 +72,7 @@ USAGE
 # Option for 'ln'
 optLink="-s"
 
-unset update optQuiet optRoot
+unset update optQuiet optFindRootDir
 
 while [ "$#" -gt 0 ]
 do
@@ -87,8 +87,8 @@ do
         -s | -silent)
             optQuiet=true
             ;;
-        -root)
-            optRoot=true
+        -pwd)
+            optFindRootDir=true
             ;;
         -*)
             usage "unknown option: '$1'"
@@ -100,7 +100,7 @@ do
     shift
 done
 
-[ "$optRoot" = true ] || [ "$#" -eq 1 ] || \
+[ "$optFindRootDir" = true ] || [ "$#" -eq 1 ] || \
     usage "Error: incorrect number of arguments"
 
 #------------------------------------------------------------------------------
@@ -109,7 +109,7 @@ unset dir
 baseDir="$1"
 
 # With -root, go on discovery
-if [ "$optRoot" = true ]
+if [ "$optFindRootDir" = true ]
 then
     if [ -n "$baseDir" ]
     then
diff --git a/wmake/wmakePrintBuild b/wmake/wmakePrintBuild
deleted file mode 100755
index bafd96bb6c9..00000000000
--- a/wmake/wmakePrintBuild
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/bin/sh
-#------------------------------------------------------------------------------
-# =========                 |
-# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-#  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
-#-------------------------------------------------------------------------------
-# License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
-#
-# Script
-#     wmakePrintBuild
-#
-# Description
-#     Print the version used when building the project
-#
-#------------------------------------------------------------------------------
-# Environment defaults
-: "${WM_DIR:-$WM_PROJECT_DIR/wmake}"
-
-#--------
-usage() {
-    exec 1>&2
-
-    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
-    cat<<USAGE
-Usage: ${0##*/} [OPTION]
-options:
-  -check          check the git head commit vs. \$WM_PROJECT_DIR/.build
-                  (exit code 0 for no changes)
-  -major          report \$WM_PROJECT_VERSION only and exit
-  -update         update \$WM_PROJECT_DIR/.build from the git information
-  -pkg TAG        specify packager/release tag ('none' marks an empty packager)
-  -short          report short version information (ie, without pkg tag)
-  -version VER    specify an alternative version
-  -api            report wmake value of OPENFOAM/OPENFOAM_API/OPENFOAM_PLUS
-  -help
-
-Print the version used when building the project, in this order of precedence:
-  * the git head commit
-  * \$WM_PROJECT_DIR/.build
-  * \$WM_PROJECT_VERSION
-
-USAGE
-    exit 1
-}
-
-# Report error and exit
-die()
-{
-    exec 1>&2
-    echo
-    echo "Error encountered:"
-    while [ "$#" -ge 1 ]; do echo "    $1"; shift; done
-    echo
-    echo "See '${0##*/} -help' for usage"
-    echo
-    exit 1
-}
-
-
-#------------------------------------------------------------------------------
-
-cat << WARN_OBSOLETE 1>&2
-###############################################################################
-##        The wmakePrintBuild utility is OBSOLETE (Dec-2018).                ##
-##        The wmakeBuildInfo utility is to be used instead.                  ##
-###############################################################################
-
-WARN_OBSOLETE
-
-
-#------------------------------------------------------------------------------
-# Parse arguments and options
-#------------------------------------------------------------------------------
-unset checkOnly update package version optApi optShort
-
-while [ "$#" -gt 0 ]
-do
-    case "$1" in
-    -h | -help*)
-        usage
-        ;;
-    -c | -check)
-        checkOnly=true
-        ;;
-    -major)
-        echo ${WM_PROJECT_VERSION:-unknown}
-        exit 0
-        ;;
-    -u | -update)
-        update=true
-        ;;
-    -pkg | -package)
-        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
-        # Mark empty as 'none', disallow '!' in string
-        package=$(echo "${2:-none}" | sed -e 's/!//g')
-        shift
-        ;;
-    -short)
-        optShort=true
-        ;;
-    -v | -version)
-        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
-        version="$2"
-        shift
-        ;;
-    -api | -plus)
-        optApi=true
-        break
-        ;;
-    *)
-        die "unknown option/argument: '$1'"
-        ;;
-    esac
-    shift
-done
-
-#------------------------------------------------------------------------------
-
-# Persistent build tag
-build="$WM_PROJECT_DIR/.build"
-
-#------------------------------------------------------------------------------
-# Retrieve old values from the $WM_PROJECT_DIR/.build cache, stored as
-#     version [packager]
-#------------------------------------------------------------------------------
-unset oldPackage oldVersion
-getOldValues()
-{
-    set -- $(tail -1 $build 2>/dev/null)
-    oldVersion="$1"
-    [ "$#" -gt 0 ] && shift
-    oldPackage="$@"
-    [ "${oldPackage:-none}" = none ] && unset oldPackage
-}
-
-#------------------------------------------------------------------------------
-# printTag - output the build tag, reuses the old -package tag if needed
-#------------------------------------------------------------------------------
-printTag()
-{
-    if [ "${package:-${oldPackage:-none}}" = none ]
-    then
-        echo "$version"
-    else
-        echo "$version ${package:-$oldPackage}"
-    fi
-}
-
-
-#------------------------------------------------------------------------------
-# Get the version
-#------------------------------------------------------------------------------
-
-if [ -n "$optApi" ]
-then
-    # Extract API version from $WM_DIR/rules/General/general
-    # Any of OPENFOAM=<digits>, OPENFOAM_API=<digits>, OPENFOAM_COM=<digits>
-    # OPENFOAM_PLUS=<digits>
-    version=$(
-        sed -ne 's@^.*OPENFOAM\(_API\|_COM\|_PLUS\)*=\([0-9][0-9]*\).*@\2@p' \
-        $WM_DIR/rules/General/general 2>/dev/null
-    )
-
-    if [ -n "$version" ]
-    then
-        echo "$version"
-        exit 0
-    else
-        echo "no wmake definition for OPENFOAM API" 1>&2
-        exit 1
-    fi
-elif [ -n "$version" ]
-then
-    # Specified a version - no error possible
-    rc=0
-else
-
-    # Abbrev commit hash + data
-    # Date format (YYMMDD) for authoring of the commit
-    version="$(git --git-dir=$WM_PROJECT_DIR/.git log -1 --date='format:%y%m%d' --format='%h-%ad' 2>/dev/null)"
-
-    test -n "$version"
-    rc=$?
-fi
-
-
-# Retrieve old values (oldPackage oldVersion)
-getOldValues
-
-if [ -n "$optShort" ]
-then
-    unset package oldPackage
-fi
-
-
-#------------------------------------------------------------------------------
-# Update persistent build tag if possible
-#------------------------------------------------------------------------------
-if [ $rc -eq 0 -a -n "$update" ]
-then
-    if [ "$version:$package" != "$oldVersion:$oldPackage" ]
-    then
-        if [ -w "$build" -o \( -w "$WM_PROJECT_DIR" -a ! -e "$build" \) ]
-        then
-            printTag >| "$build" 2>/dev/null
-        fi
-    fi
-fi
-
-
-#------------------------------------------------------------------------------
-# Check git vs. persistent build tag
-#------------------------------------------------------------------------------
-if [ -n "$checkOnly" ]
-then
-    if [ $rc -eq 0 ]
-    then
-        test "$version:${package:-$oldPackage}" = "$oldVersion:$oldPackage"
-        rc=$?
-        if [ $rc -eq 0 ]
-        then
-            echo "same version as previous build" 1>&2
-        else
-            echo "version changed from previous build" 1>&2
-        fi
-        exit $rc
-    else
-        echo "no git description found" 1>&2
-        exit 0
-    fi
-fi
-
-
-#------------------------------------------------------------------------------
-# Cannot get git information or  -version version
-#------------------------------------------------------------------------------
-if [ $rc -ne 0 ]
-then
-    if [ -n "$oldVersion" ]
-    then
-        # Use previous version info
-        version="$oldVersion"
-    else
-        # Fallback to WM_PROJECT_VERSION alone
-        version="${WM_PROJECT_VERSION:-unknown}"
-    fi
-fi
-
-
-#------------------------------------------------------------------------------
-# Output the tag
-#------------------------------------------------------------------------------
-printTag
-
-
-#------------------------------------------------------------------------------
diff --git a/wmake/wmakeRoot b/wmake/wmakeRoot
deleted file mode 100755
index 4789c4bf961..00000000000
--- a/wmake/wmakeRoot
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/sh
-#------------------------------------------------------------------------------
-# =========                 |
-# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-#  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
-#    \\/     M anipulation  |
-#-------------------------------------------------------------------------------
-# License
-#     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
-#     wmakeRoot
-#
-# Description
-#     Locate the root directory that has a Make/ directory.
-#
-# See Also
-#     wmake
-#
-#------------------------------------------------------------------------------
-Script="${0##*/}"           # Use 'Script' for error messages in wmakeFunctions
-. "${0%/*}/scripts/wmakeFunctions"              # Source wmake functions
-
-usage() {
-    exec 1>&2
-    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
-    cat<<USAGE
-
-Usage: $Script [OPTION] [dir]
-
-options:
-  -h | -help        Print the usage
-
-Locate the root directory that has a Make/ directory.
-
-USAGE
-    exit 1
-}
-
-#------------------------------------------------------------------------------
-# Parse arguments and options
-#------------------------------------------------------------------------------
-
-while [ "$#" -gt 0 ]
-do
-    case "$1" in
-    -h | -help*)
-        usage
-        ;;
-    --)
-        shift
-        break
-        ;;
-    -*)
-        usage "unknown option: '$1'"
-        ;;
-    *)
-        break
-        ;;
-    esac
-    shift
-done
-
-#------------------------------------------------------------------------------
-
-unset dir
-
-if [ $# -ge 1 ]
-then
-    if [ -d "$1" ]
-    then
-        dir="${1%/}"
-    elif [ -f "$1" ]
-    then
-        dir="${1%/*}"
-        : "${dir:=.}"
-    else
-        echo "$Script error: not a file or directory" 1>&2
-        exit 1
-    fi
-
-    cd "$dir" 2>/dev/null || {
-        echo "$Script error: could not change to directory '$dir'" 1>&2
-        exit 1
-    }
-fi
-
-
-# Locate target with Make/ directory
-
-if dir="$(findTarget .)"
-then
-    (cd "$dir" && pwd -L)
-else
-    exit 2
-fi
-
-
-#------------------------------------------------------------------------------
-- 
GitLab