From 06333efd2d3da6d2a25c061b9773b559a04e5056 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 15 Apr 2020 12:45:26 +0200
Subject: [PATCH] CONFIG: improve detection of scotch system include/libraries

- align wmake have_* scripts to support version query as per current
  develop branch

- use config.sh/ fallbacks when the corresponding *_ARCH_PATH is empty
  (eg, BOOST, CGAL, FFTW).
  This aids when building outside of the regular OpenFOAM environment.
---
 wmake/scripts/cmakeFunctions    | 28 ++++++++---
 wmake/scripts/have_adios2       | 54 +++++++++++++-------
 wmake/scripts/have_boost        | 64 ++++++++++++++++++------
 wmake/scripts/have_ccmio        | 57 ++++++++++++++-------
 wmake/scripts/have_cgal         | 62 +++++++++++++++++------
 wmake/scripts/have_fftw         | 62 +++++++++++++++++------
 wmake/scripts/have_hypre        | 54 ++++++++++++++------
 wmake/scripts/have_kahip        | 54 +++++++++++++-------
 wmake/scripts/have_metis        | 56 ++++++++++++++-------
 wmake/scripts/have_mgridgen     | 62 +++++++++++++++--------
 wmake/scripts/have_petsc        | 56 ++++++++++++++-------
 wmake/scripts/have_readline     | 28 +++++------
 wmake/scripts/have_scotch       | 89 ++++++++++++++++++++++-----------
 wmake/scripts/have_zoltan       | 56 ++++++++++++++-------
 wmake/scripts/paraviewFunctions | 30 +++++------
 wmake/scripts/sysFunctions      | 70 +++++++++++++++++++++-----
 16 files changed, 617 insertions(+), 265 deletions(-)

diff --git a/wmake/scripts/cmakeFunctions b/wmake/scripts/cmakeFunctions
index f43a0bea799..bceed70f9e4 100644
--- a/wmake/scripts/cmakeFunctions
+++ b/wmake/scripts/cmakeFunctions
@@ -5,17 +5,17 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2017-2019 OpenCFD Ltd.
+#     Copyright (C) 2017-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     cmakeFunctions
 #
 # Description
 #     Helper functions for CMake
+#
 #------------------------------------------------------------------------------
 . ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions  # Require wmake functions
 
@@ -61,6 +61,22 @@ sameDependency()
     fi
 }
 
+#
+# Save dependency information into sentinel file
+#
+storeDependency()
+{
+    local depend="$1"
+    local sentinel="$2"
+
+    if [ -n "$sentinel" ]
+    then
+        mkdir -p "$(dirname "$sentinel")"
+        echo "$depend" >| "$sentinel"
+    fi
+    return 0
+}
+
 
 # CMake with output suppressed according to WM_QUIET
 _cmake()
@@ -98,7 +114,7 @@ cmakeVersioned()
 
     mkdir -p "$objectsDir" \
     && (cd "$objectsDir" && _cmake "$@" "$sourceDir" && make) \
-    && echo "$depend" >| "${sentinel:-/dev/null}"
+    && storeDependency "$depend" "$sentinel"
 }
 
 
@@ -124,7 +140,7 @@ cmakeVersionedInstall()
 
     mkdir -p "$objectsDir" \
     && (cd "$objectsDir" && _cmake "$@" "$sourceDir" && make install) \
-    && echo "$depend" >| "${sentinel:-/dev/null}"
+    && storeDependency "$depend" "$sentinel"
 }
 
 
@@ -151,7 +167,7 @@ wmakeVersioned()
 
     mkdir -p "$objectsDir" \
     && wmake "$@" \
-    && echo "$depend" >| "${sentinel:-/dev/null}"
+    && storeDependency "$depend" "$sentinel"
 }
 
 
diff --git a/wmake/scripts/have_adios2 b/wmake/scripts/have_adios2
index c3bfbf2d0d3..f6afaf123d3 100644
--- a/wmake/scripts/have_adios2
+++ b/wmake/scripts/have_adios2
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_adios2
@@ -21,7 +20,7 @@
 #     ADIOS2_ARCH_PATH
 #
 # Functions provided
-#     have_adios2, no_adios2, echo_adios2, hint_adios2
+#     have_adios2, no_adios2, echo_adios2, hint_adios2, query_adios2
 #
 # Variables set on success
 #     HAVE_ADIOS2
@@ -38,7 +37,6 @@
 no_adios2()
 {
     unset HAVE_ADIOS2 ADIOS2_INC_DIR ADIOS2_LIB_DIR
-    return 0
 }
 
 
@@ -68,26 +66,44 @@ INFORMATION
 }
 
 
