Commit 164f0d2e authored by Michal Marek's avatar Michal Marek

kbuild: Fix handling of backslashes in *.cmd files

Commit c353acba ("kbuild: make: fix if_changed when command contains
backslashes") attempted to handle backslashes in *.cmd files, but it
only handled double backslashes for some reason. Changing make-cmd to also
handle single backslashes fixes rebuilds with dash, but it breaks bash
again. The reason is that the two shells disagree about the
interpretation of backslash sequences in the echo builtin. The way out
of this is to print the command with printf '%s\n'. While at it,
document what the individual parts of make-cmd do and why.
Reported-and-tested-by: default avatarKonstantin Khlebnikov <koct9i@gmail.com>
Reviewed-by: default avatarSam Ravnborg <sam@ravnborg.org>
Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
parent 26ea6bb1
...@@ -215,11 +215,13 @@ else ...@@ -215,11 +215,13 @@ else
arg-check = $(if $(strip $(cmd_$@)),,1) arg-check = $(if $(strip $(cmd_$@)),,1)
endif endif
# >'< substitution is for echo to work, # Replace >$< with >$$< to preserve $ when reloading the .cmd file
# >$< substitution to preserve $ when reloading .cmd file # (needed for make)
# note: when using inline perl scripts [perl -e '...$$t=1;...'] # Replace >#< with >\#< to avoid starting a comment in the .cmd file
# in $(cmd_xxx) double $$ your perl vars # (needed for make)
make-cmd = $(subst \\,\\\\,$(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))))) # Replace >'< with >'\''< to be able to enclose the whole string in '...'
# (needed for the shell)
make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
# Find any prerequisites that is newer than target or that does not exist. # Find any prerequisites that is newer than target or that does not exist.
# PHONY targets skipped in both cases. # PHONY targets skipped in both cases.
...@@ -230,7 +232,7 @@ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) ...@@ -230,7 +232,7 @@ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
@set -e; \ @set -e; \
$(echo-cmd) $(cmd_$(1)); \ $(echo-cmd) $(cmd_$(1)); \
echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
# Execute the command and also postprocess generated .d dependencies file. # Execute the command and also postprocess generated .d dependencies file.
if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment