@@ -7,10 +7,14 @@ squote := '
77empty :=
88space := $(empty) $(empty)
99
10+ ###
11+ # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
12+ dot-target = $(dir $@).$(notdir $@)
13+
1014###
1115# The temporary file to save gcc -MD generated dependencies must not
1216# contain a comma
13- depfile = $(subst $(comma),_,$(@D)/.$(@F ).d)
17+ depfile = $(subst $(comma),_,$(dot-target ).d)
1418
1519###
1620# filename of target with directory and extension stripped
@@ -119,40 +123,44 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
119123ifneq ($(KBUILD_NOCMDDEP),1)
120124# Check if both arguments has same arguments. Result in empty string if equal
121125# User may override this check using make KBUILD_NOCMDDEP=1
122- arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) )
126+ arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
127+ $(filter-out $(cmd_$@), $(cmd_$(1))) )
123128endif
124129
125130# echo command. Short version is $(quiet) equals quiet, otherwise full command
126131echo-cmd = $(if $($(quiet)cmd_$(1)), \
127132 echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
128133
134+ # >'< substitution is for echo to work,
135+ # >$< substitution to preserve $ when reloading .cmd file
136+ # note: when using inline perl scripts [perl -e '...$$t=1;...']
137+ # in $(cmd_xxx) double $$ your perl vars
129138make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))))
130139
131- # function to only execute the passed command if necessary
132- # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
133- # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars
140+ # Find any prerequisites that is newer than target or that does not exist.
141+ # PHONY targets skipped in both cases.
142+ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
143+
144+ # Execute command if command has changed or prerequisitei(s) are updated
134145#
135- if_changed = $(if $(strip $(filter-out $(PHONY),$?) \
136- $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
137- @set -e; \
138- $(echo-cmd) $(cmd_$(1)); \
139- echo 'cmd_$@ := $(make-cmd)' > $(@D)/.$(@F).cmd)
146+ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
147+ @set -e; \
148+ $(echo-cmd) $(cmd_$(1)); \
149+ echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
140150
141151# execute the command and also postprocess generated .d dependencies
142152# file
143- if_changed_dep = $(if $(strip $(filter-out $(PHONY),$?) \
144- $(filter-out FORCE $(wildcard $^),$^) \
145- $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
146- @set -e; \
147- $(echo-cmd) $(cmd_$(1)); \
148- scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(@D)/.$(@F).tmp; \
149- rm -f $(depfile); \
150- mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
153+ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \
154+ @set -e; \
155+ $(echo-cmd) $(cmd_$(1)); \
156+ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\
157+ rm -f $(depfile); \
158+ mv -f $(dot-target).tmp $(dot-target).cmd)
151159
152160# Usage: $(call if_changed_rule,foo)
153161# will check if $(cmd_foo) changed, or any of the prequisites changed,
154162# and if so will execute $(rule_foo)
155- if_changed_rule = $(if $(strip $(filter-out $(PHONY),$?) \
156- $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
157- @set -e; \
158- $(rule_$(1)))
163+ if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \
164+ @set -e; \
165+ $(rule_$(1)))
166+
0 commit comments