+# Query settings
+query_adios2()
+{
+    local config="config.sh/adios2"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query adios2 "$ADIOS2_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "adios2=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_ADIOS2, ADIOS2_INC_DIR, ADIOS2_LIB_DIR
 have_adios2()
 {
-    local prefix header library incName libName settings warn
-    # warn="==> skip adios2"
+    local warn # warn="==> skip adios2"
+    local config="config.sh/adios2"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/adios2)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        [ -n "$warn" ] && echo "$warn (no config.sh/adios2 settings)"
+        [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 2
     fi
 
     # Expected location, include/library names
-    prefix="$ADIOS2_ARCH_PATH"
-    incName="adios2.h"
-    libName="libadios2"
+    local prefix="$ADIOS2_ARCH_PATH"
+    local incName="adios2.h"
+    local libName="libadios2"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -134,11 +150,15 @@ have_adios2()
 # Reset variables
 no_adios2
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_adios2
     echo_adios2
-fi
+    ;;
+-query)
+    query_adios2
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_boost b/wmake/scripts/have_boost
index 4af9622f484..133f15d772b 100644
--- a/wmake/scripts/have_boost
+++ b/wmake/scripts/have_boost
@@ -5,23 +5,23 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_boost
 #
 # Description
-#     Detection/setup of Boost
+#     Detection/setup of BOOST
 #
 # Requires
 #     BOOST_ARCH_PATH
+# or  config.sh/CGAL (when BOOST_ARCH_PATH is empty)
 #
 # Functions provided
-#     have_boost, no_boost, echo_boost
+#     have_boost, no_boost, echo_boost, query_boost
 #
 # Variables set on success
 #     HAVE_BOOST
@@ -38,7 +38,6 @@
 no_boost()
 {
     unset HAVE_BOOST BOOST_INC_DIR BOOST_LIB_DIR
-    return 0
 }
 
 
@@ -52,19 +51,48 @@ echo_boost()
 }
 
 
