From 2fc1a1692b02334b836cda23d028f85ca5bdec68 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 6 Nov 2018 09:01:40 +0100
Subject: [PATCH] CONFIG: adjust handling of PETSc environment (-force option)

---
 etc/config.sh/petsc      | 10 ++++++++++
 wmake/scripts/have_petsc | 12 ++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/etc/config.sh/petsc b/etc/config.sh/petsc
index 937d4ff5082..31047027647 100644
--- a/etc/config.sh/petsc
+++ b/etc/config.sh/petsc
@@ -43,6 +43,16 @@ then
 
     unset petsc_version
 
+elif [ "$1" = "-force" ]
+then
+    # Forced command-line sourcing
+
+    if output="$($WM_PROJECT_DIR/bin/tools/lib-dir -sh $PETSC_ARCH_PATH 2>/dev/null)"
+    then
+        eval "$output"
+    fi
+
+    unset petsc_version output
 fi
 
 #------------------------------------------------------------------------------
diff --git a/wmake/scripts/have_petsc b/wmake/scripts/have_petsc
index c4665c7322e..f3f301b420d 100644
--- a/wmake/scripts/have_petsc
+++ b/wmake/scripts/have_petsc
@@ -55,9 +55,17 @@ echo_petsc()
 have_petsc()
 {
     local header library static label settings warn
-    # warn="==> skip petsc"
+    warn="==> skip petsc"
 
-    # Basic setup/checks
+    # Basic setup/checks. Prefer current environment value? (TDB)
+    if [ ! -d "$PETSC_ARCH_PATH" ]
+    then
+        settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/petsc) || {
+            [ -n "$warn" ] && echo "$warn (no config.sh/petsc settings)"
+            return 1
+        }
+        . $settings
+    fi
     if isNone "$PETSC_ARCH_PATH"
     then
         [ -n "$warn" ] && echo "$warn (not available)"
-- 
GitLab