From 51bf7af8ae8730b2f12ddef62eca8614ae09f39d Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Mon, 1 Apr 2019 09:03:48 +0200
Subject: [PATCH] ENH: support wmake -show options for compiler information
 (#1256)

- can be useful for retrieving the compilation flags for use with other
  make systems (eg, cmake)

  * wmake -show-compile   (C++ not C)
  * wmake -show-cxx
  * wmake -show-cxxflags
---
 wmake/makefiles/general |  2 +-
 wmake/makefiles/info    | 74 +++++++++++++++++++++++++++++++++++++++++
 wmake/wmake             | 24 +++++++++++--
 3 files changed, 96 insertions(+), 4 deletions(-)
 create mode 100644 wmake/makefiles/info

diff --git a/wmake/makefiles/general b/wmake/makefiles/general
index 6b7fc6e4b6c..198e5c1e59a 100644
--- a/wmake/makefiles/general
+++ b/wmake/makefiles/general
@@ -31,7 +31,7 @@ endif
 
 
 #------------------------------------------------------------------------------
-# Unset suffices list (suffix rules are not used)
+# No default suffix rules used
 #------------------------------------------------------------------------------
 
 .SUFFIXES:
diff --git a/wmake/makefiles/info b/wmake/makefiles/info
new file mode 100644
index 00000000000..90fa2b550df
--- /dev/null
+++ b/wmake/makefiles/info
@@ -0,0 +1,74 @@
+#----------------------------*- makefile-gmake -*------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM, licensed under GNU General Public License
+#     <http://www.gnu.org/licenses/>.
+#
+# File
+#     wmake/makefiles/info
+#
+# Description
+#     Makefile to generate information.
+#     Used by wmake -show-*
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# Use POSIX shell. Default to POSIX for the OS.
+#------------------------------------------------------------------------------
+
+SHELL   = /bin/sh
+
+#------------------------------------------------------------------------------
+# No default suffix rules used
+#------------------------------------------------------------------------------
+
+.SUFFIXES:
+
+
+#------------------------------------------------------------------------------
+# Compilation rules
+#------------------------------------------------------------------------------
+
+GENERAL_RULES = $(WM_DIR)/rules/General
+include $(GENERAL_RULES)/general
+
+
+#------------------------------------------------------------------------------
+# Display information
+#------------------------------------------------------------------------------
+
+export WM_VERSION
+
+
+.PHONY: compile
+compile:
+	@echo "$(strip $(CC) $(c++FLAGS))"
+
+.PHONY: api
+api:
+	@echo "$${WM_VERSION#*=}"
+
+.PHONY: c
+c:
+	@echo "$(strip $(cc))"
+
+.PHONY: cflags
+cflags:
+	@echo "$(strip $(cFLAGS))"
+
+.PHONY: cxx
+cxx:
+	@echo "$(strip $(CC))"
+
+.PHONY: cxxflags
+cxxflags:
+	@echo "$(strip $(c++FLAGS))"
+
+
+#----------------------------- vim: set ft=make: ------------------------------
diff --git a/wmake/wmake b/wmake/wmake
index c05e25c3f1d..7591fc94512 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -77,6 +77,11 @@ options:
   -pwd              Print root directory containing a Make/ directory and exit
   -update           Update lnInclude directories, dep files, remove deprecated
                     files and directories
+  -show             Identical to -show-compile
+  -show-api         Print api value and exit
+  -show-compile     Print C++ compiler value/flags and exit
+  -show-cxx         Print C++ compiler value and exit
+  -show-cxxflags    Print C++ compiler flags and exit
   -h | -help        Print the usage
 
 
@@ -121,7 +126,7 @@ allCores()
 #------------------------------------------------------------------------------
 
 # Default to compiling the local target only
-unset all update optPrintRootDir
+unset all optShow update optPrintRootDir
 
 while [ "$#" -gt 0 ]
 do
@@ -133,6 +138,14 @@ do
         -s | -silent)
             export WM_QUIET=true
             ;;
+        -show | -show-compile)
+            $make -f $WM_DIR/makefiles/info compile
+            optShow=true
+            ;;
+        -show-api | -show-cxx | -show-cxxflags | -show-c | -show-cflags)
+            $make -f $WM_DIR/makefiles/info "${1#-show-}"
+            optShow=true
+            ;;
         -a | -all | all)
             all=all
             ;;
@@ -147,12 +160,12 @@ do
 
             [ "$nCores" = 0 ] && allCores
             export WM_NCOMPPROCS=$nCores
-            echo "Compiling enabled on $WM_NCOMPPROCS cores"
+            echo "Compiling enabled on $WM_NCOMPPROCS cores" 1>&2
             ;;
         # Parallel compilation on specified number of cores
         -j[1-9]*)
             export WM_NCOMPPROCS=${1#-j}
-            echo "Compiling enabled on $WM_NCOMPPROCS cores"
+            echo "Compiling enabled on $WM_NCOMPPROCS cores" 1>&2
             ;;
         # Keep going, ignoring errors
         -k | -keep-going | -non-stop)
@@ -190,6 +203,11 @@ do
     shift
 done
 
+if [ "$optShow" = true ]
+then
+    exit 0
+fi
+
 
 #------------------------------------------------------------------------------
 # Check environment variables
-- 
GitLab