+# Query settings (from CGAL setup)
+query_boost()
+{
+    local config="config.sh/CGAL"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query boost "$BOOST_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "boost=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_BOOST, BOOST_INC_DIR, BOOST_LIB_DIR
 have_boost()
 {
-    local prefix header library incName libName settings warn
-    # warn="==> skip boost"
+    local warn # warn="==> skip boost"
+    local config="config.sh/CGAL"
+    local settings
 
-    # Setup - from the current environment
+    # Setup - current environment if set
+    if [ -z "$BOOST_ARCH_PATH" ]
+    then
+        if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
+        then
+            . "$settings"
+        else
+            [ -n "$warn" ] && echo "$warn (no $config settings)"
+            return 2
+        fi
+    fi
 
     # Expected location, include/library names
-    prefix="$BOOST_ARCH_PATH"
-    incName="boost/version.hpp"
-    libName="libboost_system"
+    local prefix="$BOOST_ARCH_PATH"
+    local incName="boost/version.hpp"
+    local libName="libboost_system"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -113,11 +141,15 @@ have_boost()
 # Reset variables
 no_boost
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_boost
     echo_boost
-fi
+    ;;
+-query)
+    query_boost
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_ccmio b/wmake/scripts/have_ccmio
index 3f2d6865151..47e32ff8a5e 100644
--- a/wmake/scripts/have_ccmio
+++ b/wmake/scripts/have_ccmio
@@ -5,23 +5,22 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_ccmio
 #
 # Description
-#     Detection/setup of ccmio
+#     Detection/setup of CCMIO
 #
 # Requires
 #     config.sh/ccmio
 #
 # Functions provided
-#     have_ccmio, no_ccmio, echo_ccmio
+#     have_ccmio, no_ccmio, echo_ccmio, query_ccmio
 #
 # Variables set on success
 #     HAVE_CCMIO
@@ -38,9 +37,9 @@
 no_ccmio()
 {
     unset HAVE_CCMIO CCMIO_INC_DIR CCMIO_LIB_DIR
-    return 0
 }
 
+
 # Report
 echo_ccmio()
 {
@@ -51,27 +50,45 @@ echo_ccmio()
 }
 
 
+# Query settings
+query_ccmio()
+{
+    local config="config.sh/ccmio"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query ccmio "$CCMIO_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "ccmio=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_CCMIO, CCMIO_INC_DIR, CCMIO_LIB_DIR
 have_ccmio()
 {
-    local prefix header library incName libName settings warn
-    warn="==> skip ccmio"
+    local warn="==> skip ccmio"
+    local config="config.sh/ccmio"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/ccmio)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        [ -n "$warn" ] && echo "$warn (no config.sh/ccmio settings)"
+        [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 2
     fi
 
     # Expected location, include/library names
     # Link with static libccmio only (fewer issues)
-    prefix="$CCMIO_ARCH_PATH"
-    incName="libccmio/ccmio.h"
-    libName="libccmio.a"
+    local prefix="$CCMIO_ARCH_PATH"
+    local incName="libccmio/ccmio.h"
+    local libName="libccmio.a"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -139,11 +156,15 @@ have_ccmio()
 # Reset variables
 no_ccmio
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_ccmio
     echo_ccmio
-fi
+    ;;
+-query)
+    query_ccmio
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_cgal b/wmake/scripts/have_cgal
index 35194ac9a7d..f99d1ce7efb 100644
--- a/wmake/scripts/have_cgal
+++ b/wmake/scripts/have_cgal
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_cgal
@@ -19,9 +18,10 @@
 #
 # Requires
 #     CGAL_ARCH_PATH
+# or  config.sh/CGAL (when CGAL_ARCH_PATH is empty)
 #
 # Functions provided
-#     have_cgal, no_cgal, echo_cgal
+#     have_cgal, no_cgal, echo_cgal, query_cgal
 #
 # Variables set on success
 #     HAVE_CGAL
@@ -38,7 +38,6 @@
 no_cgal()
 {
     unset HAVE_CGAL CGAL_INC_DIR CGAL_LIB_DIR
-    return 0
 }
 
 
@@ -52,19 +51,48 @@ echo_cgal()
 }
 
 
+# Query settings (from CGAL setup)
+query_cgal()
+{
+    local config="config.sh/CGAL"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query cgal "$CGAL_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "cgal=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_CGAL, CGAL_INC_DIR, CGAL_LIB_DIR
 have_cgal()
 {
-    local prefix header library incName libName settings warn
-    # warn="==> skip cgal"
+    local warn # warn="==> skip cgal"
+    local config="config.sh/CGAL"
+    local settings
 
-    # Setup - from the current environment
+    # Setup - current environment if set
+    if [ -z "$CGAL_ARCH_PATH" ]
+    then
+        if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
+        then
+            . "$settings"
+        else
+            [ -n "$warn" ] && echo "$warn (no $config settings)"
+            return 2
+        fi
+    fi
 
     # Expected location, include/library names
-    prefix="$CGAL_ARCH_PATH"
-    incName="CGAL/version.h"
-    libName="libCGAL"
+    local prefix="$CGAL_ARCH_PATH"
+    local incName="CGAL/version.h"
+    local libName="libCGAL"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -113,11 +141,15 @@ have_cgal()
 # Reset variables
 no_cgal
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_cgal
     echo_cgal
-fi
+    ;;
+-query)
+    query_cgal
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_fftw b/wmake/scripts/have_fftw
index 0fa66f1b371..fd8d2aebf63 100644
--- a/wmake/scripts/have_fftw
+++ b/wmake/scripts/have_fftw
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_fftw
@@ -19,9 +18,10 @@
 #
 # Requires
 #     FFTW_ARCH_PATH
+# or  config.sh/FFTW (when FFTW_ARCH_PATH is empty)
 #
 # Functions provided
-#     have_fftw, no_fftw, echo_fftw
+#     have_fftw, no_fftw, echo_fftw, query_fftw
 #
 # Variables set on success
 #     HAVE_FFTW
@@ -38,7 +38,6 @@
 no_fftw()
 {
     unset HAVE_FFTW FFTW_INC_DIR FFTW_LIB_DIR
-    return 0
 }
 
 
@@ -52,19 +51,48 @@ echo_fftw()
 }
 
 
+# Query settings
+query_fftw()
+{
+    local config="config.sh/FFTW"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query fftw "$FFTW_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "fftw=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_FFTW, FFTW_INC_DIR, FFTW_LIB_DIR
 have_fftw()
 {
-    local prefix header library incName libName settings warn
-    # warn="==> skip fftw"
+    local warn # warn="==> skip fftw"
+    local config="config.sh/FFTW"
+    local settings
 
-    # Setup - from the current environment
+    # Setup - current environment if set
+    if [ -z "$FFTW_ARCH_PATH" ]
+    then
+        if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
+        then
+            . "$settings"
+        else
+            [ -n "$warn" ] && echo "$warn (no $config settings)"
+            return 2
+        fi
+    fi
 
     # Expected location, include/library names
-    prefix="$FFTW_ARCH_PATH"
-    incName="fftw3.h"
-    libName="libfftw3"
+    local prefix="$FFTW_ARCH_PATH"
+    local incName="fftw3.h"
+    local libName="libfftw3"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -111,11 +139,15 @@ have_fftw()
 # Reset variables
 no_fftw
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_fftw
     echo_fftw
-fi
+    ;;
+-query)
+    query_fftw
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_hypre b/wmake/scripts/have_hypre
index 293644e9b6d..b4256dd1e31 100644
--- a/wmake/scripts/have_hypre
+++ b/wmake/scripts/have_hypre
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_hypre
@@ -19,9 +18,10 @@
 #
 # Requires
 #     HYPRE_ARCH_PATH
+# or  config.sh/hypre
 #
 # Functions provided
-#     have_hypre, no_hypre, echo_hypre
+#     have_hypre, no_hypre, echo_hypre, query_hypre
 #
 # Variables set on success
 #     HAVE_HYPRE
@@ -38,7 +38,6 @@
 no_hypre()
 {
     unset HAVE_HYPRE HYPRE_INC_DIR HYPRE_LIB_DIR
-    return 0
 }
 
 
@@ -52,29 +51,48 @@ echo_hypre()
 }
 
 
+# Query settings
+query_hypre()
+{
+    local config="config.sh/hypre"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query hypre "$HYPRE_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "hypre=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_HYPRE, HYPRE_INC_DIR, HYPRE_LIB_DIR
 have_hypre()
 {
-    local prefix header library incName libName settings warn
-    warn="==> skip hypre"
+    local warn="==> skip hypre"
+    local config="config.sh/hypre"
+    local settings
 
     # Setup - prefer current environment value? (TDB)
     if [ ! -d "$HYPRE_ARCH_PATH" ]
     then
-        if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/hypre)
+        if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
         then
             . "$settings"
         else
-            [ -n "$warn" ] && echo "$warn (no config.sh/hypre settings)"
+            [ -n "$warn" ] && echo "$warn (no $config settings)"
             return 2
         fi
     fi
 
     # Expected location, include/library names
-    prefix="$HYPRE_ARCH_PATH"
-    incName="HYPRE.h"
-    libName="libHYPRE"
+    local prefix="$HYPRE_ARCH_PATH"
+    local incName="HYPRE.h"
+    local libName="libHYPRE"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -121,11 +139,15 @@ have_hypre()
 # Reset variables
 no_hypre
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_hypre
     echo_hypre
-fi
+    ;;
+-query)
+    query_hypre
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_kahip b/wmake/scripts/have_kahip
index e10fa1927c6..78c6bc03ac3 100644
--- a/wmake/scripts/have_kahip
+++ b/wmake/scripts/have_kahip
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_kahip
@@ -21,7 +20,7 @@
 #     config.sh/kahip
 #
 # Functions provided
-#     have_kahip, no_kahip, echo_kahip
+#     have_kahip, no_kahip, echo_kahip, query_kahip
 #
 # Variables set on success
 #     HAVE_KAHIP
@@ -39,7 +38,6 @@ no_kahip()
 {
     unset HAVE_KAHIP KAHIP_ARCH_PATH KAHIP_INC_DIR KAHIP_LIB_DIR
     unset KAHIP_VERSION
-    return 0
 }
 
 
@@ -53,26 +51,44 @@ echo_kahip()
 }
 
 
