From dc2f45193bf4a4494da6d6251259ff1831e7b0d7 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Sat, 14 Dec 2019 13:53:01 +0100
Subject: [PATCH] ENH: add wmake -user option

- overrides values of FOAM_APPBIN and FOAM_LIBBIN with those from
  FOAM_USER_APPBIN and FOAM_USER_LIBBIN, respectively.

  It can be useful in some situations to compile code into user locations
  rather than library locations. In #1522, for example, it will
  normally be useful to deliver out packages that compile into
  FOAM_LIBBIN (when included as a module) but still allow the user the
  chance to install into their own directories without editing all of
  the Make/files.
---
 wmake/scripts/AllwmakeParseArguments | 10 +++++++---
 wmake/wmake                          |  6 ++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/wmake/scripts/AllwmakeParseArguments b/wmake/scripts/AllwmakeParseArguments
index 80da8a5b75b..f0c03fd87fe 100644
--- a/wmake/scripts/AllwmakeParseArguments
+++ b/wmake/scripts/AllwmakeParseArguments
@@ -54,7 +54,7 @@ USAGE
 # Parse the arguments and options
 #------------------------------------------------------------------------------
 
-unset fromWmake optDebug optLog optQueue
+unset fromWmake optDebug optUser optQueue optLog
 
 for arg in "$@"
 do
@@ -93,6 +93,10 @@ do
         optDebug="-debug"
         continue    # Permanently remove arg
         ;;
+    -user)
+        optUser="-user"
+        continue    # Permanently remove arg
+        ;;
     -q | -queue)
         optQueue="-queue"
         continue    # Permanently remove arg
@@ -116,12 +120,12 @@ if [ -z "$fromWmake" ]
 then
     if [ -z "$optLog" ]
     then
-        exec wmake -all $optQueue $*
+        exec wmake -all $optDebug $optUser $optQueue $*
         exit $? # Unneeded, but just in case something went wrong
     else
         echo "Logging wmake -all output to '$optLog'" 1>&2
         echo 1>&2
-        exec wmake -all $optDebug $optQueue $* 2>&1 | /usr/bin/tee $optLog
+        exec wmake -all $optDebug $optUser $optQueue $* 2>&1 | /usr/bin/tee $optLog
         # Need to cleanup after the tee
         rc=$? # Error code from tee (not wmake), but not entirely important
         echo "Done logging to '$optLog'" 1>&2
diff --git a/wmake/wmake b/wmake/wmake
index 88b227e17b0..bd6df9a37ec 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -73,6 +73,7 @@ options:
   -q | -queue       wmakeCollect all sub-directories, running Allwmake if present
   -k | -keep-going  Keep going even when errors occur (-non-stop)
   -debug            Define c++DBUG='-DFULLDEBUG -g -O0' as override
+  -user             Set FOAM_APPBIN/FOAM_LIBBIN to user locations
   -j                Compile using all local cores/hyperthreads
   -jN | -j N        Compile using N cores/hyperthreads
   -no-scheduler     Disable scheduled parallel compilation
@@ -148,6 +149,11 @@ do
         -debug)
             optDebug="-DFULLDEBUG -g -O0"
             ;;
+        -user)
+            [ -n "$FOAM_USER_APPBIN" ] && export FOAM_APPBIN="$FOAM_USER_APPBIN"
+            [ -n "$FOAM_USER_LIBBIN" ] && export FOAM_LIBBIN="$FOAM_USER_LIBBIN"
+            echo "Compiling with user locations" 1>&2
+            ;;
         -show-api | -show-ext-so | \
         -show-compile-c   | -show-c   | -show-cflags   | -show-cflags-arch | \
         -show-compile-cxx | -show-cxx | -show-cxxflags | -show-cxxflags-arch )
-- 
GitLab