Skip to content

Commit e828854

Browse files
Villemoesgregkh
authored andcommitted
Kbuild: fix # escaping in .cmd files for future Make
commit 9564a8c upstream. I tried building using a freshly built Make (4.2.1-69-g8a731d1), but already the objtool build broke with orc_dump.c: In function ‘orc_dump’: orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations] if (elf_getshdrnum(elf, &nr_sections)) { Turns out that with that new Make, the backslash was not removed, so cpp didn't see a #include directive, grep found nothing, and -DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS. Now, that new Make behaviour is documented in their NEWS file: * WARNING: Backward-incompatibility! Number signs (#) appearing inside a macro reference or function invocation no longer introduce comments and should not be escaped with backslashes: thus a call such as: foo := $(shell echo '#') is legal. Previously the number sign needed to be escaped, for example: foo := $(shell echo '\#') Now this latter will resolve to "\#". If you want to write makefiles portable to both versions, assign the number sign to a variable: C := \# foo := $(shell echo '$C') This was claimed to be fixed in 3.81, but wasn't, for some reason. To detect this change search for 'nocomment' in the .FEATURES variable. This also fixes up the two make-cmd instances to replace # with $(pound) rather than with \#. There might very well be other places that need similar fixup in preparation for whatever future Make release contains the above change, but at least this builds an x86_64 defconfig with the new make. Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847 Cc: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3bb6397 commit e828854

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎scripts/Kbuild.include‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ squote := '
88
empty :=
99
space := $(empty) $(empty)
1010
space_escape := _-_SPACE_-_
11+
pound := \#
1112

1213
###
1314
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
@@ -251,11 +252,11 @@ endif
251252

252253
# Replace >$< with >$$< to preserve $ when reloading the .cmd file
253254
# (needed for make)
254-
# Replace >#< with >\#< to avoid starting a comment in the .cmd file
255+
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
255256
# (needed for make)
256257
# Replace >'< with >'\''< to be able to enclose the whole string in '...'
257258
# (needed for the shell)
258-
make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
259+
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
259260

260261
# Find any prerequisites that is newer than target or that does not exist.
261262
# PHONY targets skipped in both cases.

‎tools/build/Build.include‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Convenient variables
1313
comma := ,
1414
squote := '
15+
pound := \#
1516

1617
###
1718
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
@@ -43,11 +44,11 @@ echo-cmd = $(if $($(quiet)cmd_$(1)),\
4344
###
4445
# Replace >$< with >$$< to preserve $ when reloading the .cmd file
4546
# (needed for make)
46-
# Replace >#< with >\#< to avoid starting a comment in the .cmd file
47+
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
4748
# (needed for make)
4849
# Replace >'< with >'\''< to be able to enclose the whole string in '...'
4950
# (needed for the shell)
50-
make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
51+
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
5152

5253
###
5354
# Find any prerequisites that is newer than target or that does not exist.

‎tools/objtool/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CFLAGS += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
3535
LDFLAGS += -lelf $(LIBSUBCMD)
3636

3737
# Allow old libelf to be used:
38-
elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
38+
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
3939
CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
4040

4141
AWK = awk

‎tools/scripts/Makefile.include‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ ifneq ($(silent),1)
101101
QUIET_INSTALL = @printf ' INSTALL %s\n' $1;
102102
endif
103103
endif
104+
105+
pound := \#

0 commit comments

Comments
 (0)