+# Query settings
+query_kahip()
+{
+    local config="config.sh/kahip"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query kahip "$KAHIP_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "kahip=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_KAHIP, KAHIP_ARCH_PATH, KAHIP_INC_DIR, KAHIP_LIB_DIR
 have_kahip()
 {
-    local prefix header library incName libName settings warn
-    warn="==> skip kahip"
+    local warn="==> skip kahip"
+    local config="config.sh/kahip"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/kahip)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        [ -n "$warn" ] && echo "$warn (no config.sh/kahip settings)"
+        [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 1
     fi
 
     # Expected location, include/library names
-    prefix="$KAHIP_ARCH_PATH"
-    incName="kaHIP_interface.h"
-    libName="libkahip"
+    local prefix="$KAHIP_ARCH_PATH"
+    local incName="kaHIP_interface.h"
+    local libName="libkahip"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -122,11 +138,15 @@ have_kahip()
 # Reset variables
 no_kahip
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_kahip
     echo_kahip
-fi
+    ;;
+-query)
+    query_kahip
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_metis b/wmake/scripts/have_metis
index 1d1931586a4..e251281a6de 100644
--- a/wmake/scripts/have_metis
+++ b/wmake/scripts/have_metis
@@ -5,23 +5,22 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_metis
 #
 # Description
-#     Detection/setup of metis
+#     Detection/setup of METIS
 #
 # Requires
 #     config.sh/metis
 #
 # Functions provided
-#     have_metis, no_metis, echo_metis
+#     have_metis, no_metis, echo_metis, query_metis
 #
 # Variables set on success
 #     HAVE_METIS
@@ -39,7 +38,6 @@ no_metis()
 {
     unset HAVE_METIS METIS_ARCH_PATH METIS_INC_DIR METIS_LIB_DIR
     unset METIS_VERSION
-    return 0
 }
 
 
@@ -53,26 +51,44 @@ echo_metis()
 }
 
 
+# Query settings
+query_metis()
+{
+    local config="config.sh/metis"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query metis "$METIS_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "metis=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_METIS, METIS_ARCH_PATH, METIS_INC_DIR, METIS_LIB_DIR
 have_metis()
 {
-    local prefix header library incName libName settings warn
-    warn="==> skip metis"
+    local warn="==> skip metis"
+    local config="config.sh/metis"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/metis)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        [ -n "$warn" ] && echo "$warn (no config.sh/metis settings)"
+        [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 2
     fi
 
     # Expected location, include/library names
-    prefix="$METIS_ARCH_PATH"
-    incName="metis.h"
-    libName="libmetis"
+    local prefix="$METIS_ARCH_PATH"
+    local incName="metis.h"
+    local libName="libmetis"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -129,11 +145,15 @@ have_metis()
 # Reset variables
 no_metis
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_metis
     echo_metis
-fi
+    ;;
+-query)
+    query_metis
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_mgridgen b/wmake/scripts/have_mgridgen
index dfed46abfd4..84be5ce5206 100644
--- a/wmake/scripts/have_mgridgen
+++ b/wmake/scripts/have_mgridgen
@@ -5,23 +5,22 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_mgridgen
 #
 # Description
-#     Detection/setup of mgridgen
+#     Detection/setup of MGRIDGEN
 #
 # Requires
 #     config.sh/mgridgen
 #
 # Functions provided
-#     have_mgridgen, no_mgridgen, echo_mgridgen
+#     have_mgridgen, no_mgridgen, echo_mgridgen, query_mgridgen
 #
 # Variables set on success
 #     HAVE_MGRIDGEN
@@ -39,7 +38,6 @@ no_mgridgen()
 {
     unset HAVE_MGRIDGEN MGRIDGEN_ARCH_PATH MGRIDGEN_INC_DIR MGRIDGEN_LIB_DIR
     unset MGRIDGEN_VERSION
-    return 0
 }
 
 
@@ -53,27 +51,45 @@ echo_mgridgen()
 }
 
 
