From 9f7cfa9419cdaedfcd6498fc971c5edeec16bdfe Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Nov 2022 12:15:08 +0100 Subject: [PATCH] ENH: support libz disabling via WM_COMPILE_CONTROL (as ~libz) - eg, for partially incomplete systems (without libz devel header) ENH: clearer binding of dummy Pstream in OpenFOAM/Make/options - link of dummy stub Pstream now contingent on linking libOpenFOAM as well. This makes the purpose slightly clearer ENH: cleaner option naming/handling in wmake script - allow special purpose -no-openfoam option. Eg, compiling test programs without OpenFOAM and Pstream libraries but using the rest of the wmake system. ENH: add +openmp support into WM_COMPILE_CONTROL (#2633) - this adds compile/link flags for openmp. For single-use, can also use 'wmake -openmp'. If both +openmp and ~openmp are specified in WM_COMPILE_CONTROL the ~openmp will have priority. This is actually done indirectly since ~openmp will set empty COMP_OPENMP, LINK_OPENMP internal variables, which the +openmp then adds to the c++FLAGS and linkexe targets (ie, won't actually add anything). ENH: add +ccache or ccache=... support into WM_COMPILE_CONTROL (#2633) - with the first version (+ccache), simply use ccache from the path without any extra options. - with the second version (ccache=...), can be more specific about what is called. Using "+ccache" is identical to "ccache=ccache", but the later could be used in other ways. For example, ccache=/strange/install/path/ccache ccache= Have the choice of unquoted, single or double quoted or '< >' quoted STYLE: relocate FOAM_EXTRA_LDFLAGS in general makefile - removes clutter for different linkers (eg, gold, mold, ldd) making it easier to extend for other linkers. STYLE: protect makefile checks with 'strip' function --- applications/test/00-dummy/Allwmake | 3 +- applications/test/00-machine-sizes/Allwmake | 8 + .../00-machine-sizes/Test-machine-sizes.cpp | 5 +- applications/test/00-openmp/Allwmake | 8 + .../test/{openmp => 00-openmp}/Make/files | 0 .../test/{openmp => 00-openmp}/Make/options | 0 .../test/{openmp => 00-openmp}/Test-openmp.C | 13 +- etc/bashrc | 6 +- etc/cshrc | 6 +- src/OpenFOAM/Make/options | 20 +- wmake/makefiles/general | 44 +++-- wmake/makefiles/info | 13 +- wmake/rules/General/Amd/link-c | 4 + wmake/rules/General/Amd/link-c++ | 16 +- wmake/rules/General/Clang/c++ | 2 +- wmake/rules/General/Clang/link-c | 4 + wmake/rules/General/Clang/link-c++ | 10 +- wmake/rules/General/Clang/link-gold-c++ | 16 +- wmake/rules/General/Clang/link-lld-c++ | 16 +- wmake/rules/General/Clang/link-mold-c++ | 16 +- wmake/rules/General/Gcc/link-c | 4 + wmake/rules/General/Gcc/link-c++ | 10 +- wmake/rules/General/Gcc/link-gold-c++ | 16 +- wmake/rules/General/Icc/link-c | 4 + wmake/rules/General/Icc/link-c++ | 10 +- wmake/rules/General/Icx/link-c | 4 + wmake/rules/General/Icx/link-c++ | 10 +- wmake/rules/General/Nvidia/link-c | 4 + wmake/rules/General/Nvidia/link-c++ | 10 +- wmake/rules/General/cuda | 2 +- wmake/rules/General/general | 8 +- wmake/rules/General/mpi-rules | 4 +- wmake/rules/General/transform | 4 +- wmake/rules/darwin64Clang/c | 2 +- wmake/rules/darwin64Clang/c++ | 2 +- wmake/rules/linux64Amd/c | 2 +- wmake/rules/linux64Amd/c++ | 2 +- wmake/rules/linux64Clang/c | 2 +- wmake/rules/linux64Clang/c++ | 2 +- wmake/rules/linux64Cray/c | 2 +- wmake/rules/linux64Cray/c++ | 2 +- wmake/rules/linux64Gcc/c | 2 +- wmake/rules/linux64Gcc/c++ | 2 +- wmake/rules/linux64Icc/c | 2 +- wmake/rules/linux64Icc/c++ | 2 +- wmake/rules/linux64Icx/c | 2 +- wmake/rules/linux64Icx/c++ | 2 +- wmake/rules/linux64Mingw/c | 2 +- wmake/rules/linux64Mingw/c++ | 8 +- wmake/rules/linux64Nvidia/c | 2 +- wmake/rules/linux64Nvidia/c++ | 2 +- wmake/rules/linuxARM64Arm/c | 2 +- wmake/rules/linuxARM64Arm/c++ | 2 +- wmake/rules/linuxARM64Clang/c | 2 +- wmake/rules/linuxARM64Clang/c++ | 2 +- wmake/rules/linuxARM64Fujitsu/c | 2 +- wmake/rules/linuxARM64Fujitsu/c++ | 2 +- wmake/rules/linuxARM64Gcc/c | 2 +- wmake/rules/linuxARM64Gcc/c++ | 2 +- wmake/rules/linuxARM64Nvidia/c | 2 +- wmake/rules/linuxARM64Nvidia/c++ | 2 +- wmake/rules/linuxClang/c | 2 +- wmake/rules/linuxClang/c++ | 2 +- wmake/rules/linuxGcc/c | 2 +- wmake/rules/linuxGcc/c++ | 2 +- wmake/rules/linuxIcc/c | 2 +- wmake/rules/linuxIcc/c++ | 2 +- wmake/rules/linuxPPC64Gcc/c | 2 +- wmake/rules/linuxPPC64Gcc/c++ | 2 +- wmake/rules/linuxPPC64leGcc/c | 2 +- wmake/rules/linuxPPC64leGcc/c++ | 2 +- wmake/rules/solaris64Gcc/c | 2 +- wmake/rules/solaris64Gcc/c++ | 2 +- wmake/scripts/AllwmakeParseArguments | 53 +++--- wmake/src/Makefile | 7 +- wmake/wmake | 177 ++++++++++++++---- 76 files changed, 430 insertions(+), 193 deletions(-) create mode 100755 applications/test/00-machine-sizes/Allwmake create mode 100755 applications/test/00-openmp/Allwmake rename applications/test/{openmp => 00-openmp}/Make/files (100%) rename applications/test/{openmp => 00-openmp}/Make/options (100%) rename applications/test/{openmp => 00-openmp}/Test-openmp.C (92%) diff --git a/applications/test/00-dummy/Allwmake b/applications/test/00-dummy/Allwmake index 34307a3559..d9d0702145 100755 --- a/applications/test/00-dummy/Allwmake +++ b/applications/test/00-dummy/Allwmake @@ -7,6 +7,7 @@ cd "${0%/*}" || exit # Run from this directory library/Allwmake -wmake +# Does not use libOpenFOAM or libPstream... +wmake -no-openfoam #------------------------------------------------------------------------------ diff --git a/applications/test/00-machine-sizes/Allwmake b/applications/test/00-machine-sizes/Allwmake new file mode 100755 index 0000000000..723292e35c --- /dev/null +++ b/applications/test/00-machine-sizes/Allwmake @@ -0,0 +1,8 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +#------------------------------------------------------------------------------ + +# Does not use libOpenFOAM or libPstream... +wmake -no-openfoam + +#------------------------------------------------------------------------------ diff --git a/applications/test/00-machine-sizes/Test-machine-sizes.cpp b/applications/test/00-machine-sizes/Test-machine-sizes.cpp index 5e99cacfd9..0e88c4c943 100644 --- a/applications/test/00-machine-sizes/Test-machine-sizes.cpp +++ b/applications/test/00-machine-sizes/Test-machine-sizes.cpp @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,7 +59,8 @@ void print(const char* name, bool showLimits = true) int main(int argc, char *argv[]) { - std::cout<<"machine sizes\n---\n\n"; + std::cout<< "c++ = " << __cplusplus << '\n'; + std::cout<< "machine sizes\n---\n\n"; print("short"); print("int"); diff --git a/applications/test/00-openmp/Allwmake b/applications/test/00-openmp/Allwmake new file mode 100755 index 0000000000..723292e35c --- /dev/null +++ b/applications/test/00-openmp/Allwmake @@ -0,0 +1,8 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +#------------------------------------------------------------------------------ + +# Does not use libOpenFOAM or libPstream... +wmake -no-openfoam + +#------------------------------------------------------------------------------ diff --git a/applications/test/openmp/Make/files b/applications/test/00-openmp/Make/files similarity index 100% rename from applications/test/openmp/Make/files rename to applications/test/00-openmp/Make/files diff --git a/applications/test/openmp/Make/options b/applications/test/00-openmp/Make/options similarity index 100% rename from applications/test/openmp/Make/options rename to applications/test/00-openmp/Make/options diff --git a/applications/test/openmp/Test-openmp.C b/applications/test/00-openmp/Test-openmp.C similarity index 92% rename from applications/test/openmp/Test-openmp.C rename to applications/test/00-openmp/Test-openmp.C index 3acc9e4108..dd4cad7a61 100644 --- a/applications/test/openmp/Test-openmp.C +++ b/applications/test/00-openmp/Test-openmp.C @@ -41,8 +41,13 @@ Description int main(int argc, char *argv[]) { + std::cout + << "c++ = " << __cplusplus << '\n'; + #if _OPENMP - std::cout << "_OPENMP = " << _OPENMP << "\n\n"; + std::cout + << "openmp = " << _OPENMP << '\n' + << "Initial threads = " << omp_get_num_threads() << "\n\n"; // Fork threads with their own copies of variables int nThreads, threadId; @@ -52,15 +57,15 @@ int main(int argc, char *argv[]) threadId = omp_get_thread_num(); nThreads = omp_get_num_threads(); - // Printf rather than cout to ensure that it emits in one go - printf("Called from thread = %d\n", threadId); - // Master thread if (threadId == 0) { // Printf rather than cout to ensure that it emits in one go printf("Number of threads = %d\n", nThreads); } + + // Printf rather than cout to ensure that it emits in one go + printf("Called from thread = %d\n", threadId); } #else std::cout << "Compiled without openmp!\n"; diff --git a/etc/bashrc b/etc/bashrc index c04bd12599..02d084f060 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -82,11 +82,15 @@ export WM_LABEL_SIZE=32 # = Opt | Dbg | Debug | Prof export WM_COMPILE_OPTION=Opt -# [WM_COMPILE_CONTROL] - additional control for compiler rules +# [WM_COMPILE_CONTROL] - additional control for compilation/linking # +gold : with gold linker # +lld : with lld linker (with clang) # +mold : with mold linker (with clang) +# ~libz : without libz compression +# +openmp : with openmp # ~openmp : without openmp +# +ccache : use ccache +# ccache=... : ccache command (unquoted, single/double or <> quoted) # version=... : compiler suffix (eg, "11" for gcc-11) #export WM_COMPILE_CONTROL="+gold" diff --git a/etc/cshrc b/etc/cshrc index 068b2e5ca1..7f19beec7b 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -82,11 +82,15 @@ setenv WM_LABEL_SIZE 32 # = Opt | Dbg | Debug | Prof setenv WM_COMPILE_OPTION Opt -# [WM_COMPILE_CONTROL] - additional control for compiler rules +# [WM_COMPILE_CONTROL] - additional control for compilation/linking # +gold : with gold linker # +lld : with lld linker (with clang) # +mold : with mold linker (with clang) +# ~libz : without libz compression +# +openmp : with openmp # ~openmp : without openmp +# +ccache : use ccache +# ccache=... : ccache command (unquoted, single/double or <> quoted) # version=... : compiler suffix (eg, "11" for gcc-11) #setenv WM_COMPILE_CONTROL "+gold" diff --git a/src/OpenFOAM/Make/options b/src/OpenFOAM/Make/options index 823ee2ed50..a214db6653 100644 --- a/src/OpenFOAM/Make/options +++ b/src/OpenFOAM/Make/options @@ -4,17 +4,19 @@ EXE_INC = \ LIB_LIBS = \ $(FOAM_LIBBIN)/libOSspecific.o +/* libz: (not disabled) */ +ifeq (,$(findstring ~libz,$(WM_COMPILE_CONTROL))) + EXE_INC += -DHAVE_LIBZ + LIB_LIBS += -lz +endif + + +/* Never self-link (WM_PROJECT == OpenFOAM), but do link to Pstream */ + +PROJECT_LIBS = + ifeq (libo,$(FOAM_LINK_DUMMY_PSTREAM)) LIB_LIBS += $(FOAM_LIBBIN)/dummy/libPstream.o else LIB_LIBS += -L$(FOAM_LIBBIN)/dummy -lPstream endif - -/* libz */ -EXE_INC += -DHAVE_LIBZ - -LIB_LIBS += -lz - - -/* Project lib dependencies. Never self-link (WM_PROJECT == OpenFOAM) */ -PROJECT_LIBS = diff --git a/wmake/makefiles/general b/wmake/makefiles/general index 19e5ac4165..9b50f7886c 100644 --- a/wmake/makefiles/general +++ b/wmake/makefiles/general @@ -17,6 +17,12 @@ # Description # Makefile used by wmake to make dependency files and libs and applications # +# Embedded Control Parameters +# +# WM_COMPILE_CONTROL (+openmp) +# WM_COMPILE_CONTROL (~openfoam) +# WM_OSTYPE (windows) +# #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ @@ -25,7 +31,7 @@ SHELL = /bin/sh -ifeq (,$(WM_OSTYPE)) +ifeq (,$(strip $(WM_OSTYPE))) WM_OSTYPE := POSIX endif @@ -55,22 +61,34 @@ OBJECTS_DIR = $(MAKE_DIR)/$(WM_OPTIONS) SYS_INC = SYS_LIBS = +# Add linkage for openmp into the system libraries +ifneq (,$(findstring +openmp,$(WM_COMPILE_CONTROL))) +SYS_LIBS = $(LINK_OPENMP) +endif + +# These are set by Make/options +EXE_INC = +EXE_LIBS = +LIB_LIBS = + +# Project include/libraries PROJECT_INC = \ -I$(LIB_SRC)/$(WM_PROJECT)/lnInclude \ -I$(LIB_SRC)/OSspecific/$(WM_OSTYPE)/lnInclude PROJECT_LIBS = -l$(WM_PROJECT) -ldl -EXE_INC = -EXE_LIBS = -LIB_LIBS = - +# Special compilation without OpenFOAM at all +ifneq (,$(findstring ~openfoam,$(WM_COMPILE_CONTROL))) +PROJECT_INC = +PROJECT_LIBS = +endif # These variables are used for some builds - provide fallback values -ifeq (,$(FOAM_SOLVERS)) +ifeq (,$(strip $(FOAM_SOLVERS))) FOAM_SOLVERS = $(WM_PROJECT_DIR)/applications/solvers endif -ifeq (,$(FOAM_UTILITIES)) +ifeq (,$(strip $(FOAM_UTILITIES))) FOAM_UTILITIES = $(WM_PROJECT_DIR)/applications/utilities endif @@ -134,6 +152,8 @@ LIB_HEADER_DIRS = \ #------------------------------------------------------------------------------ # Define link statements for executables +# +# Tweak with FOAM_EXTRA_LDFLAGS #------------------------------------------------------------------------------ .PHONY: all @@ -147,7 +167,7 @@ silent: $(EXE)$(EXT_EXE): $(OBJECTS) @$(WM_SCRIPTS)/makeTargetDir $(EXE) $(call QUIET_MESSAGE,link,$(EXE)$(EXT_EXE)) - $E $(LINKEXE) $(OBJECTS) -L$(LIB_PLATFORMS) \ + $E $(LINKEXE) $(FOAM_EXTRA_LDFLAGS) $(OBJECTS) -L$(LIB_PLATFORMS) \ $(EXE_LIBS) $(PROJECT_LIBS) $(SYS_LIBS) \ $(LINK_LIBS) $(GLIBS) -o $(EXE)$(EXT_EXE) @@ -157,12 +177,14 @@ exe: $(SEXE)$(EXT_EXE) | silent $(SEXE)$(EXT_EXE): $(OBJECTS) @$(WM_SCRIPTS)/makeTargetDir $(SEXE) $(call QUIET_MESSAGE,link,$(SEXE)$(EXT_EXE)) - $E $(LINKEXE) $(OBJECTS) $(EXE_LIBS) \ + $E $(LINKEXE) $(FOAM_EXTRA_LDFLAGS) $(OBJECTS) $(EXE_LIBS) \ $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(SEXE)$(EXT_EXE) #------------------------------------------------------------------------------ # Define link statements for libraries +# +# Tweak with FOAM_EXTRA_LDFLAGS #------------------------------------------------------------------------------ .PHONY: objects @@ -175,13 +197,13 @@ ifneq (,$(findstring windows,$(WM_OSTYPE))) $(LIB)$(EXT_SO): $(OBJECTS) @$(WM_SCRIPTS)/makeTargetDir $(LIB) $(call QUIET_MESSAGE,link,$(LIB)$(EXT_SO)) - $E $(LINKLIBSO) $(OBJECTS) -L$(LIB_PLATFORMS) \ + $E $(LINKLIBSO) $(FOAM_EXTRA_LDFLAGS) $(OBJECTS) -L$(LIB_PLATFORMS) \ $(PROJECT_LIBS) $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB)$(EXT_SO) else $(LIB)$(EXT_SO): $(OBJECTS) @$(WM_SCRIPTS)/makeTargetDir $(LIB) $(call QUIET_MESSAGE,link,$(LIB)$(EXT_SO)) - $E $(LINKLIBSO) $(OBJECTS) -L$(LIB_PLATFORMS) \ + $E $(LINKLIBSO) $(FOAM_EXTRA_LDFLAGS) $(OBJECTS) -L$(LIB_PLATFORMS) \ $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB)$(EXT_SO) endif diff --git a/wmake/makefiles/info b/wmake/makefiles/info index 65fabf1f6f..4cc70638f9 100644 --- a/wmake/makefiles/info +++ b/wmake/makefiles/info @@ -5,7 +5,7 @@ # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ -# Copyright (C) 2019-2021 OpenCFD Ltd. +# Copyright (C) 2019-2022 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -96,6 +96,17 @@ cflags-arch: cxxflags-arch: @echo "$(strip $(c++ARCH))" +.PHONY: openmp-compile +openmp-compile: + @echo "$(strip $(COMP_OPENMP))" + +.PHONY: openmp-link +openmp-link: + @echo "$(strip $(LINK_OPENMP))" + +.PHONY: openmp +openmp: openmp-compile + # Like openmpi mpicc --showme:compile .PHONY: mpi-compile mpi-compile: diff --git a/wmake/rules/General/Amd/link-c b/wmake/rules/General/Amd/link-c index 98428c321e..a850a3a3bd 100644 --- a/wmake/rules/General/Amd/link-c +++ b/wmake/rules/General/Amd/link-c @@ -1,5 +1,9 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(cDBUG) LINKLIBSO = $(cc) $(cARCH) -shared LINKEXE = $(cc) $(cARCH) -Xlinker -z -Xlinker nodefs + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Amd/link-c++ b/wmake/rules/General/Amd/link-c++ index cbc13eaa31..e048a3dd1b 100644 --- a/wmake/rules/General/Amd/link-c++ +++ b/wmake/rules/General/Amd/link-c++ @@ -1,8 +1,14 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) -Wl,--as-needed -LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - $(FOAM_EXTRA_LDFLAGS) +LINKLIBSO = $(CC) $(c++FLAGS) -shared -LINKEXE = $(CC) $(c++FLAGS) \ - -L$(FOAM_LIBBIN)/dummy -lPstream \ - $(FOAM_EXTRA_LDFLAGS) +LINKEXE = $(CC) $(c++FLAGS) + +# Link dummy stub to resolve libPstream symbols used by libOpenFOAM +ifneq (,$(findstring -lOpenFOAM,$(PROJECT_LIBS))) + LINKEXE += -L$(FOAM_LIBBIN)/dummy -lPstream +endif + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Clang/c++ b/wmake/rules/General/Clang/c++ index a389b8c992..a476d44f90 100644 --- a/wmake/rules/General/Clang/c++ +++ b/wmake/rules/General/Clang/c++ @@ -26,7 +26,7 @@ c++LESSWARN = \ -Wno-unknown-warning-option \ -Wno-deprecated-copy-with-user-provided-copy \ -Wno-tautological-overlap-compare \ - -Wno-#pragma-messages + -Wno-\#pragma-messages # Tuning sinclude $(GENERAL_RULES)/common/c++$(WM_COMPILE_OPTION) diff --git a/wmake/rules/General/Clang/link-c b/wmake/rules/General/Clang/link-c index 79d1f2b6be..a5a6f9c06a 100644 --- a/wmake/rules/General/Clang/link-c +++ b/wmake/rules/General/Clang/link-c @@ -1,5 +1,9 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(cDBUG) LINKLIBSO = $(cc) $(cARCH) -shared LINKEXE = $(cc) $(cARCH) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Clang/link-c++ b/wmake/rules/General/Clang/link-c++ index 1713460ec3..b4581dc9bf 100644 --- a/wmake/rules/General/Clang/link-c++ +++ b/wmake/rules/General/Clang/link-c++ @@ -1,8 +1,10 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) -LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - $(FOAM_EXTRA_LDFLAGS) +LINKLIBSO = $(CC) $(c++FLAGS) -shared LINKEXE = $(CC) $(c++FLAGS) \ - -Xlinker --add-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --add-needed + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Clang/link-gold-c++ b/wmake/rules/General/Clang/link-gold-c++ index 33f46397a5..6bf424fa3c 100644 --- a/wmake/rules/General/Clang/link-gold-c++ +++ b/wmake/rules/General/Clang/link-gold-c++ @@ -1,10 +1,16 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - -fuse-ld=gold \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=gold LINKEXE = $(CC) $(c++FLAGS) \ - -fuse-ld=gold \ - -L$(FOAM_LIBBIN)/dummy -lPstream \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=gold + +# Link dummy stub to resolve libPstream symbols used by libOpenFOAM +ifneq (,$(findstring -lOpenFOAM,$(PROJECT_LIBS))) + LINKEXE += -L$(FOAM_LIBBIN)/dummy -lPstream +endif + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Clang/link-lld-c++ b/wmake/rules/General/Clang/link-lld-c++ index dbfa03192d..4af882e95f 100644 --- a/wmake/rules/General/Clang/link-lld-c++ +++ b/wmake/rules/General/Clang/link-lld-c++ @@ -1,10 +1,16 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - -fuse-ld=lld \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=lld LINKEXE = $(CC) $(c++FLAGS) \ - -fuse-ld=lld \ - -L$(FOAM_LIBBIN)/dummy -lPstream \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=lld + +# Link dummy stub to resolve libPstream symbols used by libOpenFOAM +ifneq (,$(findstring -lOpenFOAM,$(PROJECT_LIBS))) + LINKEXE += -L$(FOAM_LIBBIN)/dummy -lPstream +endif + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Clang/link-mold-c++ b/wmake/rules/General/Clang/link-mold-c++ index b5fa124c99..f84f20cd93 100644 --- a/wmake/rules/General/Clang/link-mold-c++ +++ b/wmake/rules/General/Clang/link-mold-c++ @@ -1,10 +1,16 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - -fuse-ld=mold \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=mold LINKEXE = $(CC) $(c++FLAGS) \ - -fuse-ld=mold \ - -L$(FOAM_LIBBIN)/dummy -lPstream \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=mold + +# Link dummy stub to resolve libPstream symbols used by libOpenFOAM +ifneq (,$(findstring -lOpenFOAM,$(PROJECT_LIBS))) + LINKEXE += -L$(FOAM_LIBBIN)/dummy -lPstream +endif + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Gcc/link-c b/wmake/rules/General/Gcc/link-c index 79d1f2b6be..a5a6f9c06a 100644 --- a/wmake/rules/General/Gcc/link-c +++ b/wmake/rules/General/Gcc/link-c @@ -1,5 +1,9 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(cDBUG) LINKLIBSO = $(cc) $(cARCH) -shared LINKEXE = $(cc) $(cARCH) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Gcc/link-c++ b/wmake/rules/General/Gcc/link-c++ index e023b8a35e..ced650574c 100644 --- a/wmake/rules/General/Gcc/link-c++ +++ b/wmake/rules/General/Gcc/link-c++ @@ -1,11 +1,13 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ -Xlinker --add-needed \ - -Xlinker --no-as-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --no-as-needed LINKEXE = $(CC) $(c++FLAGS) \ -Xlinker --add-needed \ - -Xlinker --no-as-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --no-as-needed + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Gcc/link-gold-c++ b/wmake/rules/General/Gcc/link-gold-c++ index 33f46397a5..6bf424fa3c 100644 --- a/wmake/rules/General/Gcc/link-gold-c++ +++ b/wmake/rules/General/Gcc/link-gold-c++ @@ -1,10 +1,16 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - -fuse-ld=gold \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=gold LINKEXE = $(CC) $(c++FLAGS) \ - -fuse-ld=gold \ - -L$(FOAM_LIBBIN)/dummy -lPstream \ - $(FOAM_EXTRA_LDFLAGS) + -fuse-ld=gold + +# Link dummy stub to resolve libPstream symbols used by libOpenFOAM +ifneq (,$(findstring -lOpenFOAM,$(PROJECT_LIBS))) + LINKEXE += -L$(FOAM_LIBBIN)/dummy -lPstream +endif + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Icc/link-c b/wmake/rules/General/Icc/link-c index a689d22d93..f9947ee3a6 100644 --- a/wmake/rules/General/Icc/link-c +++ b/wmake/rules/General/Icc/link-c @@ -1,5 +1,9 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(cDBUG) LINKLIBSO = $(cc) $(cFLAGS) -shared LINKEXE = $(cc) $(cFLAGS) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Icc/link-c++ b/wmake/rules/General/Icc/link-c++ index e023b8a35e..ced650574c 100644 --- a/wmake/rules/General/Icc/link-c++ +++ b/wmake/rules/General/Icc/link-c++ @@ -1,11 +1,13 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ -Xlinker --add-needed \ - -Xlinker --no-as-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --no-as-needed LINKEXE = $(CC) $(c++FLAGS) \ -Xlinker --add-needed \ - -Xlinker --no-as-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --no-as-needed + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Icx/link-c b/wmake/rules/General/Icx/link-c index a689d22d93..f9947ee3a6 100644 --- a/wmake/rules/General/Icx/link-c +++ b/wmake/rules/General/Icx/link-c @@ -1,5 +1,9 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(cDBUG) LINKLIBSO = $(cc) $(cFLAGS) -shared LINKEXE = $(cc) $(cFLAGS) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Icx/link-c++ b/wmake/rules/General/Icx/link-c++ index e023b8a35e..ced650574c 100644 --- a/wmake/rules/General/Icx/link-c++ +++ b/wmake/rules/General/Icx/link-c++ @@ -1,11 +1,13 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) LINKLIBSO = $(CC) $(c++FLAGS) -shared \ -Xlinker --add-needed \ - -Xlinker --no-as-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --no-as-needed LINKEXE = $(CC) $(c++FLAGS) \ -Xlinker --add-needed \ - -Xlinker --no-as-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --no-as-needed + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Nvidia/link-c b/wmake/rules/General/Nvidia/link-c index 79d1f2b6be..a5a6f9c06a 100644 --- a/wmake/rules/General/Nvidia/link-c +++ b/wmake/rules/General/Nvidia/link-c @@ -1,5 +1,9 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(cDBUG) LINKLIBSO = $(cc) $(cARCH) -shared LINKEXE = $(cc) $(cARCH) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/Nvidia/link-c++ b/wmake/rules/General/Nvidia/link-c++ index 1713460ec3..b4581dc9bf 100644 --- a/wmake/rules/General/Nvidia/link-c++ +++ b/wmake/rules/General/Nvidia/link-c++ @@ -1,8 +1,10 @@ +#------------------------------------------------------------------------------ + LINK_LIBS = $(c++DBUG) -LINKLIBSO = $(CC) $(c++FLAGS) -shared \ - $(FOAM_EXTRA_LDFLAGS) +LINKLIBSO = $(CC) $(c++FLAGS) -shared LINKEXE = $(CC) $(c++FLAGS) \ - -Xlinker --add-needed \ - $(FOAM_EXTRA_LDFLAGS) + -Xlinker --add-needed + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/General/cuda b/wmake/rules/General/cuda index 5a30f6a663..f6dbdeaedc 100644 --- a/wmake/rules/General/cuda +++ b/wmake/rules/General/cuda @@ -3,7 +3,7 @@ SUFFIXES += .cu -ifeq (,$(NVARCH)) +ifeq (,$(strip $(NVARCH))) NVARCH = 70 endif diff --git a/wmake/rules/General/general b/wmake/rules/General/general index bb63668862..38ee9bd0fb 100644 --- a/wmake/rules/General/general +++ b/wmake/rules/General/general @@ -33,7 +33,7 @@ else endif # Default compilation is 'Opt' - never permit an empty value -ifeq (,$(WM_COMPILE_OPTION)) +ifeq (,$(strip $(WM_COMPILE_OPTION))) WM_COMPILE_OPTION := Opt endif @@ -46,6 +46,12 @@ ifneq ("$(COMPILER_FAMILY)","$(WM_COMPILER)") sinclude $(RULES)/general sinclude $(RULES)/c++ endif + +# Add compile flags for openmp +ifneq (,$(findstring +openmp,$(WM_COMPILE_CONTROL))) +c++FLAGS += $(COMP_OPENMP) +endif + include $(GENERAL_RULES)/transform #------------------------------------------------------------------------------ diff --git a/wmake/rules/General/mpi-rules b/wmake/rules/General/mpi-rules index 411e0f7f5c..21be1612da 100644 --- a/wmake/rules/General/mpi-rules +++ b/wmake/rules/General/mpi-rules @@ -22,7 +22,7 @@ ifneq ("$(MPLIB_FAMILY)","$(WM_MPLIB)") endif # Specific rules -ifneq ("","$(WM_MPLIB)") +ifneq (,$(strip $(WM_MPLIB))) sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB) sinclude $(DEFAULT_RULES)/mplib$(WM_MPLIB) # system-specific @@ -32,7 +32,7 @@ ifneq ("","$(WM_MPLIB)") endif # Default target MPI libdir is PROJECT lib/ -ifeq (,$(FOAM_MPI_LIBBIN)) +ifeq (,$(strip $(FOAM_MPI_LIBBIN))) FOAM_MPI_LIBBIN := $(FOAM_LIBBIN)/$(FOAM_MPI) endif diff --git a/wmake/rules/General/transform b/wmake/rules/General/transform index 82e8a358ff..202d0a2a2b 100644 --- a/wmake/rules/General/transform +++ b/wmake/rules/General/transform @@ -11,7 +11,7 @@ WMKDEP := $(WMAKE_BIN)/wmkdepend WMKDEP_FLAGS := -eWM_PROJECT_DIR -eWM_THIRD_PARTY_DIR -ifneq ("","$(WM_QUIET)") +ifneq (,$(strip $(WM_QUIET))) E=@ define QUIET_MESSAGE @echo " $1: $2"; @@ -38,7 +38,7 @@ $(foreach s,$(SUFFIXES),$(eval $(call DEFINE_TRANSFORM,$(s)))) $(OBJECTS_DIR)/%.dep : % $(call QUIET_MESSAGE,dep,$(&2 + echo "Logging wmake -all output to '$wmakeOpt_log'" 1>&2 echo 1>&2 - exec wmake $optWmakeFrontend -all \ - $optDebug $optQueue $* 2>&1 | /usr/bin/tee $optLog + exec wmake $wmakeOpt_frontend -all \ + $wmakeOpt_debug $wmakeOpt_queue $wmakeOpt_openmp $* 2>&1 | \ + /usr/bin/tee $wmakeOpt_log # Need to cleanup after the tee rc=$? # Error code from tee (not wmake), but not entirely important - echo "Done logging to '$optLog'" 1>&2 + echo "Done logging to '$wmakeOpt_log'" 1>&2 exit "$rc" fi fi @@ -230,8 +233,8 @@ fi # Cleanup local variables and functions #------------------------------------------------------------------------------ -unset optWmakeFrontend -unset optNonRecursive optDebug optLog optQueue +unset wmakeOpt_frontend wmakeOpt_nonRecursive +unset wmakeOpt_debug wmakeOpt_log wmakeOpt_queue unset -f usage diff --git a/wmake/src/Makefile b/wmake/src/Makefile index f53f29f50f..bea18d6281 100644 --- a/wmake/src/Makefile +++ b/wmake/src/Makefile @@ -40,9 +40,12 @@ SHELL = /bin/sh # Set compilation and dependency building rules #------------------------------------------------------------------------------ -# Locally set optimized compilation +# Locally defined: optimized compilation WM_COMPILE_OPTION = Opt +# Never want openmp for tools! +WM_COMPILE_CONTROL += ~openmp + GENERAL_RULES = $(WM_DIR)/rules/General include $(GENERAL_RULES)/general @@ -62,7 +65,7 @@ all: $(WMAKE_BIN)/lemon$(EXT_EXE) $(WMAKE_BIN)/wmkdepend$(EXT_EXE) message old: $(WMAKE_BIN)/wmkdep$(EXT_EXE) message: -ifneq ($(archBuild),$(archTarget)) +ifneq ("$(archBuild)","$(archTarget)") @echo "built wmake-bin ($(archTarget)) with $(archBuild)" else @echo "built wmake-bin ($(archTarget))" diff --git a/wmake/wmake b/wmake/wmake index aef2fecb4a..2898b73da9 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -75,7 +75,10 @@ cat<&2 + +# Handle debug flags +if [ -n "$opt_debug" ] +then + # Add -debug value and -DFULLDEBUG into FOAM_EXTRA_CXXFLAGS + opt_debug="${FOAM_EXTRA_CXXFLAGS:+ }${opt_debug} -DFULLDEBUG" + case "$FOAM_EXTRA_CXXFLAGS" in + (*-DFULLDEBUG*) + # Appears to have already been added + ;; + (*) + export FOAM_EXTRA_CXXFLAGS="${FOAM_EXTRA_CXXFLAGS}${opt_debug}" + ;; + esac +fi + +# Extract ccache controls from WM_COMPILE_CONTROL if possible +# and when queuing is not active +if [ "$opt_all" != queue ] +then + unset opt_ccache + + case "$WM_COMPILE_CONTROL" in + (*ccache=*) + opt_ccache="${WM_COMPILE_CONTROL##*ccache=}" + case "$opt_ccache" in + ('<'*) + # Angle bracket quoted: ccache= + # - extract between < > delimiters + opt_ccache="${opt_ccache#<}" + opt_ccache="${opt_ccache%%>*}" + ;; + ("'"*) + # Single-quoted + opt_ccache="${opt_ccache#\'}" + opt_ccache="${opt_ccache%%\'*}" + ;; + ('"'*) + # Double-quoted + opt_ccache="${opt_ccache#\"}" + opt_ccache="${opt_ccache%%\"*}" + ;; + (*) + # Plain ccache=command - truncate after first space + opt_ccache="${opt_ccache%% *}" + ;; + esac + ;; + (*'+ccache'*) + # Simple specification + opt_ccache="ccache" + ;; + esac + + if [ -n "$opt_ccache" ] + then + export WM_SCHEDULER="$opt_ccache" + fi +fi + +# Debug: +##echo "WM_SCHEDULER='$WM_SCHEDULER'" 1>&2 + + #------------------------------------------------------------------------------ # Recurse the source tree to update all #------------------------------------------------------------------------------ -if [ "$optUpdate" = true ] +if [ "$opt_update" = true ] then wrmdep -update wrmdep -old @@ -487,29 +597,14 @@ then export WM_UPDATE_DEPENDENCIES=yes fi - -unset exitCode - #------------------------------------------------------------------------------ # Recurse the source tree to compile "all" targets #------------------------------------------------------------------------------ -if [ -n "$optDebug" ] +if [ "$opt_all" = all ] then - # Add -debug value and -DFULLDEBUG into FOAM_EXTRA_CXXFLAGS - optDebug="${FOAM_EXTRA_CXXFLAGS:+ }$optDebug -DFULLDEBUG" - case "$FOAM_EXTRA_CXXFLAGS" in - (*-DFULLDEBUG*) - # Appears to have already been added - ;; - (*) - export FOAM_EXTRA_CXXFLAGS="${FOAM_EXTRA_CXXFLAGS}${optDebug}" - ;; - esac -fi + unset exitCode -if [ "$optAll" = all ] -then if [ -e Allwmake.override ] then if [ -x Allwmake.override ] @@ -565,9 +660,10 @@ fi #------------------------------------------------------------------------------ # Recurse source tree to compile "all" targets using wmakeCollect #------------------------------------------------------------------------------ -if [ "$optAll" = queue ] + +if [ "$opt_all" = queue ] then - [ "$optUpdate" = true ] || wmakeLnIncludeAll $parOpt + [ "$opt_update" = true ] || wmakeLnIncludeAll $parOpt if [ -n "$FOAM_BUILDROOT" ] && [ -w "$FOAM_BUILDROOT" ] then @@ -705,6 +801,7 @@ esac if [ -n "$WM_UPDATE_DEPENDENCIES" ] then + unset exitCode $make -f "$WM_DIR"/makefiles/general \ MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" updatedep