From d2eb50832ccfb6d67c633570d992ea0551617e89 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 14 Mar 2019 10:42:57 +0100
Subject: [PATCH] ENH: add handling of lib/exe file extensions in makefile
 (#1238)

- relocates some logic from makefiles/general into platform-specific
  overrides
---
 .../decompose/ptscotchDecomp/Make/options     |  2 +-
 .../decompose/scotchDecomp/Make/options       |  2 +-
 wmake/makefiles/general                       | 52 ++++++++++---------
 wmake/rules/General/general                   |  1 -
 wmake/rules/darwin64Clang/general             |  5 ++
 5 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/src/parallel/decompose/ptscotchDecomp/Make/options b/src/parallel/decompose/ptscotchDecomp/Make/options
index e5051823244..8cd4aa7b582 100644
--- a/src/parallel/decompose/ptscotchDecomp/Make/options
+++ b/src/parallel/decompose/ptscotchDecomp/Make/options
@@ -24,6 +24,6 @@ LIB_LIBS = \
     -lscotch
 
 /* May require librt, but scotch does not declare the dependency */
-ifeq ("$(SO)","so")
+ifeq ("$(EXT_SO)", ".so")
     LIB_LIBS += -lrt
 endif
diff --git a/src/parallel/decompose/scotchDecomp/Make/options b/src/parallel/decompose/scotchDecomp/Make/options
index d4e3013991c..c605567ed60 100644
--- a/src/parallel/decompose/scotchDecomp/Make/options
+++ b/src/parallel/decompose/scotchDecomp/Make/options
@@ -7,6 +7,6 @@ LIB_LIBS = \
     -lscotch -lscotcherrexit
 
 /* May require librt, but scotch does not declare the dependency */
-ifeq ("$(SO)","so")
+ifeq ("$(EXT_SO)", ".so")
     LIB_LIBS += -lrt
 endif
diff --git a/wmake/makefiles/general b/wmake/makefiles/general
index a8c81c4e252..6b7fc6e4b6c 100644
--- a/wmake/makefiles/general
+++ b/wmake/makefiles/general
@@ -2,7 +2,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           |
+#   \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 #                           | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -70,21 +70,23 @@ LIB_LIBS        =
 # Declare default name of libraries and executables
 #------------------------------------------------------------------------------
 
-# Library
-LIB             = libNULL
+# Shared library extension (with '.' separator)
+EXT_SO  = .so
 
-# Shared library extension
-ifneq (,$(findstring darwin,$(WM_ARCH)))
-SO              = dylib
-else
-SO              = so
-endif
+# Executable extension (with '.' separator)
+EXE_EXT =
+
+# Library (default which is to be overridden)
+LIB     = libNULL
+
+# Project executable (default which is to be overridden)
+EXE     = $(WM_PROJECT).out
 
-# Project executable
-EXE             = $(WM_PROJECT).out
+# Standalone executable (default which is to be overridden)
+SEXE    = a.out
 
-# Standalone executable
-SEXE            = a.out
+#DEBUG $(info "EXE_SO  = ${EXE_SO}")
+#DEBUG $(info "EXE_EXT = ${EXE_EXT}")
 
 
 #------------------------------------------------------------------------------
@@ -127,28 +129,28 @@ LIB_HEADER_DIRS = \
 #------------------------------------------------------------------------------
 
 .PHONY: all
-all: $(EXE)
+all: $(EXE)$(EXE_EXT)
 	@:
 
 .PHONY: silent
 silent:
 	@:
 
-$(EXE): $(OBJECTS)
+$(EXE)$(EXE_EXT): $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(EXE)
-	$(call QUIET_MESSAGE,ld,$(EXE))
+	$(call QUIET_MESSAGE,ld,$(EXE)$(EXE_EXT))
 	$E $(LINKEXE) $(OBJECTS) -L$(LIB_PLATFORMS) \
 	    $(EXE_LIBS) $(PROJECT_LIBS) $(SYS_LIBS) \
-	    $(LINK_LIBS) $(GLIBS) -o $(EXE)
+	    $(LINK_LIBS) $(GLIBS) -o $(EXE)$(EXE_EXT)
 
 .PHONY: exe
-exe: $(SEXE) | silent
+exe: $(SEXE)$(EXE_EXT) | silent
 
-$(SEXE): $(OBJECTS)
+$(SEXE)$(EXE_EXT): $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(SEXE)
-	$(call QUIET_MESSAGE,ld,$(SEXE))
+	$(call QUIET_MESSAGE,ld,$(SEXE)$(EXE_EXT))
 	$E $(LINKEXE) $(OBJECTS) $(EXE_LIBS) \
-	    $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(SEXE)
+	    $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(SEXE)$(EXE_EXT)
 
 
 #------------------------------------------------------------------------------
@@ -159,13 +161,13 @@ $(SEXE): $(OBJECTS)
 objects: $(OBJECTS) | silent
 
 .PHONY: libso
-libso: $(LIB).$(SO) | silent
+libso: $(LIB)$(EXT_SO) | silent
 
-$(LIB).$(SO): $(OBJECTS)
+$(LIB)$(EXT_SO): $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(LIB)
-	$(call QUIET_MESSAGE,ld,$(LIB).$(SO))
+	$(call QUIET_MESSAGE,ld,$(LIB)$(EXT_SO))
 	$E $(LINKLIBSO) $(OBJECTS) -L$(LIB_PLATFORMS) \
-	    $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB).$(SO)
+	    $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB)$(EXT_SO)
 
 .PHONY: lib
 lib: $(LIB).a | silent
diff --git a/wmake/rules/General/general b/wmake/rules/General/general
index 96978a17126..ebba2fd924a 100644
--- a/wmake/rules/General/general
+++ b/wmake/rules/General/general
@@ -31,5 +31,4 @@ sinclude $(RULES)/general
 sinclude $(RULES)/c++
 include $(GENERAL_RULES)/transform
 
-
 #------------------------------------------------------------------------------
diff --git a/wmake/rules/darwin64Clang/general b/wmake/rules/darwin64Clang/general
index 967ca8178c2..2eb439fe7d4 100644
--- a/wmake/rules/darwin64Clang/general
+++ b/wmake/rules/darwin64Clang/general
@@ -7,3 +7,8 @@ include $(GENERAL_RULES)/Clang/openmp
 
 include $(DEFAULT_RULES)/c
 include $(DEFAULT_RULES)/c++
+
+# Shared library extension (with '.' separator)
+EXT_SO  = .dylib
+
+# -----------------------------------------------------------------------------
-- 
GitLab