+# Query settings
+query_mgridgen()
+{
+    local config="config.sh/mgridgen"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query mgridgen "$MGRIDGEN_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "mgridgen=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_MGRIDGEN, MGRIDGEN_ARCH_PATH, MGRIDGEN_INC_DIR, MGRIDGEN_LIB_DIR
 have_mgridgen()
 {
-    local prefix header library incName libName libName2 settings warn
-    warn="==> skip mgridgen"
+    local warn="==> skip mgridgen"
+    local config="config.sh/mgridgen"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/mgridgen)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        #silent# [ -n "$warn" ] && echo "$warn (no config.sh/mgridgen settings)"
+        #silent# [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 2
     fi
 
     # Expected location, include/library names
-    prefix="$MGRIDGEN_ARCH_PATH"
-    incName="mgridgen.h"
-    libName="libMGridGen"
-    libName2="libmgrid"
+    local prefix="$MGRIDGEN_ARCH_PATH"
+    local incName="mgridgen.h"
+    local libName="libMGridGen"
+    local libName2="libmgrid"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -110,7 +126,7 @@ have_mgridgen()
 
     # ----------------------------------
 
-    local good label scalar
+    local label scalar
 
     # Ensure consistent sizes with OpenFOAM and mgridgen header
     # Extract typedef for idxtype, realtype
@@ -126,7 +142,6 @@ have_mgridgen()
 
     case "$WM_LABEL_SIZE:$label" in
     (32:int32_t | 32:int | 64:int64_t | 64:long)
-        good=true
         ;;
 
     (*)
@@ -140,7 +155,6 @@ have_mgridgen()
     esac
     case "$WM_PRECISION_OPTION:$scalar" in
     (SP:float | SPDP:float | DP:double)
-        good=true
         ;;
 
     (*)
@@ -166,11 +180,15 @@ have_mgridgen()
 # Reset variables
 no_mgridgen
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_mgridgen
     echo_mgridgen
-fi
+    ;;
+-query)
+    query_mgridgen
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_petsc b/wmake/scripts/have_petsc
index 2941f2e59da..4e9413c3951 100644
--- a/wmake/scripts/have_petsc
+++ b/wmake/scripts/have_petsc
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_petsc
@@ -19,9 +18,10 @@
 #
 # Requires
 #     PETSC_ARCH_PATH
+# or  config.sh/petsc
 #
 # Functions provided
-#     have_petsc, no_petsc, echo_petsc, hint_petsc
+#     have_petsc, no_petsc, echo_petsc, hint_petsc, query_petsc
 #
 # Variables set on success
 #     HAVE_PETSC
@@ -38,7 +38,6 @@
 no_petsc()
 {
     unset HAVE_PETSC PETSC_INC_DIR PETSC_LIB_DIR
-    return 0
 }
 
 
@@ -68,30 +67,49 @@ INFORMATION
 }
 
 
+# Query settings
+query_petsc()
+{
+    local config="config.sh/petsc"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query petsc "$PETSC_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "petsc=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_PETSC, PETSC_INC_DIR, PETSC_LIB_DIR
 have_petsc()
 {
-    local prefix header library incName libName pkgName settings warn
-    warn="==> skip petsc"
+    local warn="==> skip petsc"
+    local config="config.sh/petsc"
+    local settings
 
     # Setup - prefer current environment value? (TDB)
     if [ ! -d "$PETSC_ARCH_PATH" ]
     then
-        if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/petsc)
+        if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
         then
             . "$settings"
         else
-            [ -n "$warn" ] && echo "$warn (no config.sh/petsc settings)"
+            [ -n "$warn" ] && echo "$warn (no $config settings)"
             return 2
         fi
     fi
 
     # Expected location, include/library names
-    prefix="$PETSC_ARCH_PATH"
-    incName="petsc.h"
-    libName="libpetsc"
-    pkgName="PETSc"
+    local prefix="$PETSC_ARCH_PATH"
+    local incName="petsc.h"
+    local libName="libpetsc"
+    local pkgName="PETSc"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -153,11 +171,15 @@ have_petsc()
 # Reset variables
 no_petsc
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_petsc
     echo_petsc
-fi
+    ;;
+-query)
+    query_petsc
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_readline b/wmake/scripts/have_readline
index a11f2943660..51d264155fa 100644
--- a/wmake/scripts/have_readline
+++ b/wmake/scripts/have_readline
@@ -5,17 +5,16 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_readline
 #
 # Description
-#     Detection/setup of readline
+#     Detection/setup of READLINE
 #
 # Requires
 #     None
@@ -37,7 +36,6 @@
 no_readline()
 {
     unset HAVE_LIBREADLINE READLINE_INC_DIR READLINE_LIB_DIR
-    return 0
 }
 
 
