From b4d38ab4687c4ac5e56253eb12310f0a198a7a8f Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 24 Apr 2018 14:51:19 +0200
Subject: [PATCH] ENH: improve handling of ThirdParty packages

- generalize some of the library extensions (.so vs .dylib).
  Provide as wmake 'sysFunctions'

- added note about unsupported/incomplete system support

- centralize detection of ThirdParty packages into wmake/ subdirectory
  by providing a series of scripts in the spirit of GNU autoconfig.
  For example,

      have_boost, have_readline, have_scotch, ...

  Each of the `have_<package>` scripts will generally provide the
  following type of functions:

      have_<package>          # detection
      no_<package>            # reset
      echo_<package>          # echoing

  and the following type of variables:

      HAVE_<package>          # unset or 'true'
      <package>_ARCH_PATH     # root for <package>
      <package>_INC_DIR       # include directory for <package>
      <package>_LIB_DIR       # library directory for <package>

  This simplifies the calling scripts:

      if have_metis
      then
          wmake metisDecomp
      fi

  As well as reducing clutter in the corresponding Make/options:

      EXE_INC = \
          -I$(METIS_INC_DIR) \
          -I../decompositionMethods/lnInclude

      LIB_LIBS = \
          -L$(METIS_LIB_DIR) -lmetis

  Any additional modifications (platform-specific or for an external build
  system) can now be made centrally.
---
 Allwmake                                      |   1 -
 applications/Allwmake                         |   1 -
 applications/solvers/DNS/dnsFoam/Allwmake     |   8 +-
 .../compressible/rhoCentralFoam/Allwmake      |   4 +-
 .../solvers/lagrangian/DPMFoam/Allwmake       |   6 +-
 .../multiphase/MPPICInterFoam/Allwmake        |   4 +-
 .../multiphase/compressibleInterFoam/Allwmake |   6 +-
 .../compressibleMultiphaseInterFoam/Allwmake  |   6 +-
 .../solvers/multiphase/driftFluxFoam/Allwmake |   6 +-
 .../interCondensatingEvaporatingFoam/Allwmake |   8 +-
 .../multiphase/interPhaseChangeFoam/Allwmake  |   6 +-
 .../multiphase/multiphaseEulerFoam/Allwmake   |   6 +-
 .../multiphase/multiphaseInterFoam/Allwmake   |   6 +-
 .../multiphase/reactingEulerFoam/Allwmake     |   6 +-
 .../reactingMultiphaseEulerFoam/Allwmake      |   6 +-
 .../reactingTwoPhaseEulerFoam/Allwmake        |   6 +-
 .../multiphase/twoPhaseEulerFoam/Allwmake     |   6 +-
 .../utilities/mesh/conversion/ccm/Allwmake    |  13 +-
 .../utilities/mesh/generation/Allwmake        |   7 +-
 .../mesh/generation/extrude2DMesh/Allwmake    |   6 +-
 .../mesh/generation/foamyMesh/Allwmake        |  18 +-
 .../foamyHexMeshSurfaceSimplify/Allwmake      |   6 +-
 .../mesh/manipulation/renumberMesh/Allwmake   |  35 +--
 .../manipulation/renumberMesh/renumberMesh.C  |   4 +-
 .../mesh/manipulation/setSet/Allwmake         |  20 +-
 .../mesh/manipulation/setSet/setSet.C         |  14 +-
 .../utilities/miscellaneous/foamHelp/Allwmake |   6 +-
 .../graphics/PVReaders/Allwmake               |   2 +-
 .../graphics/ensightFoamReader/Allwmake       |   6 +-
 .../utilities/postProcessing/noise/Allwmake   |   8 +-
 .../utilities/preProcessing/boxTurb/Allwmake  |   8 +-
 .../preProcessing/wallFunctionTable/Allwmake  |   6 +-
 .../surface/surfaceBooleanFeatures/Allwmake   |   7 +-
 .../surface/surfaceFeatureExtract/Allwmake    |   4 +-
 bin/tools/lib-dir                             |  16 +-
 etc/config.csh/mpi                            |   2 +-
 etc/config.csh/settings                       |  12 +-
 etc/config.sh/functions                       |  25 +-
 etc/config.sh/mpi                             |   2 +-
 etc/config.sh/settings                        |  13 +-
 src/Allwmake                                  |   1 -
 src/OSspecific/POSIX/Allwmake                 |  13 +-
 src/Pstream/Allwmake                          |   4 +-
 src/TurbulenceModels/Allwmake                 |   6 +-
 src/conversion/Allwmake                       |   8 +-
 src/conversion/ccm/Allwmake                   |  39 +--
 src/conversion/ccm/Make/options               |   4 +-
 src/dummyThirdParty/Allwmake                  |   6 +-
 src/functionObjects/Allwmake                  |   6 +-
 src/functionObjects/graphics/Allwmake         |   4 +-
 .../graphics/runTimePostProcessing/Allwmake   |   4 +-
 src/fvAgglomerationMethods/Allwmake           |  84 +------
 .../MGridGenGamgAgglomeration/Make/options    |   7 +-
 src/lagrangian/Allwmake                       |   6 +-
 src/lagrangian/molecularDynamics/Allwmake     |   6 +-
 src/mesh/Allwmake                             |   6 +-
 src/parallel/Allwmake                         |   6 +-
 src/parallel/decompose/Allwmake               | 226 +-----------------
 .../decompose/kahipDecomp/Make/options        |  13 +-
 .../decompose/metisDecomp/Make/options        |  12 +-
 .../decompose/ptscotchDecomp/Make/options     |  11 +-
 .../decompose/scotchDecomp/Make/options       |  14 +-
 src/parallel/reconstruct/Allwmake             |   6 +-
 src/randomProcesses/Allwmake                  |  13 +-
 src/randomProcesses/Make/options              |   8 +-
 src/regionModels/Allwmake                     |   6 +-
 src/renumber/Allwmake                         |  20 +-
 src/renumber/SloanRenumber/Make/options       |   6 +-
 src/renumber/zoltanRenumber/Make/options      |   7 +-
 src/thermophysicalModels/Allwmake             |   6 +-
 src/transportModels/Allwmake                  |   6 +-
 wmake/scripts/have_boost                      | 127 ++++++++++
 wmake/scripts/have_ccmio                      | 145 +++++++++++
 wmake/scripts/have_cgal                       | 127 ++++++++++
 wmake/scripts/have_fftw                       | 125 ++++++++++
 wmake/scripts/have_kahip                      | 138 +++++++++++
 wmake/scripts/have_metis                      | 151 ++++++++++++
 wmake/scripts/have_mgridgen                   | 177 ++++++++++++++
 wmake/scripts/have_readline                   | 101 ++++++++
 wmake/scripts/have_scotch                     | 174 ++++++++++++++
 wmake/scripts/have_zoltan                     | 133 +++++++++++
 wmake/scripts/sysFunctions                    | 110 +++++++++
 82 files changed, 1796 insertions(+), 608 deletions(-)
 create mode 100644 wmake/scripts/have_boost
 create mode 100644 wmake/scripts/have_ccmio
 create mode 100644 wmake/scripts/have_cgal
 create mode 100644 wmake/scripts/have_fftw
 create mode 100644 wmake/scripts/have_kahip
 create mode 100644 wmake/scripts/have_metis
 create mode 100644 wmake/scripts/have_mgridgen
 create mode 100644 wmake/scripts/have_readline
 create mode 100644 wmake/scripts/have_scotch
 create mode 100644 wmake/scripts/have_zoltan
 create mode 100644 wmake/scripts/sysFunctions

diff --git a/Allwmake b/Allwmake
index ed3d03e7890..e5edf6fc976 100755
--- a/Allwmake
+++ b/Allwmake
@@ -11,7 +11,6 @@ cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR" 2>/dev/null || {
     exit 1
 }
 
-# Parse arguments for library compilation
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
 #------------------------------------------------------------------------------
diff --git a/applications/Allwmake b/applications/Allwmake
index 88211f13065..dc3dabd7988 100755
--- a/applications/Allwmake
+++ b/applications/Allwmake
@@ -11,7 +11,6 @@ cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR/applications" 2>/dev/null || {
     exit 1
 }
 
-# Parse arguments for library compilation
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
 #------------------------------------------------------------------------------
