Skip to content

Commit 9564a8c

Browse files
Villemoesmasahir0y
authored andcommitted
Kbuild: fix # escaping in .cmd files for future Make
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 <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent b41d920 commit 9564a8c

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

scripts/Kbuild.include

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ space := $(empty) $(empty)
1010
space_escape := _-_SPACE_-_
1111
right_paren := )
1212
left_paren := (
13+
pound := \#
1314

1415
###
1516
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
@@ -322,11 +323,11 @@ endif
322323

323324
# Replace >$< with >$$< to preserve $ when reloading the .cmd file
324325
# (needed for make)
325-
# Replace >#< with >\#< to avoid starting a comment in the .cmd file
326+
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
326327
# (needed for make)
327328
# Replace >'< with >'\''< to be able to enclose the whole string in '...'
328329
# (needed for the shell)
329-
make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
330+
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
330331

331332
# Find any prerequisites that is newer than target or that does not exist.
332333
# 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
@@ -120,3 +120,5 @@ ifneq ($(silent),1)
120120
QUIET_UNINST = @printf ' UNINST %s\n' $1;
121121
endif
122122
endif
123+
124+
pound := \#

0 commit comments

Comments
 (0)