@@ -54,13 +52,14 @@ echo_readline()
 # -> HAVE_LIBREADLINE, READLINE_INC_DIR, READLINE_LIB_DIR
 have_readline()
 {
-    local prefix header library incName libName settings warn
-    # warn="==> skip readline"
+    local warn # warn="==> skip readline"
+    local settings
 
     # Expected location, include/library names
-    prefix=system
-    incName="readline/readline.h"
-    libName="libreadline"
+    local prefix=system
+    local incName="readline/readline.h"
+    local libName="libreadline"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -108,11 +107,12 @@ have_readline()
 # Reset variables
 no_readline
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_readline
     echo_readline
-fi
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_scotch b/wmake/scripts/have_scotch
index 154e7e71f6e..3dd2fa43087 100644
--- a/wmake/scripts/have_scotch
+++ b/wmake/scripts/have_scotch
@@ -5,23 +5,22 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_scotch
 #
 # Description
-#     Detection/setup of scotch
+#     Detection/setup of SCOTCH
 #
 # Requires
 #     config.sh/scotch
 #
 # Functions provided
-#     have_scotch, no_scotch, echo_scotch
+#     have_scotch, no_scotch, echo_scotch, query_scotch
 #
 # Variables set on success
 #     HAVE_SCOTCH
@@ -40,7 +39,6 @@ no_scotch()
     unset HAVE_SCOTCH SCOTCH_ARCH_PATH SCOTCH_INC_DIR SCOTCH_LIB_DIR
     unset SCOTCH_VERSION
     unset HAVE_PTSCOTCH PTSCOTCH_ARCH_PATH PTSCOTCH_INC_DIR PTSCOTCH_LIB_DIR
-    return 0
 }
 
 
@@ -59,26 +57,45 @@ echo_scotch()
 }
 
 
