From 4200774d35df608fef9ecc7fc05a415c7201d457 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 14 Apr 2020 09:18:51 +0200
Subject: [PATCH] CONFIG: improve support for compiler derivatives (#1671)

- add '[-+.~]' to the recognized qualifiers.
  This allows simple readable names such as

      WM_COMPILER=Clang-vendor

  but also opens the FUTURE (not yet supported) possibility of
  combining in additional information. For example,

      WM_COMPILER=Clang~openmp
      WM_COMPILER=Clang+cuda~openmp

  by using '+' (add) and '~' (subtract) notation similar to what
  spack uses.

CONFIG: support 'override' rules

- if present, compiler-family 'override' rules are included after
  compiler-family 'general' rules have been included. This allows a
  central means for including dynamically generated content to
  override some values.

  Some examples:

  To handle different gcc versions (system compiler):

  wmake/rules/...Gcc/override

  ```
  ifneq (,$(findstring 9, $(WM_COMPILER)))
      cc  := gcc-9
      CC  := g++-9 -std=c++11
  endif
  ```

  To handle different openmp on Darwin (#1656):

  wmake/rules/darwin64Clang/override

  ```
  # Use libomp (not libgomp) unless openmp is disabled
  ifeq (,$(findstring "~openmp", "$(WM_COMPILER)"))
      COMP_OPENMP = -DUSE_OMP -Xpreprocessor -fopenmp
      LINK_OPENMP = -lomp
  else
      include $(GENERAL_RULES)/no-openmp
  endif
  ```

  This treatment arguably fits into wmake/rules/darwin64Clang/general,
  but it serves to illustrate a possible use case.
---
 wmake/rules/General/general | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/wmake/rules/General/general b/wmake/rules/General/general
index f8786b6a2d0..0e50db294a3 100644
--- a/wmake/rules/General/general
+++ b/wmake/rules/General/general
@@ -14,25 +14,29 @@ GLIBS      = -lm
 GLIB_LIBS  =
 
 
-COMPILER_FAMILY = $(shell echo "$(WM_COMPILER)" | sed -e 's/[0-9].*//')
-DEFAULT_RULES   = $(WM_DIR)/rules/$(WM_ARCH)$(COMPILER_FAMILY)
-RULES           = $(WM_DIR)/rules/$(WM_ARCH)$(WM_COMPILER)
+ARCHITECTURE_RULES = $(WM_DIR)/rules/$(WM_ARCH)
+COMPILER_FAMILY = $(shell echo "$(WM_COMPILER)" | sed -e 's/[-+.0-9~].*//')
+DEFAULT_RULES   = $(ARCHITECTURE_RULES)$(COMPILER_FAMILY)
+RULES           = $(ARCHITECTURE_RULES)$(WM_COMPILER)
 WMAKE_BIN       = $(WM_PROJECT_DIR)/platforms/tools/$(WM_ARCH)$(WM_COMPILER)
 
 # Default compilation is 'Opt' - never permit an empty value
-ifeq ($(WM_COMPILE_OPTION),)
+ifeq (,$(WM_COMPILE_OPTION))
     WM_COMPILE_OPTION = Opt
 endif
 
-ifeq ($(WM_SCHEDULER),)
+ifeq (,$(WM_SCHEDULER))
     AND = &&
 else
     AND = '&&'
 endif
 
 include $(DEFAULT_RULES)/general
+sinclude $(DEFAULT_RULES)/override
+ifneq ("$(COMPILER_FAMILY)","$(WM_COMPILER)")
 sinclude $(RULES)/general
 sinclude $(RULES)/c++
+endif
 include $(GENERAL_RULES)/transform
 
 #------------------------------------------------------------------------------
-- 
GitLab