diff --git a/applications/solvers/DNS/dnsFoam/Allwmake b/applications/solvers/DNS/dnsFoam/Allwmake
index 615be6fcc02..64bef012d97 100755
--- a/applications/solvers/DNS/dnsFoam/Allwmake
+++ b/applications/solvers/DNS/dnsFoam/Allwmake
@@ -1,8 +1,10 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # run from this directory
+cd ${0%/*} || exit 1                         # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/have_fftw
 
-if [ -f "$FFTW_ARCH_PATH/include/fftw3.h" ] || \
-   [ "${FFTW_ARCH_PATH##*-}" = system -a -f "/usr/include/fftw3.h" ]
+#------------------------------------------------------------------------------
+
+if have_fftw
 then
     wmake
 else
diff --git a/applications/solvers/compressible/rhoCentralFoam/Allwmake b/applications/solvers/compressible/rhoCentralFoam/Allwmake
index 5dee7d1a882..58648ff0444 100755
--- a/applications/solvers/compressible/rhoCentralFoam/Allwmake
+++ b/applications/solvers/compressible/rhoCentralFoam/Allwmake
@@ -1,7 +1,5 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
 (wmake $targetType BCs && wmake $targetType && wmake $targetType rhoCentralDyMFoam)
diff --git a/applications/solvers/lagrangian/DPMFoam/Allwmake b/applications/solvers/lagrangian/DPMFoam/Allwmake
index e3c5370297a..29e2940cd9f 100755
--- a/applications/solvers/lagrangian/DPMFoam/Allwmake
+++ b/applications/solvers/lagrangian/DPMFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType DPMTurbulenceModels
 
 wmake $targetType
diff --git a/applications/solvers/multiphase/MPPICInterFoam/Allwmake b/applications/solvers/multiphase/MPPICInterFoam/Allwmake
index 36e2f896469..6e71a313cc6 100755
--- a/applications/solvers/multiphase/MPPICInterFoam/Allwmake
+++ b/applications/solvers/multiphase/MPPICInterFoam/Allwmake
@@ -1,5 +1,7 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # run from this directory
+cd ${0%/*} || exit 1                            # Run from this directory
+
+#------------------------------------------------------------------------------
 
 wmake libso CompressibleTwoPhaseMixtureTurbulenceModels
 wmake
diff --git a/applications/solvers/multiphase/compressibleInterFoam/Allwmake b/applications/solvers/multiphase/compressibleInterFoam/Allwmake
index 7ecc9f42387..dfd9db7d526 100755
--- a/applications/solvers/multiphase/compressibleInterFoam/Allwmake
+++ b/applications/solvers/multiphase/compressibleInterFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType twoPhaseMixtureThermo
 wmake $targetType surfaceTensionModels
 
diff --git a/applications/solvers/multiphase/compressibleMultiphaseInterFoam/Allwmake b/applications/solvers/multiphase/compressibleMultiphaseInterFoam/Allwmake
index b92d87aef4e..0d361f95545 100755
--- a/applications/solvers/multiphase/compressibleMultiphaseInterFoam/Allwmake
+++ b/applications/solvers/multiphase/compressibleMultiphaseInterFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType multiphaseMixtureThermo
 wmake $targetType
 
diff --git a/applications/solvers/multiphase/driftFluxFoam/Allwmake b/applications/solvers/multiphase/driftFluxFoam/Allwmake
index 069235819e9..7571b50608b 100755
--- a/applications/solvers/multiphase/driftFluxFoam/Allwmake
+++ b/applications/solvers/multiphase/driftFluxFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType mixtureViscosityModels
 wmake $targetType relativeVelocityModels
 wmake $targetType
diff --git a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/Allwmake b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/Allwmake
index 59af9259fef..e64b0d12850 100755
--- a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/Allwmake
+++ b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/Allwmake
@@ -1,10 +1,10 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
-targetType=libso
+cd ${0%/*} || exit 1                        # Run from this directory
+targetType=libso                            # Preferred library type
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType temperaturePhaseChangeTwoPhaseMixtures
 wmake
 
diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/Allwmake b/applications/solvers/multiphase/interPhaseChangeFoam/Allwmake
index dfcde284ea5..6f577cedd66 100755
--- a/applications/solvers/multiphase/interPhaseChangeFoam/Allwmake
+++ b/applications/solvers/multiphase/interPhaseChangeFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType phaseChangeTwoPhaseMixtures
 wmake $targetType
 wmake $targetType interPhaseChangeDyMFoam
diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/Allwmake b/applications/solvers/multiphase/multiphaseEulerFoam/Allwmake
index d38522312d4..e22e137bcb4 100755
--- a/applications/solvers/multiphase/multiphaseEulerFoam/Allwmake
+++ b/applications/solvers/multiphase/multiphaseEulerFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmakeLnInclude interfacialModels
 wmake $targetType multiphaseSystem
 wmake $targetType interfacialModels
diff --git a/applications/solvers/multiphase/multiphaseInterFoam/Allwmake b/applications/solvers/multiphase/multiphaseInterFoam/Allwmake
index 50f78a705cd..0e3a0ff1037 100755
--- a/applications/solvers/multiphase/multiphaseInterFoam/Allwmake
+++ b/applications/solvers/multiphase/multiphaseInterFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType multiphaseMixture
 wmake $targetType
 wmake $targetType multiphaseInterDyMFoam
diff --git a/applications/solvers/multiphase/reactingEulerFoam/Allwmake b/applications/solvers/multiphase/reactingEulerFoam/Allwmake
index 87e6a81e3f0..bcf5ba22e95 100755
--- a/applications/solvers/multiphase/reactingEulerFoam/Allwmake
+++ b/applications/solvers/multiphase/reactingEulerFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmakeLnInclude interfacialModels
 wmakeLnInclude interfacialCompositionModels
 wmake $targetType phaseSystems
diff --git a/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/Allwmake b/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/Allwmake
index 05211a00395..5ad18fcf709 100755
--- a/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/Allwmake
+++ b/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType multiphaseSystem
 wmake $targetType multiphaseCompressibleTurbulenceModels
 wmake $targetType
diff --git a/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/Allwmake b/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/Allwmake
index 49c983288e0..ffbeaacbfdb 100755
--- a/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/Allwmake
+++ b/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType twoPhaseSystem
 wmake $targetType twoPhaseCompressibleTurbulenceModels
 wmake $targetType
diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/Allwmake b/applications/solvers/multiphase/twoPhaseEulerFoam/Allwmake
index 9eb3ae37c4c..73f0733ef12 100755
--- a/applications/solvers/multiphase/twoPhaseEulerFoam/Allwmake
+++ b/applications/solvers/multiphase/twoPhaseEulerFoam/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmakeLnInclude interfacialModels
 wmake $targetType twoPhaseSystem
 wmake $targetType interfacialModels
diff --git a/applications/utilities/mesh/conversion/ccm/Allwmake b/applications/utilities/mesh/conversion/ccm/Allwmake
index f0062c9774e..6306b021684 100755
--- a/applications/utilities/mesh/conversion/ccm/Allwmake
+++ b/applications/utilities/mesh/conversion/ccm/Allwmake
@@ -1,17 +1,18 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                            # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # (for error catching)
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions    # General system functions
 
-# Parse arguments for compilation (at least for error catching)
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+#------------------------------------------------------------------------------
 
-# Only build if libraries already exist
-if [ -e $FOAM_LIBBIN/libccm.so ]
+# Only build when the OpenFOAM libccm adaptor already exists
+if [ -f $FOAM_LIBBIN/libccm$extLibso ]
 then
     echo "==> build optional ccm conversion components"
     wmake $targetType ccmToFoam
     wmake $targetType foamToCcm
 else
-    echo "==> skip optional ccm conversion components (no libccm.so)"
+    echo "==> skip optional ccm conversion components (no libccm$extLibso)"
 fi
 
 #------------------------------------------------------------------------------
diff --git a/applications/utilities/mesh/generation/Allwmake b/applications/utilities/mesh/generation/Allwmake
index 4abbf97bc2e..39a942aee66 100755
--- a/applications/utilities/mesh/generation/Allwmake
+++ b/applications/utilities/mesh/generation/Allwmake
@@ -1,8 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                        # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # (for error catching)
+
+#------------------------------------------------------------------------------
 
-# Parse arguments for compilation (at least for error catching)
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 wmake -all $targetType blockMesh
 wmake -all $targetType extrude
 wmake -all $targetType extrude2DMesh
diff --git a/applications/utilities/mesh/generation/extrude2DMesh/Allwmake b/applications/utilities/mesh/generation/extrude2DMesh/Allwmake
index f8637ab7e53..2b58cd08e12 100755
--- a/applications/utilities/mesh/generation/extrude2DMesh/Allwmake
+++ b/applications/utilities/mesh/generation/extrude2DMesh/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType extrude2DMesh
 wmake $targetType
 
diff --git a/applications/utilities/mesh/generation/foamyMesh/Allwmake b/applications/utilities/mesh/generation/foamyMesh/Allwmake
index 6c838e5f09f..3dc79feaf81 100755
--- a/applications/utilities/mesh/generation/foamyMesh/Allwmake
+++ b/applications/utilities/mesh/generation/foamyMesh/Allwmake
@@ -1,16 +1,14 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                        # Run from this directory
+export WM_CONTINUE_ON_ERROR=true            # Optional unit
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # (for error catching)
+. $WM_PROJECT_DIR/wmake/scripts/have_cgal
 
-# Optional unit: continue-on-error
-# - may not have CGAL installed,
-# - or the CGAL installation moved and gives CMake problems
-export WM_CONTINUE_ON_ERROR=true
-
-# Parse arguments for library compilation
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+#------------------------------------------------------------------------------
+# Optional
+# - CGAL not installed, or installed but gives CMake problems
 
-if [ -f "$CGAL_ARCH_PATH/include/CGAL/version.h" ] || \
-   [ "${CGAL_ARCH_PATH##*-}" = system -a -f /usr/include/CGAL/version.h ]
+if have_cgal
 then
     wmake $targetType conformalVoronoiMesh
     wmake $targetType conformalVoronoi2DMesh
diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/Allwmake b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/Allwmake
index c3f900341ec..1607b672aa0 100755
--- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/Allwmake
+++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/Allwmake
@@ -1,8 +1,8 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                        # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # (for error catching)
 
-# Parse arguments for compilation (at least for error catching)
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+#------------------------------------------------------------------------------
 
 if [ -d "${FASTDUALOCTREE_SRC_PATH}" ]
 then
diff --git a/applications/utilities/mesh/manipulation/renumberMesh/Allwmake b/applications/utilities/mesh/manipulation/renumberMesh/Allwmake
index 59db39f970d..4f75bd542c9 100755
--- a/applications/utilities/mesh/manipulation/renumberMesh/Allwmake
+++ b/applications/utilities/mesh/manipulation/renumberMesh/Allwmake
@@ -1,38 +1,27 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                            # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # (for error catching)
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions    # General system functions
+. $WM_PROJECT_DIR/wmake/scripts/have_zoltan
 
-# Parse arguments for compilation (at least for error catching)
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+#------------------------------------------------------------------------------
 
 unset COMP_FLAGS LINK_FLAGS
 
-if [ -f "${FOAM_LIBBIN}/libSloanRenumber.so" ]
+if [ -f $FOAM_LIBBIN/libSloanRenumber$extLibso ]
 then
     echo "    found libSloanRenumber  --  enabling sloan renumbering support."
-    export LINK_FLAGS="${LINK_FLAGS} -lSloanRenumber"
+    export LINK_FLAGS="$LINK_FLAGS -lSloanRenumber"
 fi
 
-if [ -f "${FOAM_LIBBIN}/libzoltanRenumber.so" ]
+if [ -f $FOAM_LIBBIN/libzoltanRenumber$extLibso ]
 then
-    if [ -z "$ZOLTAN_ARCH_PATH" ]
+    if have_zoltan
     then
-        # Optional: get ZOLTAN_ARCH_PATH
-        if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/zoltan)
-        then
-            . $settings
-        fi
+        echo "    found libzoltanRenumber  --  enabling zoltan renumbering support."
+        export COMP_FLAGS="$COMP_FLAGS -DHAVE_ZOLTAN"
+        export LINK_FLAGS="$LINK_FLAGS -lzoltanRenumber -L$ZOLTAN_LIB_DIR -lzoltan"
     fi
-
-    for libdir in lib "lib${WM_COMPILER_LIB_ARCH}"
-    do
-        if [ -f "$ZOLTAN_ARCH_PATH/$libdir/libzoltan.a" ]
-        then
-            echo "    found libzoltanRenumber  --  enabling zoltan renumbering support."
-            export COMP_FLAGS="-DFOAM_USE_ZOLTAN"
-            export LINK_FLAGS="${LINK_FLAGS} -lzoltanRenumber -L$ZOLTAN_ARCH_PATH/$libdir -lzoltan"
-            break
-        fi
-    done
 fi
 
 wmake $targetType
diff --git a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
index a49d110df29..1b9c88217db 100644
--- a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
+++ b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
@@ -55,7 +55,7 @@ Description
 #include "processorMeshes.H"
 #include "hexRef8.H"
 
-#ifdef FOAM_USE_ZOLTAN
+#ifdef HAVE_ZOLTAN
     #include "zoltanRenumber.H"
 #endif
 
@@ -633,7 +633,7 @@ int main(int argc, char *argv[])
 
     // Force linker to include zoltan symbols. This section is only needed since
     // Zoltan is a static library
-    #ifdef FOAM_USE_ZOLTAN
+    #ifdef HAVE_ZOLTAN
         Info<< "renumberMesh built with zoltan support." << nl << endl;
         (void)zoltanRenumber::typeName;
     #endif
diff --git a/applications/utilities/mesh/manipulation/setSet/Allwmake b/applications/utilities/mesh/manipulation/setSet/Allwmake
index 49aaea637e3..dfee8bee52b 100755
--- a/applications/utilities/mesh/manipulation/setSet/Allwmake
+++ b/applications/utilities/mesh/manipulation/setSet/Allwmake
@@ -1,19 +1,17 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for compilation (at least for error catching)
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+cd ${0%/*} || exit 1                        # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # (for error catching)
+. $WM_PROJECT_DIR/wmake/scripts/have_readline
 
+#------------------------------------------------------------------------------
 unset COMP_FLAGS LINK_FLAGS
 
-#
-# use readline if available
-#
-if [ -f /usr/include/readline/readline.h ]
+# Use readline if available
+if have_readline
 then
-    echo "    found <readline/readline.h>  --  enabling readline support."
-    export COMP_FLAGS="-DHAS_READLINE"
-    export LINK_FLAGS="-lreadline"
+    echo "    readline detected - enabling readline support."
+    export COMP_FLAGS="-DHAVE_LIBREADLINE -I$READLINE_INC_DIR"
+    export LINK_FLAGS="-L$READLINE_LIB_DIR -lreadline"
 fi
 
 wmake $targetType
diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C
index 18f5ab5b34a..fc99cc81e5d 100644
--- a/applications/utilities/mesh/manipulation/setSet/setSet.C
+++ b/applications/utilities/mesh/manipulation/setSet/setSet.C
@@ -55,10 +55,11 @@ Description
 
 #include <stdio.h>
 
-
-#ifdef HAS_READLINE
+#ifdef HAVE_LIBREADLINE
     #include <readline/readline.h>
     #include <readline/history.h>
+
+    static const char* historyFile = ".setSet";
 #endif
 
 using namespace Foam;
@@ -66,11 +67,6 @@ using namespace Foam;
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 
-#ifdef HAS_READLINE
-static const char* historyFile = ".setSet";
-#endif
-
-
 // Write set to VTK readable files
 void writeVTK
 (
@@ -790,7 +786,7 @@ int main(int argc, char *argv[])
     printAllSets(mesh, Info);
 
     // Read history if interactive
-    #ifdef HAS_READLINE
+    #ifdef HAVE_LIBREADLINE
     if (!batch && !read_history((runTime.path()/historyFile).c_str()))
     {
         Info<< "Successfully read history from " << historyFile << endl;
@@ -872,7 +868,7 @@ int main(int argc, char *argv[])
             }
             else
             {
-                #ifdef HAS_READLINE
+                #ifdef HAVE_LIBREADLINE
                 {
                     char* linePtr = readline("readline>");
 
diff --git a/applications/utilities/miscellaneous/foamHelp/Allwmake b/applications/utilities/miscellaneous/foamHelp/Allwmake
index c00e52a8980..78dc109feca 100755
--- a/applications/utilities/miscellaneous/foamHelp/Allwmake
+++ b/applications/utilities/miscellaneous/foamHelp/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType helpTypes
 wmake $targetType
 
diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake
index c24b4e652f9..ade3a263790 100755
--- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake
+++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake
@@ -1,7 +1,7 @@
 #!/bin/sh
 cd ${0%/*} || exit 1                            # Run from this directory
 export WM_CONTINUE_ON_ERROR=true                # Optional unit
-. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments  # Parse arguments
+. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 . $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions  # The CMake functions
 
 # -----------------------------------------------------------------------------
diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/Allwmake b/applications/utilities/postProcessing/graphics/ensightFoamReader/Allwmake
index 2471b6d55ab..ecb7039b93a 100755
--- a/applications/utilities/postProcessing/graphics/ensightFoamReader/Allwmake
+++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType
 
 #------------------------------------------------------------------------------
diff --git a/applications/utilities/postProcessing/noise/Allwmake b/applications/utilities/postProcessing/noise/Allwmake
index f1cf077bb17..7452621cd23 100755
--- a/applications/utilities/postProcessing/noise/Allwmake
+++ b/applications/utilities/postProcessing/noise/Allwmake
@@ -1,8 +1,10 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # run from this directory
+cd ${0%/*} || exit 1                        # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/have_fftw
 
-if [ -f "$FFTW_ARCH_PATH/include/fftw3.h" ] || \
-   [ "${FFTW_ARCH_PATH##*-}" = system -a -f "/usr/include/fftw3.h" ]
+#------------------------------------------------------------------------------
+
+if have_fftw
 then
     wmake
 else
diff --git a/applications/utilities/preProcessing/boxTurb/Allwmake b/applications/utilities/preProcessing/boxTurb/Allwmake
index e4921f5485e..21e6762b4ae 100755
--- a/applications/utilities/preProcessing/boxTurb/Allwmake
+++ b/applications/utilities/preProcessing/boxTurb/Allwmake
@@ -1,8 +1,10 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # run from this directory
+cd ${0%/*} || exit 1                         # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/have_fftw
 
-if [ -f "$FFTW_ARCH_PATH/include/fftw3.h" ] || \
-   [ "${FFTW_ARCH_PATH##*-}" = system -a -f "/usr/include/fftw3.h" ]
+#------------------------------------------------------------------------------
+
+if have_fftw
 then
     wmake
 else
diff --git a/applications/utilities/preProcessing/wallFunctionTable/Allwmake b/applications/utilities/preProcessing/wallFunctionTable/Allwmake
index 06612a9c674..27ff0f02156 100755
--- a/applications/utilities/preProcessing/wallFunctionTable/Allwmake
+++ b/applications/utilities/preProcessing/wallFunctionTable/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType tabulatedWallFunction
 wmake $targetType
 
diff --git a/applications/utilities/surface/surfaceBooleanFeatures/Allwmake b/applications/utilities/surface/surfaceBooleanFeatures/Allwmake
index d1ec8b77c1f..0aae5a7cfb8 100755
--- a/applications/utilities/surface/surfaceBooleanFeatures/Allwmake
+++ b/applications/utilities/surface/surfaceBooleanFeatures/Allwmake
@@ -1,10 +1,11 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                        # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/have_cgal
 
+#------------------------------------------------------------------------------
 unset COMP_FLAGS LINK_FLAGS
 
-if [ -f "$CGAL_ARCH_PATH/include/CGAL/version.h" ] || \
-   [ "${CGAL_ARCH_PATH##*-}" = system -a -f /usr/include/CGAL/version.h ]
+if have_cgal
 then
     wmake PolyhedronReader
     export COMP_FLAGS='-IPolyhedronReader'
diff --git a/applications/utilities/surface/surfaceFeatureExtract/Allwmake b/applications/utilities/surface/surfaceFeatureExtract/Allwmake
index ee26d27fc3c..913a79b6409 100755
--- a/applications/utilities/surface/surfaceFeatureExtract/Allwmake
+++ b/applications/utilities/surface/surfaceFeatureExtract/Allwmake
@@ -1,7 +1,5 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
 (wmake libso extractionMethod && wmake)
diff --git a/bin/tools/lib-dir b/bin/tools/lib-dir
index fe24e510ede..72b13d5a5f3 100755
--- a/bin/tools/lib-dir
+++ b/bin/tools/lib-dir
@@ -142,12 +142,18 @@ fi
 
 if [ -n "$resolved" ]
 then
-    case "$optSyntax" in
-    csh)
+    case "$optSyntax-$(uname -s 2>/dev/null)" in
+    make*)
+        printf "%s\n" "-L$resolved"
+        ;;
+    csh-Darwin*)
+        echo "setenv DYLD_LIBRARY_PATH $resolved:$DYLD_LIBRARY_PATH"
+        ;;
+    csh*)
         echo "setenv LD_LIBRARY_PATH $resolved:$LD_LIBRARY_PATH"
         ;;
-    make)
-        printf "%s\n" "-L$resolved"
+    sh-Darwin*)
+        echo "DYLD_LIBRARY_PATH=$resolved:$DYLD_LIBRARY_PATH"
         ;;
     *)
         echo "LD_LIBRARY_PATH=$resolved:$LD_LIBRARY_PATH"
@@ -155,7 +161,7 @@ then
     esac
     exit 0      # Good
 else
-    exit 1    # Error
+    exit 1      # Error
 fi
 
 
diff --git a/etc/config.csh/mpi b/etc/config.csh/mpi
index 75c8ffec1e3..3c59434eb81 100644
--- a/etc/config.csh/mpi
+++ b/etc/config.csh/mpi
@@ -304,7 +304,7 @@ endsw
 
 
 # Add (non-dummy) MPI implementation
-# - dummy MPI already added to LD_LIBRARY_PATH and has no external libraries
+# - dummy MPI already in lib-path and has no external libraries
 if ( "$FOAM_MPI" != dummy ) then
     if ( $?FOAM_EXT_LIBBIN ) then   # External libraries (allowed to be unset)
         _foamAddLib ${FOAM_EXT_LIBBIN}/${FOAM_MPI}
diff --git a/etc/config.csh/settings b/etc/config.csh/settings
index 80ce56e41e2..213a7334f15 100644
--- a/etc/config.csh/settings
+++ b/etc/config.csh/settings
@@ -106,6 +106,12 @@ case Linux:
 case Darwin:    # Presumably x86_64
     if (! $?WM_ARCH_OPTION ) setenv WM_ARCH_OPTION 64  # Default to 64-bit
     setenv WM_ARCH darwin64
+    /bin/cat << INCOMPLETE
+===============================================================================
+Operating system '$WM_ARCH' has incomplete support in this OpenFOAM release.
+For further assistance, please contact www.OpenFOAM.com
+===============================================================================
+INCOMPLETE
     breaksw
 
 case SunOS:
@@ -118,12 +124,12 @@ case SunOS:
     breaksw
 
 default:
-    /bin/cat << UNSUPPORTED_OS
+    /bin/cat << UNSUPPORTED
 ===============================================================================
-Your '$WM_ARCH' operating system is unsupported by this OpenFOAM release.
+Operating system '$WM_ARCH' is unsupported by this OpenFOAM release.
 For further assistance, please contact www.OpenFOAM.com
 ===============================================================================
-UNSUPPORTED_OS
+UNSUPPORTED
     breaksw
 
 endsw
diff --git a/etc/config.sh/functions b/etc/config.sh/functions
index 99a5ea5b1dd..9358e2d9ba2 100644
--- a/etc/config.sh/functions
+++ b/etc/config.sh/functions
@@ -56,7 +56,7 @@ then
         [ -n "$1" ] && export LD_LIBRARY_PATH=$1:$LD_LIBRARY_PATH
     }
 
-    # Prefix to LD_LIBRARY_PATH with additional checking
+    # Prepend to LD_LIBRARY_PATH with additional checking
     # $1 = base directory for 'lib' or 'lib64'
     # $2 = fallback libname ('lib' or 'lib64')
     #
@@ -69,7 +69,7 @@ then
     # Return 0 on success
     _foamAddLibAuto()
     {
-        # Note ksh doesn't have 'local' thus these ugly variable names
+        # Note ksh does not have 'local' thus these ugly variable names
         foamVar_prefix="$1"
         foamVar_end="${1##*-}"
 
@@ -112,6 +112,27 @@ then
     }
 
 
+    # Special treatment for Darwin
+    # - DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH
+    if [ "$(uname -s 2>/dev/null)" = Darwin ]
+    then
+        unset -f _foamAddLib _foamAddLibAuto 2>/dev/null
+
+        # Prepend DYLD_LIBRARY_PATH
+        _foamAddLib()
+        {
+            [ -n "$1" ] && export DYLD_LIBRARY_PATH=$1:$DYLD_LIBRARY_PATH
+        }
+
+        # Prepend to DYLD_LIBRARY_PATH with additional checking
+        # - use lib-dir script instead of rewriting
+        _foamAddLibAuto()
+        {
+            eval "$($WM_PROJECT_DIR/bin/tools/lib-dir -sh $@)";
+        }
+    fi
+
+
     # Source an etc file, possibly with some verbosity
     # - use eval to avoid intermediate variables (ksh doesn't have 'local')
     if [ "$FOAM_VERBOSE" -a "$PS1" ]
diff --git a/etc/config.sh/mpi b/etc/config.sh/mpi
index 55e7cda57b9..4feee873129 100644
--- a/etc/config.sh/mpi
+++ b/etc/config.sh/mpi
@@ -307,7 +307,7 @@ esac
 
 
 # Add (non-dummy) MPI implementation
-# - dummy MPI already added to LD_LIBRARY_PATH and has no external libraries
+# - dummy MPI already in lib-path and has no external libraries
 if [ "$FOAM_MPI" != dummy ] && type _foamAddLib > /dev/null 2>&1
 then
     if [ -n "$FOAM_EXT_LIBBIN" ]    # External libraries (allowed to be unset)
diff --git a/etc/config.sh/settings b/etc/config.sh/settings
index f60e616ff16..545e8a234f1 100644
--- a/etc/config.sh/settings
+++ b/etc/config.sh/settings
@@ -100,6 +100,13 @@ Linux)
 Darwin)     # Presumably x86_64
     : ${WM_ARCH_OPTION:=64}; export WM_ARCH_OPTION  # Default to 64-bit
     WM_ARCH=darwin64
+    /bin/cat << INCOMPLETE 1>&2
+===============================================================================
+Operating system '$WM_ARCH' has incomplete support in this OpenFOAM release.
+For further assistance, please contact www.OpenFOAM.com
+===============================================================================
+INCOMPLETE
+    echo "Darwin support ($WM_ARCH) is incomplete" 1>&2
     ;;
 
 SunOS)
@@ -112,12 +119,12 @@ SunOS)
     ;;
 
 *)  # An unsupported operating system
-    /bin/cat << UNSUPPORTED_OS 1>&2
+    /bin/cat << UNSUPPORTED 1>&2
 ===============================================================================
-Your '$WM_ARCH' operating system is unsupported by this OpenFOAM release.
+Operating system '$WM_ARCH' is unsupported by this OpenFOAM release.
 For further assistance, please contact www.OpenFOAM.com
 ===============================================================================
-UNSUPPORTED_OS
+UNSUPPORTED
     ;;
 esac
 
diff --git a/src/Allwmake b/src/Allwmake
index 259d52a55d0..faf50939444 100755
--- a/src/Allwmake
+++ b/src/Allwmake
@@ -11,7 +11,6 @@ cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR/src" 2>/dev/null || {
     exit 1
 }
 
-# Parse arguments for library compilation
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
 #------------------------------------------------------------------------------
diff --git a/src/OSspecific/POSIX/Allwmake b/src/OSspecific/POSIX/Allwmake
index 83d082c99e5..ef725400a69 100755
--- a/src/OSspecific/POSIX/Allwmake
+++ b/src/OSspecific/POSIX/Allwmake
@@ -1,22 +1,19 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
-targetType=libo
+cd ${0%/*} || exit 1                        # Run from this directory
+targetType=libo                             # Preferred library type
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments $*
 
+#------------------------------------------------------------------------------
 unset COMP_FLAGS LINK_FLAGS
 
-#
-# use <sys/inotify.h> if available (Linux)
-#
+# If <sys/inotify.h> is available (Linux)
 if [ -f /usr/include/sys/inotify.h ]
 then
     echo "    found <sys/inotify.h>  --  enabling inotify for file monitoring."
     export COMP_FLAGS="-DFOAM_USE_INOTIFY"
 fi
 
-# make (non-shared by default) object
+# Make object (non-shared by default)
 wmake $targetType
 
 #------------------------------------------------------------------------------
diff --git a/src/Pstream/Allwmake b/src/Pstream/Allwmake
index e69310f341b..f7447abf1e2 100755
--- a/src/Pstream/Allwmake
+++ b/src/Pstream/Allwmake
@@ -1,9 +1,8 @@
 #!/bin/sh
 cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
 
 # Define how to create an mpi-versioned library of $targetType
 # compile into qualified directory
@@ -35,5 +34,4 @@ case "$WM_MPLIB" in
     ;;
 esac
 
-
 #------------------------------------------------------------------------------
diff --git a/src/TurbulenceModels/Allwmake b/src/TurbulenceModels/Allwmake
index dfe590d2a49..717ff9f150c 100755
--- a/src/TurbulenceModels/Allwmake
+++ b/src/TurbulenceModels/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType turbulenceModels
 wmake $targetType incompressible
 wmake $targetType compressible
diff --git a/src/conversion/Allwmake b/src/conversion/Allwmake
index 664d800a63a..e2fd470725b 100755
--- a/src/conversion/Allwmake
+++ b/src/conversion/Allwmake
@@ -1,10 +1,10 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
-targetType=libso
+cd ${0%/*} || exit 1                        # Run from this directory
+targetType=libso                            # Preferred library type
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType
 
 ccm/Allwmake
diff --git a/src/conversion/ccm/Allwmake b/src/conversion/ccm/Allwmake
index 768101d601e..0c358cc7811 100755
--- a/src/conversion/ccm/Allwmake
+++ b/src/conversion/ccm/Allwmake
@@ -1,39 +1,18 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Optional component: (eg, may depend on third-party libraries)
-
-# Parse arguments for compilation (at least for error catching)
+cd ${0%/*} || exit 1                         # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+. $WM_PROJECT_DIR/wmake/scripts/have_ccmio
 
-warning="==> skip optional libccm adapter"
-
-if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/ccmio)
-then
-    . $settings
-else
-    echo "$warning (no config.sh/ccmio settings)"
-    exit
-fi
+#------------------------------------------------------------------------------
+# Optional
+# - may depend on third-party libraries
 
+warning="==> skip optional libccm adapter"
 
-# Link with static libccmio only (possibly fewer issues)
-if [ -e $CCMIO_ARCH_PATH/include/libccmio/ccmio.h \
-  -a -e $CCMIO_ARCH_PATH/lib/libccmio.a ]
+# Link with static libccmio only (fewer issues)
+if have_ccmio
 then
-    # The libccmio uses int32_t.
-    # The OpenFOAM adapter thus requires additional work for 64-bit labels.
-    # The OpenFOAM adapter was originally only designed for 'double'
-
-    if [ "$WM_LABEL_SIZE" = 64 ]
-    then
-        echo "$warning (not designed for 64-bit labels)"
-    elif [ "$WM_PRECISION_OPTION" = SP ]
-    then
-        echo "$warning (not designed for single precision)"
-    else
-        wmake libso || echo "$warning (build issues detected)"
-    fi
+    wmake libso || echo "$warning (build issues detected)"
 else
     echo $warning
 fi
diff --git a/src/conversion/ccm/Make/options b/src/conversion/ccm/Make/options
index 3272da3576e..17c07c6824d 100644
--- a/src/conversion/ccm/Make/options
+++ b/src/conversion/ccm/Make/options
@@ -6,9 +6,9 @@ EXE_INC = \
     -I$(LIB_SRC)/fileFormats/lnInclude \
     -I$(LIB_SRC)/meshTools/lnInclude \
     -I$(LIB_SRC)/conversion/lnInclude \
-    -I$(CCMIO_ARCH_PATH)/include
+    -I$(CCMIO_INC_DIR)
 
 LIB_LIBS = \
     -lfiniteVolume \
     -lconversion \
-    -L$(CCMIO_ARCH_PATH)/lib -lccmio
+    -L$(CCMIO_LIB_DIR) -lccmio
diff --git a/src/dummyThirdParty/Allwmake b/src/dummyThirdParty/Allwmake
index a1628e356fb..5a5be522c73 100755
--- a/src/dummyThirdParty/Allwmake
+++ b/src/dummyThirdParty/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType scotchDecomp
 wmake $targetType ptscotchDecomp
 wmake $targetType metisDecomp
diff --git a/src/functionObjects/Allwmake b/src/functionObjects/Allwmake
index 073a57e3f5b..df7176d7ef9 100755
--- a/src/functionObjects/Allwmake
+++ b/src/functionObjects/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType field
 wmake $targetType forces
 wmake $targetType lagrangian
diff --git a/src/functionObjects/graphics/Allwmake b/src/functionObjects/graphics/Allwmake
index e665220999e..ab6a4e7c891 100755
--- a/src/functionObjects/graphics/Allwmake
+++ b/src/functionObjects/graphics/Allwmake
@@ -1,5 +1,7 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
+cd ${0%/*} || exit 1                        # Run from this directory
+
+#------------------------------------------------------------------------------
 
 runTimePostProcessing/Allwmake
 
diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwmake b/src/functionObjects/graphics/runTimePostProcessing/Allwmake
index 5d1376aa351..a0321c849b1 100755
--- a/src/functionObjects/graphics/runTimePostProcessing/Allwmake
+++ b/src/functionObjects/graphics/runTimePostProcessing/Allwmake
@@ -1,6 +1,6 @@
 #!/bin/sh
-cd ${0%/*} || exit 1                             # Run from this directory
-. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions   # The CMake functions
+cd ${0%/*} || exit 1                            # Run from this directory
+. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions  # The CMake functions
 
 # -----------------------------------------------------------------------------
 
diff --git a/src/fvAgglomerationMethods/Allwmake b/src/fvAgglomerationMethods/Allwmake
index 09f2dcf3c15..f2f26b42af7 100755
--- a/src/fvAgglomerationMethods/Allwmake
+++ b/src/fvAgglomerationMethods/Allwmake
@@ -1,86 +1,14 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                         # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+. $WM_PROJECT_DIR/wmake/scripts/have_mgridgen
 
-: ${FOAM_EXT_LIBBIN:=/usr/lib$WM_COMPILER_LIB_ARCH}  # Extra safety
-export FOAM_EXT_LIBBIN
-
-# Test for mgridgen.
-# - return 0 and export MGRIDGEN_ARCH_PATH on success
-hasMgridGen()
-{
-    local warning="==> skip mgridgen"
-
-    unset MGRIDGEN_ARCH_PATH MGRIDGEN_VERSION
-    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/mgridgen) || {
-        # ignore silently# echo "$warning (no config.sh/mgridgen settings)"
-        return 1
-    }
-
-    . $settings
-    if [ -z "$MGRIDGEN_ARCH_PATH" -o "${MGRIDGEN_ARCH_PATH##*-}" = none ]
-    then
-        # ignore silently# echo "$warning (not available)"
-        return 1
-    fi
-
-    # Header
-    local header=$MGRIDGEN_ARCH_PATH/include/mgridgen.h
-    [ -f "$header" ] || {
-        # ignore silently# echo "$warning (no header)"
-        return 2  # file not found
-    }
-
-    # Library
-    [ -r $FOAM_EXT_LIBBIN/libMGridGen.so ] || \
-    [ -r $MGRIDGEN_ARCH_PATH/lib/libmgrid.a ] || \
-    [ -r $MGRIDGEN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmgrid.a ] || \
-    [ "${MGRIDGEN_ARCH_PATH##*-}" = system ] || {
-        # ignore silently# echo "$warning (missing library)"
-        return 2
-    }
-
-    # Ensure consistent sizes with OpenFOAM and mgridgen header
-    # Extract typedef for idxtype, realtype
-    local label=$(sed -ne \
-        's/^.*typedef *\([^ ]*\) *idxtype.*/\1/ip' \
-        "$header")
-    local scalar=$(sed -ne \
-        's/^.*typedef *\([^ ]*\) *realtype.*/\1/ip' \
-        "$header")
-
-    : ${label:=unknown}
-    : ${scalar:=unknown}
-
-    case "$WM_LABEL_SIZE:$label" in
-    (32:int32_t | 32:int | 64:int64_t | 64:long)
-        export MGRIDGEN_ARCH_PATH
-        ;;
-
-    *)
-        echo "$warning (label='$WM_LABEL_SIZE', mgridgen.h has '$label')"
-        return 1
-        ;;
-    esac
-    case "$WM_PRECISION_OPTION:$scalar" in
-    (SP:float | DP:double)
-        export MGRIDGEN_ARCH_PATH
-        ;;
-
-    *)
-        echo "$warning (scalar='$WM_PRECISION_OPTION', mgridgen.h has '$scalar')"
-        return 1
-        ;;
-    esac
-
-    # OK
-    echo "mgridgen (label=$label, scalar=$scalar) - $MGRIDGEN_ARCH_PATH"
+#------------------------------------------------------------------------------
 
