Commit 9c8fa9bc authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Michal Marek

kbuild: fix if_change and friends to consider argument order

Currently, arg-check is implemented as follows:

  arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
                      $(filter-out $(cmd_$@),   $(cmd_$(1))) )

This does not care about the order of arguments that appear in
$(cmd_$(1)) and $(cmd_$@).  So, if_changed and friends never rebuild
the target if only the argument order is changed.  This is a problem
when the link order is changed.

Apparently,

  obj-y += foo.o
  obj-y += bar.o

and

  obj-y += bar.o
  obj-y += foo.o

should be distinguished because the link order determines the probe
order of drivers.  So, built-in.o should be rebuilt when the order
of objects is changed.

This commit fixes arg-check to compare the old/current commands
including the argument order.

Of course, this change has a side effect; Kbuild will react to the
change of compile option order.  For example, "-DFOO -DBAR" and
"-DBAR -DFOO" should give no difference to the build result, but
false positive should be better than false negative.

I am moving space_escape to the top of Kbuild.include just for a
matter of preference.  In practical terms, space_escape can be
defined after arg-check because arg-check uses "=" flavor, not ":=".
Having said that, collecting convenient variables in one place makes
sense from the point of readability.

Chaining "%%%SPACE%%%" to "_-_SPACE_-_" is also a matter of taste
at this point.  Actually, it can be arbitrary as long as it is an
unlikely used string.  The only problem I see in "%%%SPACE%%%" is
that "%" is a special character in "$(patsubst ...)" context.  This
commit just uses "$(subst ...)" for arg-check, but I am fixing it now
in case we might want to use it in $(patsubst ...) context in the
future.
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: default avatarMichal Marek <mmarek@suse.com>
parent a7c65b97
...@@ -7,6 +7,7 @@ quote := " ...@@ -7,6 +7,7 @@ quote := "
squote := ' squote := '
empty := empty :=
space := $(empty) $(empty) space := $(empty) $(empty)
space_escape := _-_SPACE_-_
### ###
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
...@@ -226,10 +227,10 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) ...@@ -226,10 +227,10 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
# See Documentation/kbuild/makefiles.txt for more info # See Documentation/kbuild/makefiles.txt for more info
ifneq ($(KBUILD_NOCMDDEP),1) ifneq ($(KBUILD_NOCMDDEP),1)
# Check if both arguments has same arguments. Result is empty string if equal. # Check if both arguments are the same including their order. Result is empty
# User may override this check using make KBUILD_NOCMDDEP=1 # string if equal. User may override this check using make KBUILD_NOCMDDEP=1
arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ arg-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \
$(filter-out $(cmd_$@), $(cmd_$(1))) ) $(subst $(space),$(space_escape),$(strip $(cmd_$1))))
else else
arg-check = $(if $(strip $(cmd_$@)),,1) arg-check = $(if $(strip $(cmd_$@)),,1)
endif endif
...@@ -373,8 +374,6 @@ endif ...@@ -373,8 +374,6 @@ endif
# #
############################################################################### ###############################################################################
# #
space_escape := %%%SPACE%%%
#
define config_filename define config_filename
ifneq ($$(CONFIG_$(1)),"") ifneq ($$(CONFIG_$(1)),"")
$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) $(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1)))))))
......
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