+# Query settings
+query_scotch()
+{
+    local config="config.sh/scotch"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query scotch "$SCOTCH_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "scotch=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_SCOTCH, SCOTCH_ARCH_PATH, SCOTCH_INC_DIR, SCOTCH_LIB_DIR
 have_scotch()
 {
-    local prefix header library incName libName settings warn
-    warn="==> skip scotch"
+    local warn="==> skip scotch"
+    local config="config.sh/scotch"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        [ -n "$warn" ] && echo "$warn (no config.sh/scotch settings)"
+        [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 2
     fi
 
     # Expected location, include/library names
-    prefix="$SCOTCH_ARCH_PATH"
-    incName="scotch.h"
-    libName="libscotch"
+    local prefix="$SCOTCH_ARCH_PATH"
+    local incName="scotch.h"
+    local libName="libscotch"
+    local localDir="scotch-int$WM_LABEL_SIZE"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -87,13 +104,18 @@ have_scotch()
         return 1
     elif hasAbsdir "$prefix"
     then
-        header=$(findFirstFile "$prefix/include/$incName")
+        header=$(findFirstFile \
+            "$prefix/include/$localDir/$incName" \
+            "$prefix/include/$incName" \
+        )
         library=$(findExtLib "$libName")
     elif isSystem "$prefix"
     then
         header=$(findFirstFile \
+            "/usr/local/include/$localDir/$incName" \
             "/usr/local/include/scotch/$incName" \
             "/usr/local/include/$incName" \
+            "/usr/include/$localDir/$incName" \
             "/usr/include/scotch/$incName" \
             "/usr/include/$incName" \
         )
@@ -102,6 +124,7 @@ have_scotch()
         unset prefix
     fi
     # ----------------------------------
+    equalBaseName "${header%/*}" "$localDir" || unset localDir
 
     # Header
     [ -n "$header" ] || {
@@ -111,7 +134,7 @@ have_scotch()
 
     # Library
     [ -n "$library" ] \
-    || library=$(findLibrary -prefix="$prefix" -name="$libName") \
+    || library=$(findLibrary -prefix="$prefix" -name="$libName" -local="$localDir") \
     || {
         [ -n "$warn" ] && echo "$warn (no library)"
         return 2
@@ -119,7 +142,7 @@ have_scotch()
 
     # ----------------------------------
 
-    local good label
+    local label
 
     # Ensure consistent sizes between OpenFOAM and scotch header
     # extract 'typedef int64_t SCOTCH_Num' or equivalent
@@ -147,7 +170,6 @@ have_scotch()
 
     case "$WM_LABEL_SIZE:$label" in
     (32:int32_t | 32:int | 64:int64_t | 64:long)
-        good=true
         ;;
 
     (*)
@@ -176,8 +198,7 @@ have_scotch()
 # -> HAVE_PTSCOTCH, PTSCOTCH_ARCH_PATH, PTSCOTCH_INC_DIR, PTSCOTCH_LIB_DIR
 have_ptscotch()
 {
-    local prefix header library incName libName settings warn
-    warn="==> skip ptscotch"
+    local warn="==> skip ptscotch"
 
     if [ "$HAVE_SCOTCH" != true ]
     then
@@ -189,9 +210,11 @@ have_ptscotch()
     [ -n "$PTSCOTCH_ARCH_PATH" ] || PTSCOTCH_ARCH_PATH="$SCOTCH_ARCH_PATH"
 
     # Expected location, include/library names
-    prefix="$PTSCOTCH_ARCH_PATH"
-    incName="ptscotch.h"
-    libName="libptscotch"
+    local prefix="$PTSCOTCH_ARCH_PATH"
+    local incName="ptscotch.h"
+    local libName="libptscotch"
+    local localDir="scotch-int$WM_LABEL_SIZE"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -202,25 +225,27 @@ have_ptscotch()
     then
         header=$(findFirstFile  \
             "$prefix/include/$FOAM_MPI/$incName" \
+            "$prefix/include/$localDir/$incName" \
             "$prefix/include/$incName"
         )
         library="$(findExtLib $FOAM_MPI/$libName $libName)"
     elif isSystem "$prefix"
     then
-        prefix=/usr
         header=$(findFirstFile \
             "/usr/local/include/ptscotch/$incName" \
             "/usr/local/include/scotch/$incName" \
             "/usr/local/include/$incName" \
+            "/usr/include/$localDir/$incName" \
             "/usr/include/ptscotch/$incName" \
             "/usr/include/scotch/$incName" \
             "/usr/include/$incName" \
         )
-        case "$header" in (/usr/local/*) prefix=/usr/local ;; esac
+        prefix=$(sysPrefix "$header")
     else
         unset prefix
     fi
     # ----------------------------------
+    equalBaseName "${header%/*}" "$localDir" || unset localDir
 
     # Header
     [ -n "$header" ] || {
@@ -230,7 +255,7 @@ have_ptscotch()
 
     # Library
     [ -n "$library" ] \
-    || library=$(findLibrary -prefix="$prefix" -name="$libName") \
+    || library=$(findLibrary -prefix="$prefix" -name="$libName" -local="$localDir") \
     || {
         [ -n "$warn" ] && echo "$warn (no library)"
         return 2
@@ -250,11 +275,15 @@ have_ptscotch()
 # Reset variables
 no_scotch
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_scotch && have_ptscotch
     echo_scotch
-fi
+    ;;
+-query)
+    query_scotch
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_zoltan b/wmake/scripts/have_zoltan
index d0a9b30fe18..bf43ca58522 100644
--- a/wmake/scripts/have_zoltan
+++ b/wmake/scripts/have_zoltan
@@ -5,23 +5,22 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     have_zoltan
 #
 # Description
-#     Detection/setup of zoltan
+#     Detection/setup of ZOLTAN
 #
 # Requires
 #     config.sh/zoltan
 #
 # Functions provided
-#     have_zoltan, no_zoltan, echo_zoltan
+#     have_zoltan, no_zoltan, echo_zoltan, query_zoltan
 #
 # Variables set on success
 #     HAVE_ZOLTAN
@@ -38,7 +37,6 @@
 no_zoltan()
 {
     unset HAVE_ZOLTAN ZOLTAN_INC_DIR ZOLTAN_LIB_DIR
-    return 0
 }
 
 
@@ -52,26 +50,44 @@ echo_zoltan()
 }
 
 
+# Query settings
+query_zoltan()
+{
+    local config="config.sh/zoltan"
+    local settings
+
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
+    then
+        . "$settings"
+        _process_query zoltan "$ZOLTAN_ARCH_PATH"
+    else
+        echo "(no $config settings)" 1>&2
+        echo "zoltan=unknown"
+    fi
+}
+
+
 # On success, return 0 and export variables
 # -> HAVE_ZOLTAN, ZOLTAN_INC_DIR, ZOLTAN_LIB_DIR
 have_zoltan()
 {
-    local prefix header library incName libName settings warn
-    # warn="==> skip zoltan"
+    local warn # warn="==> skip zoltan"
+    local config="config.sh/zoltan"
+    local settings
 
-    # Setup
-    if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/zoltan)
+    if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
     then
         . "$settings"
     else
-        [ -n "$warn" ] && echo "$warn (no config.sh/zoltan settings)"
+        [ -n "$warn" ] && echo "$warn (no $config settings)"
         return 2
     fi
 
     # Expected location, include/library names
-    prefix="$ZOLTAN_ARCH_PATH"
-    incName="zoltan.h"
-    libName="libzoltan"
+    local prefix="$ZOLTAN_ARCH_PATH"
+    local incName="zoltan.h"
+    local libName="libzoltan"
+    local header library
 
     # ----------------------------------
     if isNone "$prefix"
@@ -118,11 +134,15 @@ have_zoltan()
 # Reset variables
 no_zoltan
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_zoltan
     echo_zoltan
-fi
+    ;;
+-query)
+    query_zoltan
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/paraviewFunctions b/wmake/scripts/paraviewFunctions
index 94a82e5624a..5a4ea1dec77 100644
--- a/wmake/scripts/paraviewFunctions
+++ b/wmake/scripts/paraviewFunctions
@@ -5,11 +5,10 @@
 #   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
-#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     paraviewFunctions
@@ -47,7 +46,6 @@ no_paraview()
 {
     unset HAVE_PVPLUGIN_SUPPORT FOAM_PV_PLUGIN_LIBBIN
     unset PARAVIEW_API PARAVIEW_INC_DIR
-    return 0
 }
 
 
@@ -93,15 +91,15 @@ cmakePvInstall()
 wmakeLibPv()
 {
     local depend="ParaView_DIR=$ParaView_DIR"
-    local sentinel
+    local sentinel libName
 
     for libName
     do
-        sentinel=$(sameDependency "$depend" $libName) || \
+        sentinel=$(sameDependency "$depend" "$libName") || \
             wclean $libName
 
         wmake $targetType $libName \
-        && echo "$depend" > ${sentinel:-/dev/null}
+        && storeDependency "$depend" "$sentinel"
     done
 }
 
@@ -148,8 +146,8 @@ get_pvplugin_api()
 #
 have_pvplugin_support()
 {
-    local header settings warn pv_api installDir binDir includeDir targetDir
-    warn="==> skip paraview-plugin"
+    local warn="==> skip paraview-plugin"
+    local settings pv_api installDir binDir includeDir targetDir
 
     # Trivial check
     command -v cmake >/dev/null || {
@@ -172,7 +170,7 @@ have_pvplugin_support()
     fi
 
     # Include/library names
-    header="pqServerManagerModel.h"
+    local header="pqServerManagerModel.h"
 
     if [ -n "$ParaView_DIR" ]
     then
@@ -232,11 +230,15 @@ have_pvplugin_support()
 # Force reset of old variables
 no_paraview
 
-# Testing
-if [ "$1" = "-test" ]
-then
+# Test/query
+case "$1" in
+-test)
     have_pvplugin_support
     echo_paraview
-fi
+    ;;
+-query)
+    ## query_paraview
+    ;;
+esac
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/sysFunctions b/wmake/scripts/sysFunctions
index 3c7e41a2c9d..2330bf6f59f 100644
--- a/wmake/scripts/sysFunctions
+++ b/wmake/scripts/sysFunctions
@@ -8,8 +8,7 @@
 #     Copyright (C) 2018-2020 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
-#     This file is part of OpenFOAM, licensed under GNU General Public License
-#     <http://www.gnu.org/licenses/>.
+#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
 #
 # Script
 #     sysFunctions
@@ -40,7 +39,7 @@ then
     # Load once, but do not rely on this variable elsewhere
     WMAKE_SCRIPTS_SYSFUNCTIONS=loaded
 
-    # Handle Debian multi-arch, ignore missing/bad dpkg-architecture.
+    # Debian multi-arch, ignore missing/bad dpkg-architecture.
     if [ -z "$DEB_TARGET_MULTIARCH" ]
     then
         DEB_TARGET_MULTIARCH=$(dpkg-architecture -qDEB_TARGET_MULTIARCH 2>/dev/null || true)
@@ -101,6 +100,35 @@ then
     }
 
 
+    # True if '$1' and '$2' have the same directory basename
+    # Eg,
+    #    equalBaseName "/usr/include/scotch-int32" "scotch-int32"
+    equalBaseName()
+    {
+        test "${1##*/}" = "${2##*/}"
+    }
+
+
+    # Simple output for -query
+    # $1 = software
+    # $2 = setting
+    _process_query()
+    {
+        if isNone "$2"
+        then
+            echo "$1=none"
+        elif isAbsdir "$2"    ## not hasAbsdir
+        then
+            echo "$1=${2##*/}"
+        elif isSystem "$2"
+        then
+            echo "$1=system"
+        else
+            echo "$1=unknown"
+        fi
+    }
+
+
     # Return system prefix (/usr, /usr/local, ...) based on hint provided
     # Eg,
     #    sysPrefix "/usr/local/include/fftw3.h"  -> "/usr/local"
@@ -170,15 +198,15 @@ then
     # This function has two modes of operation.
     #
     # 1) Automated search.
-    #    Specify -prefix=dirName -name=libName and search for
-    #    (lib, lib64, lib/x86_64..) etc.
+    #    Specify -prefix=dirName -name=libName, optionally -local=subdirName
+    #    and search for (lib, lib64, lib/x86_64..) etc.
     #
     # 2) Directed search.
     #    specify the fully qualified names to search on the parameter list
     #
     findLibrary()
     {
-        local prefixDir searchDir searchName
+        local prefixDir localDir searchDir searchName
         local file ext
 
         searchDir=true
@@ -191,6 +219,12 @@ then
                 shift
                 ;;
 
+            -local=*)
+                # Prefix with directory separator
+                localDir="/${1#*=}"
+                shift
+                ;;
+
             -name=*)
                 searchName="${1#*=}"
                 shift
@@ -204,18 +238,30 @@ then
 
         if [ -n "$searchName" ]
         then
-            # Automated search
-            # Eg, lib/ lib64/, lib/x86_64-linux-gnu
+            # Automated search (eg, lib/ lib64/, lib/x86_64-linux-gnu)
+            # but also handle possible local versions (eg, lib/scotch-int32)
 
             : "${prefixDir:=/usr}"  # A reasonable default
             [ -d "$prefixDir" ] || return 2
 
-            for searchDir in \
-                lib \
-                "${WM_COMPILER_LIB_ARCH:+lib}$WM_COMPILER_LIB_ARCH" \
-                "${DEB_TARGET_MULTIARCH:+lib/}${DEB_TARGET_MULTIARCH}" \
+            # Local and regular search paths
+            set -- \
+                "lib${localDir}" \
+                "${WM_COMPILER_LIB_ARCH:+lib${WM_COMPILER_LIB_ARCH}${localDir}}" \
+                "${DEB_TARGET_MULTIARCH:+lib/${DEB_TARGET_MULTIARCH}${localDir}}" \
+                "lib" \
+                "${WM_COMPILER_LIB_ARCH:+lib${WM_COMPILER_LIB_ARCH}}" \
+                "${DEB_TARGET_MULTIARCH:+lib/${DEB_TARGET_MULTIARCH}}" \
                 ;
+
+            # Ignore empty local search path ("/")
+            [ "${#localDir}" -gt 1 ] || shift 3
+
+            ## echo "search: $# $@" 1>&2
+
+            for searchDir in "$@"
             do
+                [ -n "$searchDir" ] || continue
                 for ext in '' $extLibraries
                 do
                     file="$prefixDir/$searchDir/$searchName$ext"
-- 
GitLab