-}
+: ${FOAM_EXT_LIBBIN:=/usr/lib$WM_COMPILER_LIB_ARCH}  # Extra safety?
+export FOAM_EXT_LIBBIN
 
-if hasMgridGen
+if have_mgridgen
 then
     wmake $targetType MGridGenGamgAgglomeration
 fi
diff --git a/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/Make/options b/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/Make/options
index 8f7b5aedc66..7fd6b0ae766 100644
--- a/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/Make/options
+++ b/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/Make/options
@@ -1,9 +1,6 @@
 EXE_INC = \
     -I$(LIB_SRC)/finiteVolume/lnInclude \
-    -I$(MGRIDGEN_ARCH_PATH)/include
+    -I$(MGRIDGEN_INC_DIR)
 
 LIB_LIBS = \
-    -L$(FOAM_EXT_LIBBIN) \
-    -L$(MGRIDGEN_ARCH_PATH)/lib \
-    -L$(MGRIDGEN_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -lmgrid
+    -L$(MGRIDGEN_LIB_DIR) -lmgrid
diff --git a/src/lagrangian/Allwmake b/src/lagrangian/Allwmake
index a70ae861ba0..0f58db93952 100755
--- a/src/lagrangian/Allwmake
+++ b/src/lagrangian/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType distributionModels
 wmake $targetType basic
 wmake $targetType solidParticle
diff --git a/src/lagrangian/molecularDynamics/Allwmake b/src/lagrangian/molecularDynamics/Allwmake
index c1221b264c9..ce45c96d26a 100755
--- a/src/lagrangian/molecularDynamics/Allwmake
+++ b/src/lagrangian/molecularDynamics/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType potential
 wmake $targetType molecularMeasurements
 wmake $targetType molecule
diff --git a/src/mesh/Allwmake b/src/mesh/Allwmake
index 52ef361a9fd..f9d7193a10f 100755
--- a/src/mesh/Allwmake
+++ b/src/mesh/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType snappyHexMesh
 wmake $targetType blockMesh
 wmake $targetType extrudeModel
diff --git a/src/parallel/Allwmake b/src/parallel/Allwmake
index a588a2b796e..15aba58375d 100755
--- a/src/parallel/Allwmake
+++ b/src/parallel/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 decompose/Allwmake $targetType $*
 reconstruct/Allwmake $targetType $*
 wmake $targetType distributed
diff --git a/src/parallel/decompose/Allwmake b/src/parallel/decompose/Allwmake
index f3711333487..b745c6a5032 100755
--- a/src/parallel/decompose/Allwmake
+++ b/src/parallel/decompose/Allwmake
@@ -1,220 +1,14 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                         # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+. $WM_PROJECT_DIR/wmake/scripts/have_kahip
+. $WM_PROJECT_DIR/wmake/scripts/have_metis
+. $WM_PROJECT_DIR/wmake/scripts/have_scotch
 
-: ${FOAM_EXT_LIBBIN:=/usr/lib$WM_COMPILER_LIB_ARCH}  # Extra safety
-export FOAM_EXT_LIBBIN
-
-# Check for the existence of any of the files
-# On success, echoes the file found and returns 0, otherwise returns 2
-findFirstFile()
-{
-    local file
-    for file
-    do
-        if [ -f "$file" -a -r "$file" ]
-        then
-            echo "$file"
-            return 0
-        fi
-    done
-
-    return 2
-}
-
-
-# Test for kahip.
-# - return 0 and export KAHIP_ARCH_PATH on success
-hasKahip()
-{
-    local warning="==> skip kahip"
-    local header label settings
-
-    unset KAHIP_ARCH_PATH KAHIP_VERSION
-    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/kahip) || {
-        echo "$warning (no config.sh/kahip settings)"
-        return 1
-    }
-
-    . $settings
-    if [ -z "$KAHIP_ARCH_PATH" -o "${KAHIP_ARCH_PATH##*-}" = none ]
-    then
-        echo "$warning (not available)"
-        return 1
-    fi
-
-    # Header
-    header=$(findFirstFile \
-        $KAHIP_ARCH_PATH/include/kaHIP_interface.h \
-        /usr/include/kaHIP_interface.h \
-    ) || {
-        echo "$warning (no header)"
-        return 2  # file not found
-    }
-
-    # Library
-    [ "${KAHIP_ARCH_PATH##*-}" = system ] || \
-    findFirstFile \
-        $FOAM_EXT_LIBBIN/libkahip.so \
-        $KAHIP_ARCH_PATH/lib/libkahip.a  \
-        $KAHIP_ARCH_PATH/lib/libkahip.so \
-        $KAHIP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libkahip.a \
-        $KAHIP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libkahip.so \
-    > /dev/null || {
-        echo "$warning (missing library)"
-        return 2
-    }
-
-    # kahip itself is 32-bit int, but our interface itself handles some
-    # 64-bit conversion (mesh size).
-
-    export KAHIP_ARCH_PATH
-    echo "kahip (label=32) - $KAHIP_ARCH_PATH"
-}
-
-
-# Test for metis.
-# - return 0 and export METIS_ARCH_PATH on success
-hasMetis()
-{
-    local warning="==> skip metis"
-    local header label settings
-
-    unset METIS_ARCH_PATH METIS_VERSION
-    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/metis) || {
-        echo "$warning (no config.sh/metis settings)"
-        return 1
-    }
-
-    . $settings
-    if [ -z "$METIS_ARCH_PATH" -o "${METIS_ARCH_PATH##*-}" = none ]
-    then
-        echo "$warning (not available)"
-        return 1
-    fi
-
-    # Header
-    header=$(findFirstFile \
-        $METIS_ARCH_PATH/include/metis.h \
-        /usr/include/metis.h \
-    ) || {
-        echo "$warning (no header)"
-        return 2  # file not found
-    }
-
-    # Library
-    [ "${METIS_ARCH_PATH##*-}" = system ] || \
-    findFirstFile \
-        $FOAM_EXT_LIBBIN/libmetis.so \
-        $METIS_ARCH_PATH/lib/libmetis.a \
-        $METIS_ARCH_PATH/lib/libmetis.so \
-        $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmetis.a \
-        $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmetis.so \
-    > /dev/null || {
-        echo "$warning (missing library)"
-        return 2
-    }
-
-    # Ensure consistent sizes between OpenFOAM and metis header
-    # Extract IDXTYPEWIDTH from metis.h: regex as per ThirdParty Allwmake
-    label=$(sed -ne 's/^.*#define  *IDXTYPEWIDTH  *\([1-9][0-9]\).*/\1/p' $header)
-    : ${label:=unknown}
-
-    if [ "$WM_LABEL_SIZE" = "$label" ]
-    then
-        echo "Metis (label=$label) - $METIS_ARCH_PATH"
-        export METIS_ARCH_PATH
-    else
-        echo "$warning (label=$WM_LABEL_SIZE, metis.h has '$label')"
-        return 1
-    fi
-}
-
-
-# Test for scotch.
-# - return 0 and export SCOTCH_ARCH_PATH, SCOTCH_VERSION on success
-hasScotch()
-{
-    local warning="==> skip scotch"
-    local header label settings
-
-    unset SCOTCH_ARCH_PATH SCOTCH_VERSION
-    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch) || {
-        echo "$warning (no config.sh/scotch settings)"
-        return 1
-    }
-
-    . $settings
-    if [ -z "$SCOTCH_ARCH_PATH" -o "${SCOTCH_ARCH_PATH##*-}" = none ]
-    then
-        echo "$warning (not available)"
-        return 1
-    fi
-
-    # Header
-    header=$(findFirstFile \
-        $SCOTCH_ARCH_PATH/include/scotch.h \
-        /usr/include/scotch/scotch.h \
-        /usr/include/scotch.h
-    ) || {
-        echo "$warning (no header)"
-        return 2  # file not found
-    }
-
-    # Library
-    [ "${SCOTCH_ARCH_PATH##*-}" = system ] || \
-    findFirstFile \
-        $FOAM_EXT_LIBBIN/libscotch.so \
-        $SCOTCH_ARCH_PATH/lib/libscotch.a \
-        $SCOTCH_ARCH_PATH/lib/libscotch.so \
-        $SCOTCH_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libscotch.a \
-        $SCOTCH_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libscotch.so \
-    > /dev/null || {
-        echo "$warning (missing library)"
-        return 2
-    }
-
-    # Ensure consistent sizes between OpenFOAM and scotch header
-    # extract 'typedef int64_t SCOTCH_Num' or equivalent
-    label=$(sed -ne \
-        's/^.*typedef *\([^ ]*\) *SCOTCH_Num.*/\1/ip' \
-        "$header")
-
-    : ${label:=unknown}
-
-    # No SCOTCH_VERSION set? Try to obtain from header
-    # extract #define SCOTCH_VERSION, SCOTCH_RELEASE, SCOTCH_PATCHLEVEL
-    [ -n "$SCOTCH_VERSION" ] || \
-    SCOTCH_VERSION=$(
-        eval $(
-            sed -ne \
-            's/^ *#define *SCOTCH_\(VERSION\|RELEASE\|PATCHLEVEL\) *\([0-9][0-9]*\).*$/\1=\2/p' \
-            "$header"
-        )
-
-        set -- $VERSION $RELEASE $PATCHLEVEL
-        IFS="."
-        [ "$#" -gt 0 ] && echo "scotch-$*"
-    )
-
-    # Failsafe value
-    : ${SCOTCH_VERSION:=scotch}
-
-    case "$WM_LABEL_SIZE:$label" in
-    (32:int32_t | 32:int | 64:int64_t | 64:long)
-        echo "Scotch (label=$label) - $SCOTCH_ARCH_PATH"
-        export SCOTCH_ARCH_PATH SCOTCH_VERSION
-        ;;
-
-    *)
-        echo "$warning (label='$WM_LABEL_SIZE', scotch.h has '$label')"
-        return 1
-        ;;
-    esac
-}
+#------------------------------------------------------------------------------
 
