kbuild: macrofy the condition of if_changed and friends
PATCH 1/2 kbuild: macrofy the condition of if_changed and friends
Add a new macro that expands into $(newer-prereqs)$(cmd-check).
It makes it easier to add common code for if_changed, if_changed_dep, and if_changed_rule.
---
scripts/Kbuild.include | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
scripts/Kbuild.include +5 -3
@@ -130,13 +130,15 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) # PHONY targets skipped in both cases. newer-prereqs = $(filter-out $(PHONY),$?) +if-changed-cond = $(newer-prereqs)$(cmd-check) + # Execute command if command has changed or prerequisite(s) are updated. -if_changed = $(if $(newer-prereqs)$(cmd-check), \ +if_changed = $(if $(if-changed-cond), \ $(cmd); \ printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Execute the command and also postprocess generated .d dependencies file. -if_changed_dep = $(if $(newer-prereqs)$(cmd-check),$(cmd_and_fixdep),@:) +if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:) cmd_and_fixdep = \ $(cmd); \
@@ -146,7 +148,7 @@ cmd_and_fixdep = \ # Usage: $(call if_changed_rule,foo) # Will check if $(cmd_foo) or any of the prerequisites changed, # and if so will execute $(rule_foo). -if_changed_rule = $(if $(newer-prereqs)$(cmd-check),$(rule_$(1)),@:) +if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:) ### # why - tell why a target got built
Signature · 1 line
2.30.2
PATCH 2/2 kbuild: warn if FORCE is missing for if_changed(_dep,_rule) and filechk
if_changed, if_changed_dep, and if_changed_rule must have FORCE as a prerequisite so the command line change is detected.
Documentation/kbuild/makefiles.rst clearly explains it:
Note: It is a typical mistake to forget the FORCE prerequisite.
However, not all people read the document, or understand what is written in it.
People repeated this mistake over again, and I determined a compelling force is needed.
Show a warning if FORCE is missing in the prerequisite of if_changed and friends. Same for filechk.
---
scripts/Kbuild.include | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/Kbuild.include +6 -1
@@ -57,6 +57,7 @@ kecho := $($(quiet)kecho) # - If the content differ the new file is used # - If they are equal no change, and no timestamp update define filechk + $(check-FORCE) $(Q)set -e; \ mkdir -p $(dir $@); \ trap "rm -f $(dot-target).tmp" EXIT; \
@@ -130,7 +131,11 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) # PHONY targets skipped in both cases. newer-prereqs = $(filter-out $(PHONY),$?) -if-changed-cond = $(newer-prereqs)$(cmd-check) +# It is a typical mistake to forget the FORCE prerequisite. Check it here so +# no more breakage will slip in. +check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequsite is missing)) + +if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE) # Execute command if command has changed or prerequisite(s) are updated. if_changed = $(if $(if-changed-cond), \
Signature · 1 line
2.30.2
Re: [PATCH 2/2] kbuild: warn if FORCE is missing for if_changed(_dep,_rule) and filechk
Quoted 35 lines · On Friday, 2021-08-13 Masahiro Yamada wrote:
if_changed,if_changed_dep, andif_changed_rulemust have FORCE as a prerequisite so the command line change is detected.
Documentation/kbuild/makefiles.rstclearly explains it:Note: It is a typical mistake to forget the FORCE prerequisite.
However, not all people read the document, or understand what is written in it.
People repeated this mistake over again, and I determined a compelling force is needed.
Show a warning if FORCE is missing in the prerequisite of
if_changedand friends. Same for filechk.Signed-off-by Masahiro Yamada <[email protected]>---
scripts/Kbuild.include | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)scripts/Kbuild.include +1
-0@@ -57,6 +57,7 @@ kecho := $($(quiet)kecho) # - If the content differ the new file is used # - If they are equal no change, and no timestamp update define filechk + $(check-FORCE) $(Q)set -e; \ mkdir -p $(dir $@); \ trap "rm -f $(dot-target).tmp" EXIT; \
scripts/Kbuild.include make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) · line 134
Quoted 5 lines
scripts/Kbuild.include +1
-1@@ -130,7 +131,11 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) # PHONY targets skipped in both cases. newer-prereqs = $(filter-out $(PHONY),$?) -if-changed-cond = $(newer-prereqs)$(cmd-check) +# It is a typical mistake to forget the FORCE prerequisite. Check it here so
prerequsite -> prerequisite?
Successfully found the missing FORCE in arch/x86/entry/vdso/Makefile:135.
Quoted 10 lines
scripts/Kbuild.include +4
-0+# no more breakage will slip in. +check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequsite is missing)) + +if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE) # Execute command if command has changed or prerequisite(s) are updated. if_changed = $(if $(if-changed-cond), \Signature · 1 line
2.30.2
Re: [PATCH 2/2] kbuild: warn if FORCE is missing for if_changed(_dep,_rule) and filechk
Quoted 40 lines · Nicolas Schier
Quoted 38 lines · On Friday, 2021-08-13 Masahiro Yamada wrote:
if_changed,if_changed_dep, andif_changed_rulemust have FORCE as a prerequisite so the command line change is detected.
Documentation/kbuild/makefiles.rstclearly explains it:Note: It is a typical mistake to forget the FORCE prerequisite.
However, not all people read the document, or understand what is written in it.
People repeated this mistake over again, and I determined a compelling force is needed.
Show a warning if FORCE is missing in the prerequisite of
if_changedand friends. Same for filechk.Signed-off-by Masahiro Yamada <[email protected]>---
scripts/Kbuild.include | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)scripts/Kbuild.include +1
-0@@ -57,6 +57,7 @@ kecho := $($(quiet)kecho) # - If the content differ the new file is used # - If they are equal no change, and no timestamp update define filechk + $(check-FORCE) $(Q)set -e; \ mkdir -p $(dir $@); \ trap "rm -f $(dot-target).tmp" EXIT; \@@ -130,7 +131,11 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) # PHONY targets skipped in both cases. newer-prereqs = $(filter-out $(PHONY),$?)
Quoted 4 lines
scripts/Kbuild.include make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) · line 134
Quoted 2 lines
scripts/Kbuild.include +1
-1-if-changed-cond = $(newer-prereqs)$(cmd-check) +# It is a typical mistake to forget the FORCE prerequisite. Check it here soprerequsite -> prerequisite?
Thanks for catching it.
Applied with the typo fixed.
Quoted 15 lines
Successfully found the missing FORCE in
arch/x86/entry/vdso/Makefile:135.Tested-by Nicolas Schier <[email protected]>Quoted 10 lines
scripts/Kbuild.include +4
-1+# no more breakage will slip in. +check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequsite is missing)) + +if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE) # Execute command if command has changed or prerequisite(s) are updated. if_changed = $(if $(if-changed-cond), \ --2.30.2
Signature · 2 lines
Best Regards Masahiro Yamada