From 4730c381eface67b315ec57ba63635a9da80ff1e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 19 Aug 2022 14:49:37 +0200 Subject: [PATCH] COMP: avoid cpp replacement of linux,unix,... in Make/options (fixes #2548) - the cpp command is used to process Make/{files,options}, but builtin defines such as `linux` will cause problems (macro replacement) if these is present in the Make/{files,options}. Solve by undefining -Ulinux, -Uunix macros, which will leave directory names such as "/usr/lib/x86_64-linux-gnu/..." intact. Directories with _linux, __linux__ content (for example), could still pose future issues. --- wmake/makefiles/files | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/wmake/makefiles/files b/wmake/makefiles/files index 39337b91d3..a5a35883dd 100644 --- a/wmake/makefiles/files +++ b/wmake/makefiles/files @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2018-2020 OpenCFD Ltd. +# Copyright (C) 2018-2022 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -47,16 +47,31 @@ WM_SCRIPTS = $(WM_DIR)/scripts # Causes all derived files to be remade if any are changed or missing #------------------------------------------------------------------------------ +# Process 'Make/{files,options}' via cpp, but undefine linux,unix,... to avoid +# inadvertent replacements (Eg, leave /usr/lib/x86_64-linux-gnu/... intact) +define PREFILTER_MAKE_OPTIONS + @$(CPP) -Ulinux -Uunix $(GFLAGS) $1 | sed -e 's@ *@ @g' > $2 +endef + + all : $(OPTIONS) $(SFILES) $(VARS) +# Make/options +# ~~~~~~~~~~~~ $(OPTIONS) : $(MAKE_DIR)/options - @$(CPP) $(GFLAGS) $(MAKE_DIR)/options | sed -e 's@ *@ @g' > $(OPTIONS) + $(call PREFILTER_MAKE_OPTIONS,$<,${OPTIONS}) ifneq (,$(findstring windows,$(WM_OSTYPE))) @$(WM_SCRIPTS)/wmakeWindowsDlOpenLibs $(OPTIONS) >> $(OPTIONS) endif + # Ensure final line is followed by newline. Extra comment for safety. + @echo >> $(OPTIONS) + @echo "# options" >> $(OPTIONS) + +# Make/files +# ~~~~~~~~~~ $(SFILES): $(MAKE_DIR)/files - @$(CPP) $(GFLAGS) $(MAKE_DIR)/files | sed -e 's@ *@ @g' > $(FILES) + $(call PREFILTER_MAKE_OPTIONS,$<,${FILES}) # Extracted macro definitions. @sed -n -e '/=/p' $(FILES) > $(VARS) @echo "SOURCE = \\" > $(SFILES) @@ -64,7 +79,7 @@ $(SFILES): $(MAKE_DIR)/files @sed -e '/=/d; /^#/d; /^[ \t]*$$/d' -e 's@[ \t]*$$@ \\@' $(FILES) >> $(SFILES) @rm -f $(FILES) # Ensure final line is followed by newline. Extra comment for safety. - @echo "" >> $(SFILES) + @echo >> $(SFILES) @echo "# sources" >> $(SFILES)