+: ${FOAM_EXT_LIBBIN:=/usr/lib$WM_COMPILER_LIB_ARCH}  # Extra safety?
+export FOAM_EXT_LIBBIN
 
 #
 # Define how to create an mpi-versioned library of $targetType
@@ -244,7 +38,7 @@ wmakeMpiLib()
 
 wmakeLnInclude -u decompositionMethods
 
-if hasScotch
+if have_scotch
 then
     wmake $targetType scotchDecomp
     if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ]
@@ -253,12 +47,12 @@ then
     fi
 fi
 
-if hasMetis
+if have_metis
 then
     wmake $targetType metisDecomp
 fi
 
-if hasKahip
+if have_kahip
 then
     wmake $targetType kahipDecomp
 fi
diff --git a/src/parallel/decompose/kahipDecomp/Make/options b/src/parallel/decompose/kahipDecomp/Make/options
index fcd1c5d268a..98706a61656 100644
--- a/src/parallel/decompose/kahipDecomp/Make/options
+++ b/src/parallel/decompose/kahipDecomp/Make/options
@@ -1,15 +1,10 @@
 EXE_INC = \
-    -I$(KAHIP_ARCH_PATH)/include \
+    -I$(KAHIP_INC_DIR) \
     -I../decompositionMethods/lnInclude
 
 /*
- * The $(KAHIP_ARCH_PATH)/lib$WM_COMPILER_LIB_ARCH path is provided
- * to support central, non-thirdparty installations.
- *
- * KaHIP is often compiled with openmp, but may be missing the
- * link dependency for openmp.
+ * KaHIP is usually compiled with openmp, but may be missing the
+ * openmp link dependency.
  */
 LIB_LIBS = \
