Commit d51bfb78 authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: introduce escsq to escapre single quotes

This makes things a little bit more reader friendly and gvim is less
confused.
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 37193147
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Convinient variables # Convinient variables
comma := , comma := ,
squote := '
empty := empty :=
space := $(empty) $(empty) space := $(empty) $(empty)
...@@ -11,6 +12,10 @@ space := $(empty) $(empty) ...@@ -11,6 +12,10 @@ space := $(empty) $(empty)
# contain a comma # contain a comma
depfile = $(subst $(comma),_,$(@D)/.$(@F).d) depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
###
# Escape single quote for use in echo statements
escsq = $(subst $(squote),'\$(squote)',$1)
### ###
# filechk is used to check if the content of a generated file is updated. # filechk is used to check if the content of a generated file is updated.
# Sample usage: # Sample usage:
...@@ -47,7 +52,7 @@ build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj ...@@ -47,7 +52,7 @@ build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
# If quiet is set, only print short version of command # If quiet is set, only print short version of command
cmd = @$(if $($(quiet)cmd_$(1)),\ cmd = @$(if $($(quiet)cmd_$(1)),\
echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) echo ' $(call escsq,$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
# Add $(obj)/ for paths that is not absolute # Add $(obj)/ for paths that is not absolute
objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
...@@ -68,7 +73,7 @@ endif ...@@ -68,7 +73,7 @@ endif
# echo command. Short version is $(quiet) equals quiet, otherwise full command # echo command. Short version is $(quiet) equals quiet, otherwise full command
echo-cmd = $(if $($(quiet)cmd_$(1)), \ echo-cmd = $(if $($(quiet)cmd_$(1)), \
echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
# function to only execute the passed command if necessary # function to only execute the passed command if necessary
# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
...@@ -78,7 +83,7 @@ if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ ...@@ -78,7 +83,7 @@ if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
@set -e; \ @set -e; \
$(echo-cmd) \ $(echo-cmd) \
$(cmd_$(1)); \ $(cmd_$(1)); \
echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) echo 'cmd_$@ := $(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
# execute the command and also postprocess generated .d dependencies # execute the command and also postprocess generated .d dependencies
# file # file
...@@ -87,7 +92,7 @@ if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ ...@@ -87,7 +92,7 @@ if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
@set -e; \ @set -e; \
$(echo-cmd) \ $(echo-cmd) \
$(cmd_$(1)); \ $(cmd_$(1)); \
scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
rm -f $(depfile); \ rm -f $(depfile); \
mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
......
...@@ -179,10 +179,10 @@ endif ...@@ -179,10 +179,10 @@ endif
define rule_cc_o_c define rule_cc_o_c
$(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \ $(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \
$(cmd_checksrc) \ $(cmd_checksrc) \
$(if $($(quiet)cmd_cc_o_c),echo ' $(subst ','\'',$($(quiet)cmd_cc_o_c))';) \ $(if $($(quiet)cmd_cc_o_c),echo ' $(call escsq,$($(quiet)cmd_cc_o_c))';) \
$(cmd_cc_o_c); \ $(cmd_cc_o_c); \
$(cmd_modversions) \ $(cmd_modversions) \
scripts/basic/fixdep $(depfile) $@ '$(subst ','\'',$(cmd_cc_o_c))' > $(@D)/.$(@F).tmp; \ scripts/basic/fixdep $(depfile) $@ '$(call escsq,$(cmd_cc_o_c))' > $(@D)/.$(@F).tmp; \
rm -f $(depfile); \ rm -f $(depfile); \
mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
endef endef
......
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