diff options
| author | Sam Ravnborg <sam@mars.ravnborg.org> | 2006-07-23 13:37:44 -0400 |
|---|---|---|
| committer | Sam Ravnborg <sam@neptun.ravnborg.org> | 2006-09-25 03:00:00 -0400 |
| commit | 48f1f0589dd09df6ea07d41c737db3218ad2cb79 (patch) | |
| tree | 2dd9563f30467f252e08477e7e63c4adeb4c0caa /scripts/Kbuild.include | |
| parent | d3660a8cbdfad620af88b85b7bbfff29160f14c2 (diff) | |
kbuild: consistently decide when to rebuild a target
Consistently decide when to rebuild a target across all of
if_changed, if_changed_dep, if_changed_rule.
PHONY targets are now treated alike (ignored) for all targets
While add it make Kbuild.include almost readable by factoring out a few
bits to some common variables and reuse this in Makefile.build.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/Kbuild.include')
| -rw-r--r-- | scripts/Kbuild.include | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index bb19c1561f1..1d6ffb26e20 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include | |||
| @@ -8,9 +8,13 @@ empty := | |||
| 8 | space := $(empty) $(empty) | 8 | space := $(empty) $(empty) |
| 9 | 9 | ||
| 10 | ### | 10 | ### |
| 11 | # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o | ||
| 12 | dot-target = $(dir $@).$(notdir $@) | ||
| 13 | |||
| 14 | ### | ||
| 11 | # The temporary file to save gcc -MD generated dependencies must not | 15 | # The temporary file to save gcc -MD generated dependencies must not |
| 12 | # contain a comma | 16 | # contain a comma |
| 13 | depfile = $(subst $(comma),_,$(@D)/.$(@F).d) | 17 | depfile = $(subst $(comma),_,$(dot-target).d) |
| 14 | 18 | ||
| 15 | ### | 19 | ### |
| 16 | # filename of target with directory and extension stripped | 20 | # filename of target with directory and extension stripped |
| @@ -119,40 +123,44 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) | |||
| 119 | ifneq ($(KBUILD_NOCMDDEP),1) | 123 | ifneq ($(KBUILD_NOCMDDEP),1) |
| 120 | # Check if both arguments has same arguments. Result in empty string if equal | 124 | # Check if both arguments has same arguments. Result in empty string if equal |
| 121 | # User may override this check using make KBUILD_NOCMDDEP=1 | 125 | # 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))) ) | ||
| 123 | endif | 128 | endif |
| 124 | 129 | ||
| 125 | # echo command. Short version is $(quiet) equals quiet, otherwise full command | 130 | # echo command. Short version is $(quiet) equals quiet, otherwise full command |
| 126 | echo-cmd = $(if $($(quiet)cmd_$(1)), \ | 131 | echo-cmd = $(if $($(quiet)cmd_$(1)), \ |
| 127 | echo ' $(call escsq,$($(quiet)cmd_$(1)))';) | 132 | echo ' $(call escsq,$($(quiet)cmd_$(1)))';) |
| 128 | 133 | ||
| 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 | ||
| 129 | make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))) | 138 | make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))) |
| 130 | 139 | ||
| 131 | # function to only execute the passed command if necessary | 140 | # Find any prerequisites that is newer than target or that does not exist. |
| 132 | # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file | 141 | # PHONY targets skipped in both cases. |
| 133 | # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars | 142 | any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) |
| 143 | |||
| 144 | # Execute command if command has changed or prerequisitei(s) are updated | ||
| 134 | # | 145 | # |
| 135 | if_changed = $(if $(strip $(filter-out $(PHONY),$?) \ | 146 | if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ |
| 136 | $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ | 147 | @set -e; \ |
| 137 | @set -e; \ | 148 | $(echo-cmd) $(cmd_$(1)); \ |
| 138 | $(echo-cmd) $(cmd_$(1)); \ | 149 | echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) |
| 139 | echo 'cmd_$@ := $(make-cmd)' > $(@D)/.$(@F).cmd) | ||
| 140 | 150 | ||
| 141 | # execute the command and also postprocess generated .d dependencies | 151 | # execute the command and also postprocess generated .d dependencies |
| 142 | # file | 152 | # file |
| 143 | if_changed_dep = $(if $(strip $(filter-out $(PHONY),$?) \ | 153 | if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ |
| 144 | $(filter-out FORCE $(wildcard $^),$^) \ | 154 | @set -e; \ |
| 145 | $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ | 155 | $(echo-cmd) $(cmd_$(1)); \ |
| 146 | @set -e; \ | 156 | scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ |
| 147 | $(echo-cmd) $(cmd_$(1)); \ | 157 | rm -f $(depfile); \ |
| 148 | scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(@D)/.$(@F).tmp; \ | 158 | mv -f $(dot-target).tmp $(dot-target).cmd) |
| 149 | rm -f $(depfile); \ | ||
| 150 | mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) | ||
| 151 | 159 | ||
| 152 | # Usage: $(call if_changed_rule,foo) | 160 | # Usage: $(call if_changed_rule,foo) |
| 153 | # will check if $(cmd_foo) changed, or any of the prequisites changed, | 161 | # will check if $(cmd_foo) changed, or any of the prequisites changed, |
| 154 | # and if so will execute $(rule_foo) | 162 | # and if so will execute $(rule_foo) |
| 155 | if_changed_rule = $(if $(strip $(filter-out $(PHONY),$?) \ | 163 | if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ |
| 156 | $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ | 164 | @set -e; \ |
| 157 | @set -e; \ | 165 | $(rule_$(1))) |
| 158 | $(rule_$(1))) | 166 | |