-    -L$(KAHIP_ARCH_PATH)/lib \
-    -L$(KAHIP_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -L$(FOAM_EXT_LIBBIN) $(LINK_OPENMP) -lkahip
+    -L$(KAHIP_LIB_DIR) $(LINK_OPENMP) -lkahip
diff --git a/src/parallel/decompose/metisDecomp/Make/options b/src/parallel/decompose/metisDecomp/Make/options
index a832e26823f..c44099aa7ee 100644
--- a/src/parallel/decompose/metisDecomp/Make/options
+++ b/src/parallel/decompose/metisDecomp/Make/options
@@ -1,14 +1,6 @@
 EXE_INC = \
-    /* -DFULLDEBUG -g -O0 */ \
-    -I$(METIS_ARCH_PATH)/include \
+    -I$(METIS_INC_DIR) \
     -I../decompositionMethods/lnInclude
 
-/*
- * The $(METIS_ARCH_PATH)/lib$WM_COMPILER_LIB_ARCH path is provided
- * to support central, non-thirdparty installations
- */
 LIB_LIBS = \
-    -L$(METIS_ARCH_PATH)/lib \
-    -L$(METIS_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -L$(FOAM_EXT_LIBBIN) \
-    -lmetis
+    -L$(METIS_LIB_DIR) -lmetis
diff --git a/src/parallel/decompose/ptscotchDecomp/Make/options b/src/parallel/decompose/ptscotchDecomp/Make/options
index 51ae4a6662c..72c68165664 100644
--- a/src/parallel/decompose/ptscotchDecomp/Make/options
+++ b/src/parallel/decompose/ptscotchDecomp/Make/options
@@ -3,21 +3,16 @@ sinclude $(RULES)/mplib$(WM_MPLIB)
 
 EXE_INC = \
     $(PFLAGS) $(PINC) \
+    -I../decompositionMethods/lnInclude \
     -I$(SCOTCH_ARCH_PATH)/include/$(FOAM_MPI) \
-    -I$(SCOTCH_ARCH_PATH)/include \
-    -I/usr/include/scotch \
-    -I../decompositionMethods/lnInclude
+    -I$(SCOTCH_INC_DIR)
 
 /*
  * The '-lscotch' is a slight hack:
  * ptscotch 6 requires scotch linked in, but does not declare the dependency
- *
- * The $(SCOTCH_ARCH_PATH)/lib$WM_COMPILER_LIB_ARCH path is provided
- * to support central, non-thirdparty installations
  */
 LIB_LIBS = \
-    -L$(SCOTCH_ARCH_PATH)/lib \
-    -L$(SCOTCH_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
+    -L$(SCOTCH_LIB_DIR) \
     -L$(FOAM_EXT_LIBBIN) \
     -L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) \
     -lptscotch \
diff --git a/src/parallel/decompose/scotchDecomp/Make/options b/src/parallel/decompose/scotchDecomp/Make/options
index 1ca71f6a683..ebf3fa21b43 100644
--- a/src/parallel/decompose/scotchDecomp/Make/options
+++ b/src/parallel/decompose/scotchDecomp/Make/options
@@ -7,18 +7,8 @@ sinclude $(RULES)/mplib$(WM_MPLIB)
 
 EXE_INC = \
     $(PFLAGS) $(PINC) \
-    -I$(SCOTCH_ARCH_PATH)/include \
-    -I/usr/include/scotch \
+    -I$(SCOTCH_INC_DIR) \
     -I../decompositionMethods/lnInclude
 
-/*
- * The $(SCOTCH_ARCH_PATH)/lib$WM_COMPILER_LIB_ARCH path is provided
- * to support central, non-thirdparty installations
- */
 LIB_LIBS = \
-    -L$(SCOTCH_ARCH_PATH)/lib \
-    -L$(SCOTCH_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -L$(FOAM_EXT_LIBBIN) \
-    -lscotch \
-    -lscotcherrexit \
-    -lrt
+    -L$(SCOTCH_LIB_DIR) -lscotch -lscotcherrexit -lrt
diff --git a/src/parallel/reconstruct/Allwmake b/src/parallel/reconstruct/Allwmake
index d9ebb6fc900..d5089a9c462 100755
--- a/src/parallel/reconstruct/Allwmake
+++ b/src/parallel/reconstruct/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType reconstruct
 
 #------------------------------------------------------------------------------
diff --git a/src/randomProcesses/Allwmake b/src/randomProcesses/Allwmake
index db8daca130e..c81ffedf781 100755
--- a/src/randomProcesses/Allwmake
+++ b/src/randomProcesses/Allwmake
@@ -1,14 +1,13 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
-targetType=libso
+cd ${0%/*} || exit 1                        # Run from this directory
+targetType=libso                            # Preferred library type
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+. $WM_PROJECT_DIR/wmake/scripts/have_fftw
+
+#------------------------------------------------------------------------------
 
-if [ -f "$FFTW_ARCH_PATH/include/fftw3.h" ] || \
-   [ "${FFTW_ARCH_PATH##*-}" = system -a -f "/usr/include/fftw3.h" ]
+if have_fftw
 then
-    # If it fails, we want to know.
     wmake $targetType
 else
     echo "==> skip randomProcesses library (no FFTW)"
diff --git a/src/randomProcesses/Make/options b/src/randomProcesses/Make/options
index 233247dccd5..6bb57027c0b 100644
--- a/src/randomProcesses/Make/options
+++ b/src/randomProcesses/Make/options
@@ -1,12 +1,10 @@
 EXE_INC = \
-    -I$(FFTW_ARCH_PATH)/include \
     -I$(LIB_SRC)/finiteVolume/lnInclude \
     -I$(LIB_SRC)/sampling/lnInclude \
-    -I$(LIB_SRC)/surfMesh/lnInclude
+    -I$(LIB_SRC)/surfMesh/lnInclude \
+    -I$(FFTW_INC_DIR)
 
 LIB_LIBS = \
-    -L$(FFTW_ARCH_PATH)/lib \
-    -L$(FFTW_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -lfftw3 \
+    -L$(FFTW_LIB_DIR) -lfftw3 \
     -lfiniteVolume \
     -lsampling
diff --git a/src/regionModels/Allwmake b/src/regionModels/Allwmake
index 1f2348ee2c4..d29ed140c7c 100755
--- a/src/regionModels/Allwmake
+++ b/src/regionModels/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType regionModel
 wmake $targetType pyrolysisModels
 wmake $targetType surfaceFilmModels
diff --git a/src/renumber/Allwmake b/src/renumber/Allwmake
index aef86c64506..c8122c5a886 100755
--- a/src/renumber/Allwmake
+++ b/src/renumber/Allwmake
@@ -1,29 +1,25 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
-targetType=libso
+cd ${0%/*} || exit 1                        # Run from this directory
+targetType=libso                            # Preferred library type
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
+. $WM_PROJECT_DIR/wmake/scripts/have_boost
+. $WM_PROJECT_DIR/wmake/scripts/have_zoltan
 
-# Optional: get ZOLTAN_ARCH_PATH
-if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/zoltan)
-then
-    . $settings
-fi
+#------------------------------------------------------------------------------
 
 wmake $targetType renumberMethods
 
 warning="==> skip SloanRenumber"
-if [ -f "$BOOST_ARCH_PATH/include/boost/version.hpp" ] || \
-   [ "${BOOST_ARCH_PATH##*-}" = system -a -f /usr/include/boost/version.hpp ]
+if have_boost
 then
     wmake $targetType SloanRenumber || echo "$warning (build issues detected)"
 else
     echo "$warning (no boost)"
 fi
 
+
 warning="==> skip zoltanRenumber"
-if [ -d "$ZOLTAN_ARCH_PATH" ]
+if have_zoltan
 then
     wmake $targetType zoltanRenumber || echo "$warning (build issues detected)"
 else
diff --git a/src/renumber/SloanRenumber/Make/options b/src/renumber/SloanRenumber/Make/options
index b76ce9a4bcf..23dc9dd623f 100644
--- a/src/renumber/SloanRenumber/Make/options
+++ b/src/renumber/SloanRenumber/Make/options
@@ -1,14 +1,12 @@
 EXE_INC = \
     ${c++LESSWARN} \
-    -I$(BOOST_ARCH_PATH)/include \
+    -I$(BOOST_INC_DIR) \
     -I$(LIB_SRC)/meshTools/lnInclude \
     -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude \
     -I$(LIB_SRC)/renumber/renumberMethods/lnInclude
 
 LIB_LIBS = \
-    -L$(BOOST_ARCH_PATH)/lib \
-    -L$(BOOST_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -lboost_system \
+    -L$(BOOST_LIB_DIR) -lboost_system \
     -lmeshTools \
     -ldecompositionMethods \
     -lrenumberMethods
diff --git a/src/renumber/zoltanRenumber/Make/options b/src/renumber/zoltanRenumber/Make/options
index e92e24e0962..79dc4f2bc89 100644
--- a/src/renumber/zoltanRenumber/Make/options
+++ b/src/renumber/zoltanRenumber/Make/options
@@ -2,15 +2,12 @@ sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB)
 sinclude $(RULES)/mplib$(WM_MPLIB)
 
 EXE_INC = \
-    /* -DFULLDEBUG -g -O0 */ \
     $(PFLAGS) $(PINC) \
     ${c++LESSWARN} \
     -I$(LIB_SRC)/renumber/renumberMethods/lnInclude \
     -I$(LIB_SRC)/meshTools/lnInclude \
-    -I$(ZOLTAN_ARCH_PATH)/include
+    -I$(ZOLTAN_INC_DIR)
 
 LIB_LIBS = \
-    -L$(ZOLTAN_ARCH_PATH)/lib \
-    -L$(ZOLTAN_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -lzoltan \
+    -L$(ZOLTAN_LIB_DIR) -lzoltan \
     -lmeshTools
diff --git a/src/thermophysicalModels/Allwmake b/src/thermophysicalModels/Allwmake
index 2d59e0aae5a..520a2d0af2b 100755
--- a/src/thermophysicalModels/Allwmake
+++ b/src/thermophysicalModels/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType specie
 wmake $targetType solidSpecie
 wmake $targetType thermophysicalProperties
diff --git a/src/transportModels/Allwmake b/src/transportModels/Allwmake
index b533c83c310..4790540e340 100755
--- a/src/transportModels/Allwmake
+++ b/src/transportModels/Allwmake
@@ -1,9 +1,9 @@
 #!/bin/sh
-cd ${0%/*} || exit 1    # Run from this directory
-
-# Parse arguments for library compilation
+cd ${0%/*} || exit 1                        # Run from this directory
 . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
 
+#------------------------------------------------------------------------------
+
 wmake $targetType twoPhaseMixture
 wmake $targetType interfaceProperties
 wmake $targetType twoPhaseProperties
diff --git a/wmake/scripts/have_boost b/wmake/scripts/have_boost
new file mode 100644
index 00000000000..c1cd39dbc17
--- /dev/null
+++ b/wmake/scripts/have_boost
@@ -0,0 +1,127 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_boost
+#
+# Description
+#     Detection/setup of Boost
+#
+# Requires
+#     BOOST_ARCH_PATH
+#
+# Functions provided
+#     have_boost, no_boost, echo_boost
+#
+# Variables set on success
+#     HAVE_BOOST
+#     BOOST_ARCH_PATH
+#     BOOST_INC_DIR
+#     BOOST_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_boost()
+{
+    unset HAVE_BOOST BOOST_INC_DIR BOOST_LIB_DIR
+    return 0
+}
+
+
+# Report
+echo_boost()
+{
+    echo "boost=${HAVE_BOOST:-false}"
+    echo "root=$BOOST_ARCH_PATH"
+    echo "include=$BOOST_INC_DIR"
+    echo "library=$BOOST_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_BOOST, BOOST_INC_DIR, BOOST_LIB_DIR
+have_boost()
+{
+    local header library static label settings warn
+    # warn="==> skip boost"
+
+    # Basic setup/checks
+    if isNone "$BOOST_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="boost/version.hpp"
+    library="libboost_system$extLibso"
+
+
+    if hasAbsdir "$BOOST_ARCH_PATH"
+    then
+        header=$(findFirstFile $BOOST_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $BOOST_ARCH_PATH/lib/$library \
+            $BOOST_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$BOOST_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+    header="${header%/*}"     # Strip one-level (include/boost/...)
+
+    export HAVE_BOOST=true
+    export BOOST_ARCH_PATH
+    export BOOST_INC_DIR="${header%/*}"     # Basename
+    export BOOST_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_boost
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_boost
+    echo_boost
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_ccmio b/wmake/scripts/have_ccmio
new file mode 100644
index 00000000000..a957415b6f7
--- /dev/null
+++ b/wmake/scripts/have_ccmio
@@ -0,0 +1,145 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_ccmio
+#
+# Description
+#     Detection/setup of ccmio
+#
+# Requires
+#     config.sh/ccmio
+#
+# Functions provided
+#     have_ccmio, no_ccmio, echo_ccmio
+#
+# Variables set on success
+#     HAVE_CCMIO
+#     CCMIO_ARCH_PATH
+#     CCMIO_INC_DIR
+#     CCMIO_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_ccmio()
+{
+    unset HAVE_CCMIO CCMIO_INC_DIR CCMIO_LIB_DIR
+    return 0
+}
+
+# Report
+echo_ccmio()
+{
+    echo "ccmio=${HAVE_CCMIO:-false}"
+    echo "root=$CCMIO_ARCH_PATH"
+    echo "include=$CCMIO_INC_DIR"
+    echo "library=$CCMIO_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_CCMIO, CCMIO_INC_DIR, CCMIO_LIB_DIR
+have_ccmio()
+{
+    local header library static label settings warn good
+    warn="==> skip ccmio"
+
+    # Basic setup/checks
+    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/ccmio) || {
+        [ -n "$warn" ] && echo "$warn (no config.sh/ccmio settings)"
+        return 1
+    }
+    . $settings
+    if isNone "$CCMIO_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names.
+    # Link with static libccmio only (fewer issues)
+    #
+    header="libccmio/ccmio.h"
+    static="libccmio$extLiba"
+
+
+    if hasAbsdir "$CCMIO_ARCH_PATH"
+    then
+        header=$(findFirstFile $CCMIO_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $CCMIO_ARCH_PATH/lib/$static \
+            $CCMIO_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$static \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+    header="${header%/*}"     # Strip one-level (include/libccmio/...)
+
+    # The libccmio uses int32_t.
+    # The OpenFOAM adapter thus requires additional work for 64-bit labels.
+    # The OpenFOAM adapter was originally only designed for 'double'
+
+    if [ "$WM_LABEL_SIZE" = 32 ]
+    then
+        if [ "$WM_PRECISION_OPTION" = DP ]
+        then
+            good=true
+        else
+            [ -n "$warn" ] && echo "$warn (double precision only)"
+            no_ccmio
+            return 1
+        fi
+    else
+        [ -n "$warn" ] && echo "$warn (32-bit labels only)"
+        no_ccmio
+        return 1
+    fi
+
+    export HAVE_CCMIO=true
+    export CCMIO_ARCH_PATH
+    export CCMIO_INC_DIR="${header%/*}"     # Basename
+    export CCMIO_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_ccmio
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_ccmio
+    echo_ccmio
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_cgal b/wmake/scripts/have_cgal
new file mode 100644
index 00000000000..9c14b0caec9
--- /dev/null
+++ b/wmake/scripts/have_cgal
@@ -0,0 +1,127 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_cgal
+#
+# Description
+#     Detection/setup of CGAL
+#
+# Requires
+#     CGAL_ARCH_PATH
+#
+# Functions provided
+#     have_cgal, no_cgal, echo_cgal
+#
+# Variables set on success
+#     HAVE_CGAL
+#     CGAL_ARCH_PATH
+#     CGAL_INC_DIR
+#     CGAL_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_cgal()
+{
+    unset HAVE_CGAL CGAL_INC_DIR CGAL_LIB_DIR
+    return 0
+}
+
+
+# Reset variables
+echo_cgal()
+{
+    echo "cgal=${HAVE_CGAL:-false}"
+    echo "root=$CGAL_ARCH_PATH"
+    echo "include=$CGAL_INC_DIR"
+    echo "library=$CGAL_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_CGAL, CGAL_INC_DIR, CGAL_LIB_DIR
+have_cgal()
+{
+    local header library static label settings warn
+    # warn="==> skip cgal"
+
+    # Basic setup/checks
+    if isNone "$CGAL_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="CGAL/version.h"
+    library="libCGAL$extLibso"
+
+
+    if hasAbsdir "$CGAL_ARCH_PATH"
+    then
+        header=$(findFirstFile $CGAL_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $CGAL_ARCH_PATH/lib/$library \
+            $CGAL_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$CGAL_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+    header="${header%/*}"     # Strip one-level (include/CGAL/...)
+
+    export HAVE_CGAL=true
+    export CGAL_ARCH_PATH
+    export CGAL_INC_DIR="${header%/*}"     # Basename
+    export CGAL_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_cgal
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_cgal
+    echo_cgal
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_fftw b/wmake/scripts/have_fftw
new file mode 100644
index 00000000000..d3e87c5daba
--- /dev/null
+++ b/wmake/scripts/have_fftw
@@ -0,0 +1,125 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_fftw
+#
+# Description
+#     Detection/setup of FFTW
+#
+# Requires
+#     FFTW_ARCH_PATH
+#
+# Functions provided
+#     have_fftw, no_fftw, echo_fftw
+#
+# Variables set on success
+#     HAVE_FFTW
+#     FFTW_ARCH_PATH
+#     FFTW_INC_DIR
+#     FFTW_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_fftw()
+{
+    unset HAVE_FFTW FFTW_INC_DIR FFTW_LIB_DIR
+    return 0
+}
+
+
+# Report
+echo_fftw()
+{
+    echo "fftw=${HAVE_FFTW:-false}"
+    echo "root=$FFTW_ARCH_PATH"
+    echo "include=$FFTW_INC_DIR"
+    echo "library=$FFTW_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_FFTW, FFTW_INC_DIR, FFTW_LIB_DIR
+have_fftw()
+{
+    local header library static label settings warn
+    # warn="==> skip fftw"
+
+    # Basic setup/checks
+    if isNone "$FFTW_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="fftw3.h"
+    library="libfftw3$extLibso"
+
+
+    if hasAbsdir "$FFTW_ARCH_PATH"
+    then
+        header=$(findFirstFile $FFTW_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $FFTW_ARCH_PATH/lib/$library \
+            $FFTW_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$FFTW_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+    export HAVE_FFTW=true
+    export FFTW_ARCH_PATH
+    export FFTW_INC_DIR="${header%/*}"     # Basename
+    export FFTW_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_fftw
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_fftw
+    echo_fftw
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_kahip b/wmake/scripts/have_kahip
new file mode 100644
index 00000000000..84e8cbde35c
--- /dev/null
+++ b/wmake/scripts/have_kahip
@@ -0,0 +1,138 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_kahip
+#
+# Description
+#     Detection/setup of KAHIP
+#
+# Requires
+#     config.sh/kahip
+#
+# Functions provided
+#     have_kahip, no_kahip, echo_kahip
+#
+# Variables set on success
+#     HAVE_KAHIP
+#     KAHIP_ARCH_PATH
+#     KAHIP_INC_DIR
+#     KAHIP_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_kahip()
+{
+    unset HAVE_KAHIP KAHIP_ARCH_PATH KAHIP_INC_DIR KAHIP_LIB_DIR
+    unset KAHIP_VERSION
+    return 0
+}
+
+
+# Report
+echo_kahip()
+{
+    echo "kahip=${HAVE_KAHIP:-false}"
+    echo "root=$KAHIP_ARCH_PATH"
+    echo "include=$KAHIP_INC_DIR"
+    echo "library=$KAHIP_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_KAHIP, KAHIP_ARCH_PATH, KAHIP_INC_DIR, KAHIP_LIB_DIR
+have_kahip()
+{
+    local header library static label settings warn
+    warn="==> skip kahip"
+
+    # Basic setup/checks
+    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/kahip) || {
+        [ -n "$warn" ] && echo "$warn (no config.sh/kahip settings)"
+        return 1
+    }
+    . $settings
+    if isNone "$KAHIP_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="kaHIP_interface.h"
+    library="libkahip$extLibso"
+    static="libkahip$extLiba"
+
+    if hasAbsdir "$KAHIP_ARCH_PATH"
+    then
+        header=$(findFirstFile $KAHIP_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $METIS_ARCH_PATH/lib/$static \
+            $METIS_ARCH_PATH/lib/$library \
+            $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$static \
+            $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$KAHIP_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+
+    # kahip itself is 32-bit int, but our interface itself handles some
+    # 64-bit conversion (mesh size).
+
+    echo "kahip (label=32) - $KAHIP_ARCH_PATH"
+    export HAVE_KAHIP=true
+    export KAHIP_ARCH_PATH
+    export KAHIP_INC_DIR="${header%/*}"     # Basename
+    export KAHIP_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_kahip
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_kahip
+    echo_kahip
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_metis b/wmake/scripts/have_metis
new file mode 100644
index 00000000000..ec5b185c041
--- /dev/null
+++ b/wmake/scripts/have_metis
@@ -0,0 +1,151 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_metis
+#
+# Description
+#     Detection/setup of metis
+#
+# Requires
+#     config.sh/metis
+#
+# Functions provided
+#     have_metis, no_metis, echo_metis
+#
+# Variables set on success
+#     HAVE_METIS
+#     METIS_ARCH_PATH
+#     METIS_INC_DIR
+#     METIS_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_metis()
+{
+    unset HAVE_METIS METIS_ARCH_PATH METIS_INC_DIR METIS_LIB_DIR
+    unset METIS_VERSION
+    return 0
+}
+
+
+# Report
+echo_metis()
+{
+    echo "metis=${HAVE_METIS:-false}"
+    echo "root=$METIS_ARCH_PATH"
+    echo "include=$METIS_INC_DIR"
+    echo "library=$METIS_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_METIS, METIS_ARCH_PATH, METIS_INC_DIR, METIS_LIB_DIR
+have_metis()
+{
+    local header library static label settings warn
+    warn="==> skip metis"
+
+    # Basic setup/checks
+    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/metis) || {
+        [ -n "$warn" ] && echo "$warn (no config.sh/metis settings)"
+        return 1
+    }
+    . $settings
+    if isNone "$METIS_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="metis.h"
+    library="libmetis$extLibso"
+    static="libmetis$extLiba"
+
+
+    if hasAbsdir "$METIS_ARCH_PATH"
+    then
+        header=$(findFirstFile $METIS_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $METIS_ARCH_PATH/lib/$static \
+            $METIS_ARCH_PATH/lib/$library \
+            $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$static \
+            $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$METIS_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+
+    # Ensure consistent sizes between OpenFOAM and metis header
+    # Extract IDXTYPEWIDTH from metis.h: regex as per ThirdParty Allwmake
+    label=$(sed -ne 's/^.*#define  *IDXTYPEWIDTH  *\([1-9][0-9]\).*/\1/p' $header)
+    : ${label:=unknown}
+
+    if [ "$WM_LABEL_SIZE" = "$label" ]
+    then
+        echo "Metis (label=$label) - $METIS_ARCH_PATH"
+        export HAVE_METIS=true
+        export METIS_ARCH_PATH
+        export METIS_INC_DIR="${header%/*}"     # Basename
+        export METIS_LIB_DIR="${library%/*}"    # Basename
+    else
+        if [ -n "$warn" ]
+        then
+            echo "$warn (label=$WM_LABEL_SIZE, metis.h has '$label')"
+        fi
+        no_metis
+        return 1
+    fi
+}
+
+
+# Force reset of old variables
+no_metis
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_metis
+    echo_metis
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_mgridgen b/wmake/scripts/have_mgridgen
new file mode 100644
index 00000000000..3c232c43fb5
--- /dev/null
+++ b/wmake/scripts/have_mgridgen
@@ -0,0 +1,177 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_mgridgen
+#
+# Description
+#     Detection/setup of mgridgen
+#
+# Requires
+#     config.sh/mgridgen
+#
+# Functions provided
+#     have_mgridgen, no_mgridgen, echo_mgridgen
+#
+# Variables set on success
+#     HAVE_MGRIDGEN
+#     MGRIDGEN_ARCH_PATH
+#     MGRIDGEN_INC_DIR
+#     MGRIDGEN_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_mgridgen()
+{
+    unset HAVE_MGRIDGEN MGRIDGEN_ARCH_PATH MGRIDGEN_INC_DIR MGRIDGEN_LIB_DIR
+    unset MGRIDGEN_VERSION
+    return 0
+}
+
+
+# Report
+echo_mgridgen()
+{
+    echo "mgridgen=${HAVE_MGRIDGEN:-false}"
+    echo "root=$MGRIDGEN_ARCH_PATH"
+    echo "include=$MGRIDGEN_INC_DIR"
+    echo "library=$MGRIDGEN_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_MGRIDGEN, MGRIDGEN_ARCH_PATH, MGRIDGEN_INC_DIR, MGRIDGEN_LIB_DIR
+have_mgridgen()
+{
+    local header library static label scalar settings warn good
+    warn="==> skip mgridgen"
+
+    # Basic setup/checks
+    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/mgridgen) || {
+        #silent# [ -n "$warn" ] && echo "$warn (no config.sh/mgridgen settings)"
+        return 1
+    }
+    . $settings
+    if isNone "$MGRIDGEN_ARCH_PATH"
+    then
+        #silent# [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="mgridgen.h"
+    library="libMGridGen$extLibso"
+    static="libmgrid$extLiba"
+
+
+    if hasAbsdir "$MGRIDGEN_ARCH_PATH"
+    then
+        header=$(findFirstFile $MGRIDGEN_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $MGRIDGEN_ARCH_PATH/lib/$static \
+            $MGRIDGEN_ARCH_PATH/lib/$library \
+            $MGRIDGEN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$static \
+            $MGRIDGEN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$MGRIDGEN_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        #silent# [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        #silent# [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+
+    # Ensure consistent sizes with OpenFOAM and mgridgen header
+    # Extract typedef for idxtype, realtype
+    label=$(sed -ne \
+        's/^.*typedef *\([^ ]*\) *idxtype.*/\1/ip' \
+        "$header")
+    scalar=$(sed -ne \
+        's/^.*typedef *\([^ ]*\) *realtype.*/\1/ip' \
+        "$header")
+
+    : ${label:=unknown}
+    : ${scalar:=unknown}
+
+
+    case "$WM_LABEL_SIZE:$label" in
+    (32:int32_t | 32:int | 64:int64_t | 64:long)
+        good=true
+        ;;
+
+    *)
+        if [ -n "$warn" ]
+        then
+            echo "$warn (label='$WM_LABEL_SIZE', mgridgen.h has '$label')"
+        fi
+        return 1
+        ;;
+    esac
+    case "$WM_PRECISION_OPTION:$scalar" in
+    (SP:float | DP:double)
+        good=true
+        ;;
+
+    *)
+        if [ -n "$warn" ]
+        then
+            echo "$warn (scalar='$WM_PRECISION_OPTION', mgridgen.h has '$scalar')"
+        fi
+        return 1
+        ;;
+    esac
+
+    # OK
+    echo "mgridgen (label=$label, scalar=$scalar) - $MGRIDGEN_ARCH_PATH"
+    export HAVE_MGRIDGEN=true
+    export MGRIDGEN_ARCH_PATH MGRIDGEN_VERSION
+    export MGRIDGEN_INC_DIR="${header%/*}"     # Basename
+    export MGRIDGEN_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_mgridgen
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_mgridgen
+    echo_mgridgen
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_readline b/wmake/scripts/have_readline
new file mode 100644
index 00000000000..db85cdf0e83
--- /dev/null
+++ b/wmake/scripts/have_readline
@@ -0,0 +1,101 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_readline
+#
+# Description
+#     Detection/setup of readline
+#
+# Requires
+#     None
+#
+# Functions provided
+#     have_readline, no_readline, echo_readline
+#
+# Variables set on success
+#     HAVE_LIBREADLINE - as per GNU autoconf
+#     READLINE_INC_DIR
+#     READLINE_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_readline()
+{
+    unset HAVE_LIBREADLINE READLINE_INC_DIR READLINE_LIB_DIR
+    return 0
+}
+
+
+# Report
+echo_readline()
+{
+    echo "readline=${HAVE_LIBREADLINE:-false}"
+    echo "include=$READLINE_INC_DIR"
+    echo "library=$READLINE_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_LIBREADLINE, READLINE_INC_DIR, READLINE_LIB_DIR
+have_readline()
+{
+    local header library static settings warn
+    # warn="==> skip readline"
+
+
+    # Header/library names
+    header="readline/readline.h"
+    library="libreadline$extLibso"
+
+    # System only?
+    header=$(findFirstFile /usr/include/$header)
+
+    library=$(findFirstFile \
+        /usr/lib/$library \
+        /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+    )
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+    header="${header%/*}"     # Strip one-level (include/readline/...)
+
+    export HAVE_LIBREADLINE=true
+    export READLINE_INC_DIR="${header%/*}"     # Basename
+    export READLINE_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_readline
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_readline
+    echo_readline
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_scotch b/wmake/scripts/have_scotch
new file mode 100644
index 00000000000..2ad72ec4c6d
--- /dev/null
+++ b/wmake/scripts/have_scotch
@@ -0,0 +1,174 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_scotch
+#
+# Description
+#     Detection/setup of scotch
+#
+# Requires
+#     config.sh/scotch
+#
+# Functions provided
+#     have_scotch, no_scotch, echo_scotch
+#
+# Variables set on success
+#     HAVE_SCOTCH
+#     SCOTCH_ARCH_PATH
+#     SCOTCH_INC_DIR
+#     SCOTCH_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_scotch()
+{
+    unset HAVE_SCOTCH SCOTCH_ARCH_PATH SCOTCH_INC_DIR SCOTCH_LIB_DIR
+    unset SCOTCH_VERSION
+    return 0
+}
+
+
+# Report
+echo_scotch()
+{
+    echo "scotch=${HAVE_SCOTCH:-false}"
+    echo "root=$SCOTCH_ARCH_PATH"
+    echo "include=$SCOTCH_INC_DIR"
+    echo "library=$SCOTCH_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_SCOTCH, SCOTCH_ARCH_PATH, SCOTCH_INC_DIR, SCOTCH_LIB_DIR
+have_scotch()
+{
+    local header library static label settings warn
+    warn="==> skip scotch"
+
+    # Basic setup/checks
+    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch) || {
+        [ -n "$warn" ] && echo "$warn (no config.sh/scotch settings)"
+        return 1
+    }
+    . $settings
+    if isNone "$SCOTCH_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="scotch.h"
+    library="libscotch$extLibso"
+    static="libscotch$extLiba"
+
+
+    if hasAbsdir "$SCOTCH_ARCH_PATH"
+    then
+        header=$(findFirstFile $SCOTCH_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $SCOTCH_ARCH_PATH/lib/$static \
+            $SCOTCH_ARCH_PATH/lib/$library \
+            $SCOTCH_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$static \
+            $SCOTCH_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$SCOTCH_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header /usr/include/scotch/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+
+    # Ensure consistent sizes between OpenFOAM and scotch header
+    # extract 'typedef int64_t SCOTCH_Num' or equivalent
+    label=$(sed -ne \
+        's/^.*typedef *\([^ ]*\) *SCOTCH_Num.*/\1/ip' \
+        "$header")
+    : ${label:=unknown} # Failsafe value
+
+
+    # No SCOTCH_VERSION set? Try to obtain from header
+    # extract #define SCOTCH_VERSION, SCOTCH_RELEASE, SCOTCH_PATCHLEVEL
+    [ -n "$SCOTCH_VERSION" ] || \
+    SCOTCH_VERSION=$(
+        eval $(
+            sed -ne \
+            's/^ *#define *SCOTCH_\(VERSION\|RELEASE\|PATCHLEVEL\) *\([0-9][0-9]*\).*$/\1=\2/p' \
+            "$header"
+        )
+
+        set -- $VERSION $RELEASE $PATCHLEVEL
+        IFS="."
+        [ "$#" -gt 0 ] && echo "scotch-$*"
+    )
+    : ${SCOTCH_VERSION:=scotch} # Failsafe value
+
+
+    case "$WM_LABEL_SIZE:$label" in
+    (32:int32_t | 32:int | 64:int64_t | 64:long)
+        echo "Scotch (label=$label) - $SCOTCH_ARCH_PATH"
+        export HAVE_SCOTCH=true
+        export SCOTCH_ARCH_PATH SCOTCH_VERSION
+        export SCOTCH_INC_DIR="${header%/*}"     # Basename
+        export SCOTCH_LIB_DIR="${library%/*}"    # Basename
+        ;;
+
+    *)
+        if [ -n "$warn" ]
+        then
+            echo "$warn (label='$WM_LABEL_SIZE', scotch.h has '$label')"
+        fi
+        no_scotch
+        return 1
+        ;;
+    esac
+}
+
+
+# Force reset of old variables
+no_scotch
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_scotch
+    echo_scotch
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_zoltan b/wmake/scripts/have_zoltan
new file mode 100644
index 00000000000..bd02ac54a4e
--- /dev/null
+++ b/wmake/scripts/have_zoltan
@@ -0,0 +1,133 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     have_zoltan
+#
+# Description
+#     Detection/setup of zoltan
+#
+# Requires
+#     config.sh/zoltan
+#
+# Functions provided
+#     have_zoltan, no_zoltan, echo_zoltan
+#
+# Variables set on success
+#     HAVE_ZOLTAN
+#     ZOLTAN_ARCH_PATH
+#     ZOLTAN_INC_DIR
+#     ZOLTAN_LIB_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
+
+#------------------------------------------------------------------------------
+
+# Reset variables
+no_zoltan()
+{
+    unset HAVE_ZOLTAN ZOLTAN_INC_DIR ZOLTAN_LIB_DIR
+    return 0
+}
+
+
+# Report
+echo_zoltan()
+{
+    echo "zoltan=${HAVE_ZOLTAN:-false}"
+    echo "root=$ZOLTAN_ARCH_PATH"
+    echo "include=$ZOLTAN_INC_DIR"
+    echo "library=$ZOLTAN_LIB_DIR"
+}
+
+
+# On success, return 0 and export variables
+# -> HAVE_ZOLTAN, ZOLTAN_INC_DIR, ZOLTAN_LIB_DIR
+have_zoltan()
+{
+    local header library static label settings warn
+    # warn="==> skip zoltan"
+
+    # Basic setup/checks
+    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/zoltan) || {
+        [ -n "$warn" ] && echo "$warn (no config.sh/zoltan settings)"
+        return 1
+    }
+    . $settings
+    if isNone "$ZOLTAN_ARCH_PATH"
+    then
+        [ -n "$warn" ] && echo "$warn (not available)"
+        return 1
+    fi
+
+
+    # Header/library names
+    header="zoltan.h"
+    library="libzoltan$extLibso"
+    static="libzoltan$extLiba"
+
+
+    if hasAbsdir "$ZOLTAN_ARCH_PATH"
+    then
+        header=$(findFirstFile $ZOLTAN_ARCH_PATH/include/$header)
+
+        # FOAM_EXT_LIBBIN is allowed to be unset
+        library=$(findFirstFile \
+            $FOAM_EXT_LIBBIN/$library \
+            $ZOLTAN_ARCH_PATH/lib/$static \
+            $ZOLTAN_ARCH_PATH/lib/$library \
+            $ZOLTAN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$static \
+            $ZOLTAN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    elif isSystem "$ZOLTAN_ARCH_PATH"
+    then
+        header=$(findFirstFile /usr/include/$header)
+
+        library=$(findFirstFile \
+            /usr/lib/$library \
+            /usr/lib$WM_COMPILER_LIB_ARCH/$library \
+        )
+    else
+        unset header library
+    fi
+
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (missing library)"
+        return 2
+    }
+
+    export HAVE_ZOLTAN=true
+    export ZOLTAN_ARCH_PATH
+    export ZOLTAN_INC_DIR="${header%/*}"     # Basename
+    export ZOLTAN_LIB_DIR="${library%/*}"    # Basename
+}
+
+
+# Force reset of old variables
+no_zoltan
+
+# Testing
+if [ "$1" = "-test" ]
+then
+    have_zoltan
+    echo_zoltan
+fi
+
+#------------------------------------------------------------------------------
diff --git a/wmake/scripts/sysFunctions b/wmake/scripts/sysFunctions
new file mode 100644
index 00000000000..9b3630c749d
--- /dev/null
+++ b/wmake/scripts/sysFunctions
@@ -0,0 +1,110 @@
+#----------------------------------*-sh-*--------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# Script
+#     sysFunctions
+#
+# Description
+#     General system helper functions
+#
+# Functions provided
+#     isDarwin
+#     isNone
+#     isSystem
+#     isAbsdir, hasAbsdir
+#     findFirstFile
+#
+# Variables provided
+#     extLiba
+#     extLibso
+#
+#------------------------------------------------------------------------------
+
+if [ -z "$WMAKE_SCRIPTS_SYSFUNCTIONS" ]
+then
+    # Load once, but do not rely on this variable elsewhere
+    WMAKE_SCRIPTS_SYSFUNCTIONS=loaded
+
+    # Static library extension. Default=.a
+    extLiba=".a"
+
+    # Shared library extension. Default=.so
+    case "$(uname -s 2>/dev/null)" in
+    Darwin)
+        extLibso=".dylib"
+        ;;
+    *)
+        extLibso=".so"
+        ;;
+    esac
+
+
+    # True if OS is Darwin.
+    # Uses libso extension to cache the value
+    # (instead of calling 'uname -s' each time)
+    isDarwin()
+    {
+        test "$extLibso" = ".dylib"
+    }
+
+
+    # True if '$1' begins with '/'
+    isAbsdir()
+    {
+        test "$1" = "/${1#/}"
+    }
+
+
+    # True if '$1' begins with '/' and also exists as a directory
+    hasAbsdir()
+    {
+        test "$1" = "/${1#/}" -a -d "$1"
+    }
+
+
+    # True if '$1' is an empty string or matches "*-none".
+    # Eg,
+    #    if isNone "$KAHIP_ARCH_PATH" ...
+    isNone()
+    {
+        test -z "$1" -o "${1##*-}" = none
+    }
+
+
+    # True if '$1' matches "*-system"
+    # Eg,
+    #    if isSystem "$BOOST_ARCH_PATH"
+    isSystem()
+    {
+        test "${1##*-}" = system
+    }
+
+
+    # Check for the existence of any of the files
+    # On success, echoes the file found and returns 0, otherwise returns 2
+    findFirstFile()
+    {
+        local file
+        for file
+        do
+            if [ -f "$file" -a -r "$file" ]
+            then
+                echo "$file"
+                return 0
+            fi
+        done
+        return 2
+    }
+
+fi
+
+
+#------------------------------------------------------------------------------
-- 
GitLab