2019-05-30 20:03:44 +08:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2005-07-26 04:10:36 +08:00
|
|
|
####
|
|
|
|
# kbuild: Generic definitions
|
|
|
|
|
2007-02-09 05:48:51 +08:00
|
|
|
# Convenient variables
|
2005-07-26 04:10:36 +08:00
|
|
|
comma := ,
|
2014-03-20 10:08:20 +08:00
|
|
|
quote := "
|
2006-01-07 05:35:59 +08:00
|
|
|
squote := '
|
2005-07-26 04:10:36 +08:00
|
|
|
empty :=
|
|
|
|
space := $(empty) $(empty)
|
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: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-05-07 14:48:26 +08:00
|
|
|
space_escape := _-_SPACE_-_
|
Kbuild: fix # escaping in .cmd files for future Make
I tried building using a freshly built Make (4.2.1-69-g8a731d1), but
already the objtool build broke with
orc_dump.c: In function ‘orc_dump’:
orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]
if (elf_getshdrnum(elf, &nr_sections)) {
Turns out that with that new Make, the backslash was not removed, so cpp
didn't see a #include directive, grep found nothing, and
-DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS.
Now, that new Make behaviour is documented in their NEWS file:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation
no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
C := \#
foo := $(shell echo '$C')
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
This also fixes up the two make-cmd instances to replace # with $(pound)
rather than with \#. There might very well be other places that need
similar fixup in preparation for whatever future Make release contains
the above change, but at least this builds an x86_64 defconfig with the
new make.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-04-09 05:35:28 +08:00
|
|
|
pound := \#
|
2005-07-26 04:10:36 +08:00
|
|
|
|
2006-07-24 01:37:44 +08:00
|
|
|
###
|
|
|
|
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
|
|
|
|
dot-target = $(dir $@).$(notdir $@)
|
|
|
|
|
2022-05-27 18:01:49 +08:00
|
|
|
###
|
|
|
|
# Name of target with a '.tmp_' as filename prefix. foo/bar.o => foo/.tmp_bar.o
|
|
|
|
tmp-target = $(dir $@).tmp_$(notdir $@)
|
|
|
|
|
2005-07-26 04:10:36 +08:00
|
|
|
###
|
2020-04-23 22:23:53 +08:00
|
|
|
# The temporary file to save gcc -MMD generated dependencies must not
|
2005-07-26 04:10:36 +08:00
|
|
|
# contain a comma
|
2006-07-24 01:37:44 +08:00
|
|
|
depfile = $(subst $(comma),_,$(dot-target).d)
|
2005-07-26 04:10:36 +08:00
|
|
|
|
2006-07-01 15:58:02 +08:00
|
|
|
###
|
|
|
|
# filename of target with directory and extension stripped
|
|
|
|
basetarget = $(basename $(notdir $@))
|
|
|
|
|
2019-01-17 18:02:43 +08:00
|
|
|
###
|
|
|
|
# real prerequisites without phony targets
|
|
|
|
real-prereqs = $(filter-out $(PHONY), $^)
|
|
|
|
|
2006-01-07 05:35:59 +08:00
|
|
|
###
|
|
|
|
# Escape single quote for use in echo statements
|
|
|
|
escsq = $(subst $(squote),'\$(squote)',$1)
|
|
|
|
|
2019-12-19 16:33:27 +08:00
|
|
|
###
|
|
|
|
# Quote a string to pass it to C files. foo => '"foo"'
|
|
|
|
stringify = $(squote)$(quote)$1$(quote)$(squote)
|
|
|
|
|
2008-11-06 16:31:34 +08:00
|
|
|
###
|
|
|
|
# Easy method for doing a status message
|
|
|
|
kecho := :
|
|
|
|
quiet_kecho := echo
|
|
|
|
silent_kecho := :
|
|
|
|
kecho := $($(quiet)kecho)
|
|
|
|
|
2005-07-26 04:10:36 +08:00
|
|
|
###
|
|
|
|
# filechk is used to check if the content of a generated file is updated.
|
|
|
|
# Sample usage:
|
2019-01-03 09:16:54 +08:00
|
|
|
#
|
|
|
|
# filechk_sample = echo $(KERNELRELEASE)
|
|
|
|
# version.h: FORCE
|
2005-07-26 04:10:36 +08:00
|
|
|
# $(call filechk,sample)
|
2019-01-03 09:16:54 +08:00
|
|
|
#
|
2005-07-26 04:10:36 +08:00
|
|
|
# The rule defined shall write to stdout the content of the new file.
|
|
|
|
# The existing file will be compared with the new one.
|
|
|
|
# - If no file exist it is created
|
|
|
|
# - If the content differ the new file is used
|
|
|
|
# - If they are equal no change, and no timestamp update
|
|
|
|
define filechk
|
2021-08-13 14:30:05 +08:00
|
|
|
$(check-FORCE)
|
2020-01-10 13:02:24 +08:00
|
|
|
$(Q)set -e; \
|
|
|
|
mkdir -p $(dir $@); \
|
|
|
|
trap "rm -f $(dot-target).tmp" EXIT; \
|
|
|
|
{ $(filechk_$(1)); } > $(dot-target).tmp; \
|
|
|
|
if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \
|
|
|
|
$(kecho) ' UPD $@'; \
|
|
|
|
mv -f $(dot-target).tmp $@; \
|
2005-07-26 04:10:36 +08:00
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
2007-02-09 05:48:51 +08:00
|
|
|
###
|
2005-07-26 04:10:36 +08:00
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(build)=dir
|
2014-09-09 19:03:58 +08:00
|
|
|
build := -f $(srctree)/scripts/Makefile.build obj
|
2005-07-26 04:10:36 +08:00
|
|
|
|
2014-09-03 21:29:24 +08:00
|
|
|
###
|
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(dtbinst)=dir
|
2018-09-12 12:52:54 +08:00
|
|
|
dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
|
2014-09-03 21:29:24 +08:00
|
|
|
|
2014-11-26 18:31:13 +08:00
|
|
|
###
|
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(clean)=dir
|
|
|
|
clean := -f $(srctree)/scripts/Makefile.clean obj
|
|
|
|
|
2007-02-06 09:18:21 +08:00
|
|
|
# echo command.
|
|
|
|
# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
|
2007-02-08 06:04:35 +08:00
|
|
|
echo-cmd = $(if $($(quiet)cmd_$(1)),\
|
2007-02-06 09:18:21 +08:00
|
|
|
echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
|
|
|
|
|
kbuild: sink stdout from cmd for silent build
When building with 'make -s', no output to stdout should be printed.
As Arnd Bergmann reported [1], mkimage shows the detailed information
of the generated images.
I think this should be suppressed by the 'cmd' macro instead of by
individual scripts.
Insert 'exec >/dev/null;' in order to redirect stdout to /dev/null for
silent builds.
[Note about this implementation]
'exec >/dev/null;' may look somewhat tricky, but this has a reason.
Appending '>/dev/null' at the end of command line is a common way for
redirection, so I first tried this:
cmd = @set -e; $(echo-cmd) $(cmd_$(1)) >/dev/null
... but it would not work if $(cmd_$(1)) itself contains a redirection.
For example, cmd_wrap in scripts/Makefile.asm-generic redirects the
output from the 'echo' command into the target file.
It would be expanded into:
echo "#include <asm-generic/$*.h>" > $@ >/dev/null
Then, the target file gets empty because the string will go to /dev/null
instead of $@.
Next, I tried this:
cmd = @set -e; $(echo-cmd) { $(cmd_$(1)); } >/dev/null
The form above would be expanded into:
{ echo "#include <asm-generic/$*.h>" > $@; } >/dev/null
This works as expected. However, it would be a syntax error if
$(cmd_$(1)) is empty.
When CONFIG_TRIM_UNUSED_KSYMS is disabled, $(call cmd,gen_ksymdeps) in
scripts/Makefile.build would be expanded into:
set -e; { ; } >/dev/null
..., which causes an syntax error.
I also tried this:
cmd = @set -e; $(echo-cmd) ( $(cmd_$(1)) ) >/dev/null
... but this causes a syntax error for the same reason.
So, finally I adopted:
cmd = @set -e; $(echo-cmd) exec >/dev/null; $(cmd_$(1))
[1]: https://lore.kernel.org/lkml/20210514135752.2910387-1-arnd@kernel.org/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-05-17 15:03:13 +08:00
|
|
|
# sink stdout for 'make -s'
|
|
|
|
redirect :=
|
|
|
|
quiet_redirect :=
|
|
|
|
silent_redirect := exec >/dev/null;
|
|
|
|
|
2007-02-06 09:18:21 +08:00
|
|
|
# printing commands
|
kbuild: sink stdout from cmd for silent build
When building with 'make -s', no output to stdout should be printed.
As Arnd Bergmann reported [1], mkimage shows the detailed information
of the generated images.
I think this should be suppressed by the 'cmd' macro instead of by
individual scripts.
Insert 'exec >/dev/null;' in order to redirect stdout to /dev/null for
silent builds.
[Note about this implementation]
'exec >/dev/null;' may look somewhat tricky, but this has a reason.
Appending '>/dev/null' at the end of command line is a common way for
redirection, so I first tried this:
cmd = @set -e; $(echo-cmd) $(cmd_$(1)) >/dev/null
... but it would not work if $(cmd_$(1)) itself contains a redirection.
For example, cmd_wrap in scripts/Makefile.asm-generic redirects the
output from the 'echo' command into the target file.
It would be expanded into:
echo "#include <asm-generic/$*.h>" > $@ >/dev/null
Then, the target file gets empty because the string will go to /dev/null
instead of $@.
Next, I tried this:
cmd = @set -e; $(echo-cmd) { $(cmd_$(1)); } >/dev/null
The form above would be expanded into:
{ echo "#include <asm-generic/$*.h>" > $@; } >/dev/null
This works as expected. However, it would be a syntax error if
$(cmd_$(1)) is empty.
When CONFIG_TRIM_UNUSED_KSYMS is disabled, $(call cmd,gen_ksymdeps) in
scripts/Makefile.build would be expanded into:
set -e; { ; } >/dev/null
..., which causes an syntax error.
I also tried this:
cmd = @set -e; $(echo-cmd) ( $(cmd_$(1)) ) >/dev/null
... but this causes a syntax error for the same reason.
So, finally I adopted:
cmd = @set -e; $(echo-cmd) exec >/dev/null; $(cmd_$(1))
[1]: https://lore.kernel.org/lkml/20210514135752.2910387-1-arnd@kernel.org/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-05-17 15:03:13 +08:00
|
|
|
cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(cmd_$(1))
|
2005-07-26 04:10:36 +08:00
|
|
|
|
|
|
|
###
|
2007-02-06 09:18:21 +08:00
|
|
|
# if_changed - execute command if any prerequisite is newer than
|
2005-07-26 04:10:36 +08:00
|
|
|
# target, or command line has changed
|
|
|
|
# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies
|
|
|
|
# including used config symbols
|
|
|
|
# if_changed_rule - as if_changed but execute rule instead
|
2019-06-13 01:52:48 +08:00
|
|
|
# See Documentation/kbuild/makefiles.rst for more info
|
2005-07-26 04:10:36 +08:00
|
|
|
|
|
|
|
ifneq ($(KBUILD_NOCMDDEP),1)
|
2019-06-23 00:07:03 +08:00
|
|
|
# Check if both commands are the same including their order. Result is empty
|
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: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-05-07 14:48:26 +08:00
|
|
|
# string if equal. User may override this check using make KBUILD_NOCMDDEP=1
|
2019-06-23 00:07:03 +08:00
|
|
|
cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \
|
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: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-05-07 14:48:26 +08:00
|
|
|
$(subst $(space),$(space_escape),$(strip $(cmd_$1))))
|
2011-05-16 22:37:34 +08:00
|
|
|
else
|
2019-06-23 00:07:03 +08:00
|
|
|
cmd-check = $(if $(strip $(cmd_$@)),,1)
|
2005-07-26 04:10:36 +08:00
|
|
|
endif
|
|
|
|
|
2014-08-08 03:39:57 +08:00
|
|
|
# Replace >$< with >$$< to preserve $ when reloading the .cmd file
|
|
|
|
# (needed for make)
|
Kbuild: fix # escaping in .cmd files for future Make
I tried building using a freshly built Make (4.2.1-69-g8a731d1), but
already the objtool build broke with
orc_dump.c: In function ‘orc_dump’:
orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]
if (elf_getshdrnum(elf, &nr_sections)) {
Turns out that with that new Make, the backslash was not removed, so cpp
didn't see a #include directive, grep found nothing, and
-DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS.
Now, that new Make behaviour is documented in their NEWS file:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation
no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
C := \#
foo := $(shell echo '$C')
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
This also fixes up the two make-cmd instances to replace # with $(pound)
rather than with \#. There might very well be other places that need
similar fixup in preparation for whatever future Make release contains
the above change, but at least this builds an x86_64 defconfig with the
new make.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-04-09 05:35:28 +08:00
|
|
|
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
|
2014-08-08 03:39:57 +08:00
|
|
|
# (needed for make)
|
|
|
|
# Replace >'< with >'\''< to be able to enclose the whole string in '...'
|
|
|
|
# (needed for the shell)
|
Kbuild: fix # escaping in .cmd files for future Make
I tried building using a freshly built Make (4.2.1-69-g8a731d1), but
already the objtool build broke with
orc_dump.c: In function ‘orc_dump’:
orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]
if (elf_getshdrnum(elf, &nr_sections)) {
Turns out that with that new Make, the backslash was not removed, so cpp
didn't see a #include directive, grep found nothing, and
-DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS.
Now, that new Make behaviour is documented in their NEWS file:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation
no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
C := \#
foo := $(shell echo '$C')
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
This also fixes up the two make-cmd instances to replace # with $(pound)
rather than with \#. There might very well be other places that need
similar fixup in preparation for whatever future Make release contains
the above change, but at least this builds an x86_64 defconfig with the
new make.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-04-09 05:35:28 +08:00
|
|
|
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
|
2006-01-30 17:04:27 +08:00
|
|
|
|
kbuild: drop $(wildcard $^) check in if_changed* for faster rebuild
The incremental build of Linux kernel is pretty slow when lots of
objects are compiled. The rebuild of allmodconfig may take a few
minutes even when none of the objects needs to be rebuilt.
The time-consuming part in the incremental build is the evaluation of
if_changed* macros since they are used in the recipes to compile C and
assembly source files into objects.
I notice the following code in if_changed* is expensive:
$(filter-out $(PHONY) $(wildcard $^),$^)
In the incremental build, every object has its .*.cmd file, which
contains the auto-generated list of included headers. So, $^ are
expanded into the long list of the source file + included headers,
and $(wildcard $^) checks whether they exist.
It may not be clear why this check exists there.
Here is the record of my research.
[1] The first code addition into Kbuild
This code dates back to 2002. It is the pre-git era. So, I copy-pasted
it from the historical git tree.
| commit 4a6db0791528c220655b063cf13fefc8470dbfee (HEAD)
| Author: Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
| Date: Mon Jun 17 00:22:37 2002 -0500
|
| kbuild: Handle removed headers
|
| New and old way to handle dependencies would choke when a file
| #include'd by other files was removed, since the dependency on it was
| still recorded, but since it was gone, make has no idea what to do about
| it (and would complain with "No rule to make <file> ...")
|
| We now add targets for all the previously included files, so make will
| just ignore them if they disappear.
|
| diff --git a/Rules.make b/Rules.make
| index 6ef827d3df39..7db5301ea7db 100644
| --- a/Rules.make
| +++ b/Rules.make
| @@ -446,7 +446,7 @@ if_changed = $(if $(strip $? \
| # execute the command and also postprocess generated .d dependencies
| # file
|
| -if_changed_dep = $(if $(strip $? \
| +if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
| $(filter-out $(cmd_$(1)),$(cmd_$@))\
| $(filter-out $(cmd_$@),$(cmd_$(1)))),\
| @set -e; \
| diff --git a/scripts/fixdep.c b/scripts/fixdep.c
| index b5d7bee8efc7..db45bd1888c0 100644
| --- a/scripts/fixdep.c
| +++ b/scripts/fixdep.c
| @@ -292,7 +292,7 @@ void parse_dep_file(void *map, size_t len)
| exit(1);
| }
| memcpy(s, m, p-m); s[p-m] = 0;
| - printf("%s: \\\n", target);
| + printf("deps_%s := \\\n", target);
| m = p+1;
|
| clear_config();
| @@ -314,7 +314,8 @@ void parse_dep_file(void *map, size_t len)
| }
| m = p + 1;
| }
| - printf("\n");
| + printf("\n%s: $(deps_%s)\n\n", target, target);
| + printf("$(deps_%s):\n", target);
| }
|
| void print_deps(void)
The "No rule to make <file> ..." error can be solved by passing -MP to
the compiler, but I think the detection of header removal is a good
feature. When a header is removed, all source files that previously
included it should be re-compiled. This makes sure we has correctly
got rid of #include directives of it.
This is also related with the behavior of $?. The GNU Make manual says:
$?
The names of all the prerequisites that are newer than the target,
with spaces between them.
This does not explain whether a non-existent prerequisite is considered
to be newer than the target.
At this point of time, GNU Make 3.7x was used, where the $? did not
include non-existent prerequisites. Therefore,
$(filter-out FORCE $(wildcard $^),$^)
was useful to detect the header removal, and to rebuild the related
objects if it is the case.
[2] Change of $? behavior
Later, the behavior of $? was changed (fixed) to include prerequisites
that did not exist.
First, GNU Make commit 64e16d6c00a5 ("Various changes getting ready for
the release of 3.81.") changed it, but in the release test of 3.81, it
turned out to break the kernel build.
See these:
- http://lists.gnu.org/archive/html/bug-make/2006-03/msg00003.html
- https://savannah.gnu.org/bugs/?16002
- https://savannah.gnu.org/bugs/?16051
Then, GNU Make commit 6d8d9b74d9c5 ("Numerous updates to tests for
issues found on Cygwin and Windows.") reverted it for the 3.81 release
to give Linux kernel time to adjust to the new behavior.
After the 3.81 release, GNU Make commit 7595f38f62af ("Fixed a number
of documentation bugs, plus some build/install issues:") re-added it.
[3] Adjustment to the new $? behavior on Kbuild side
Meanwhile, the kernel build was changed by commit 4f1933620f57 ("kbuild:
change kbuild to not rely on incorrect GNU make behavior") to adjust to
the new $? behavior.
[4] GNU Make 3.82 released in 2010
GNU Make 3.82 was the first release that integrated the correct $?
behavior. At this point, Kbuild dealt with GNU Make versions with
different $? behaviors.
3.81 or older:
$? does not contain any non-existent prerequisite.
$(filter-out $(PHONY) $(wildcard $^),$^) was useful to detect
removed include headers.
3.82 or newer:
$? contains non-existent prerequisites. When a header is removed,
it appears in $?. $(filter-out $(PHONY) $(wildcard $^),$^) became
a redundant check.
With the correct $? behavior, we could have dropped the expensive
check for 3.82 or later, but we did not. (Maybe nobody noticed this
optimization.)
[5] The .SECONDARY special target trips up $?
Some time later, I noticed $? did not work as expected under some
circumstances. As above, $? should contain non-existent prerequisites,
but the ones specified as SECONDARY do not appear in $?.
I asked this in GNU Make ML, and it seems a bug:
https://lists.gnu.org/archive/html/bug-make/2019-01/msg00001.html
Since commit 8e9b61b293d9 ("kbuild: move .SECONDARY special target to
Kbuild.include"), all files, including headers listed in .*.cmd files,
are treated as secondary.
So, we are back into the incorrect $? behavior.
If we Kbuild want to react to the header removal, we need to keep
$(filter-out $(PHONY) $(wildcard $^),$^) but this makes the rebuild
so slow.
[Summary]
- I believe noticing the header removal and recompiling related objects
is a nice feature for the build system.
- If $? worked correctly, $(filter-out $(PHONY),$?) would be enough
to detect the header removal.
- Currently, $? does not work correctly when used with .SECONDARY,
and Kbuild is hit by this bug.
- I filed a bug report for this, but not fixed yet as of writing.
- Currently, the header removal is detected by the following expensive
code:
$(filter-out $(PHONY) $(wildcard $^),$^)
- I do not want to revert commit 8e9b61b293d9 ("kbuild: move
.SECONDARY special target to Kbuild.include"). Specifying
.SECONDARY globally is clean, and it matches to the Kbuild policy.
This commit proactively removes the expensive check since it makes the
incremental build faster. A downside is Kbuild will no longer be able
to notice the header removal.
You can confirm it by the full-build followed by a header removal, and
then re-build.
$ make defconfig all
[ full build ]
$ rm include/linux/device.h
$ make
CALL scripts/checksyscalls.sh
CALL scripts/atomic/check-atomics.sh
DESCEND objtool
CHK include/generated/compile.h
Kernel: arch/x86/boot/bzImage is ready (#11)
Building modules, stage 2.
MODPOST 12 modules
Previously, Kbuild noticed a missing header and emits a build error.
Now, Kbuild is fine with it. This is an unusual corner-case, not a big
deal. Once the $? bug is fixed in GNU Make, everything will work fine.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2019-11-07 23:09:44 +08:00
|
|
|
# Find any prerequisites that are newer than target or that do not exist.
|
|
|
|
# (This is not true for now; $? should contain any non-existent prerequisites,
|
|
|
|
# but it does not work as expected when .SECONDARY is present. This seems a bug
|
|
|
|
# of GNU Make.)
|
2006-07-24 01:37:44 +08:00
|
|
|
# PHONY targets skipped in both cases.
|
2019-11-07 23:09:45 +08:00
|
|
|
newer-prereqs = $(filter-out $(PHONY),$?)
|
2006-07-24 01:37:44 +08:00
|
|
|
|
2021-08-13 14:30:05 +08:00
|
|
|
# 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 prerequisite is missing))
|
|
|
|
|
|
|
|
if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE)
|
2021-08-13 14:30:04 +08:00
|
|
|
|
2007-02-06 09:18:21 +08:00
|
|
|
# Execute command if command has changed or prerequisite(s) are updated.
|
2022-05-27 18:01:54 +08:00
|
|
|
if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:)
|
|
|
|
|
|
|
|
cmd_and_savecmd = \
|
2018-11-30 09:05:29 +08:00
|
|
|
$(cmd); \
|
2022-05-27 18:01:54 +08:00
|
|
|
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd
|
2005-07-26 04:10:36 +08:00
|
|
|
|
2007-02-06 09:18:21 +08:00
|
|
|
# Execute the command and also postprocess generated .d dependencies file.
|
2021-08-13 14:30:04 +08:00
|
|
|
if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
|
kbuild: add fine grained build dependencies for exported symbols
Like with kconfig options, we now have the ability to compile in and
out individual EXPORT_SYMBOL() declarations based on the content of
include/generated/autoksyms.h. However we don't want the entire
world to be rebuilt whenever that file is touched.
Let's apply the same build dependency trick used for CONFIG_* symbols
where the time stamp of empty files whose paths matching those symbols
is used to trigger fine grained rebuilds. In our case the key is the
symbol name passed to EXPORT_SYMBOL().
However, unlike config options, we cannot just use fixdep to parse
the source code for EXPORT_SYMBOL(ksym) because several variants exist
and parsing them all in a separate tool, and keeping it in synch, is
not trivially maintainable. Furthermore, there are variants such as
EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
that are instanciated via a macro for which we can't easily determine
the actual exported symbol name(s) short of actually running the
preprocessor on them.
Storing the symbol name string in a special ELF section doesn't work
for targets that output assembly or preprocessed source.
So the best way is really to leverage the preprocessor by having it
output actual symbol names anchored by a special sequence that can be
easily filtered out. Then the list of symbols is simply fed to fixdep
to be merged with the other dependencies.
That implies the preprocessor is executed twice for each source file.
A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
instance that was filtered apart from stderr by the build system with
a sed script during the actual compilation pass. Unfortunately the
preprocessor/compiler diagnostic output isn't stable between versions
and this solution, although more efficient, was deemed too fragile.
Because of the lowercasing performed by fixdep, there might be name
collisions triggering spurious rebuilds for similar symbols. But this
shouldn't be a big issue in practice. (This is the case for CONFIG_*
symbols and I didn't want to be different here, whatever the original
reason for doing so.)
To avoid needless build overhead, the exported symbol name gathering is
performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-23 02:41:57 +08:00
|
|
|
|
2016-02-18 04:50:06 +08:00
|
|
|
cmd_and_fixdep = \
|
2018-11-30 09:05:27 +08:00
|
|
|
$(cmd); \
|
kbuild: let fixdep directly write to .*.cmd files
Currently, fixdep writes dependencies to .*.tmp, which is renamed to
.*.cmd after everything succeeds. This is a very safe way to avoid
corrupted .*.cmd files. The if_changed_dep has carried this safety
mechanism since it was added in 2002.
If fixdep fails for some reasons or a user terminates the build while
fixdep is running, the incomplete output from the fixdep could be
troublesome.
This is my insight about some bad scenarios:
[1] If the compiler succeeds to generate *.o file, but fixdep fails
to write necessary dependencies to .*.cmd file, Make will miss
to rebuild the object when headers or CONFIG options are changed.
In this case, fixdep should not generate .*.cmd file at all so
that 'arg-check' will surely trigger the rebuild of the object.
[2] A partially constructed .*.cmd file may not be a syntactically
correct makefile. The next time Make runs, it would include it,
then fail to parse it. Once this happens, 'make clean' is be the
only way to fix it.
In fact, [1] is no longer a problem since commit 9c2af1c7377a ("kbuild:
add .DELETE_ON_ERROR special target"). Make deletes a target file on
any failure in its recipe. Because fixdep is a part of the recipe of
*.o target, if it fails, the *.o is deleted anyway. However, I am a
bit worried about the slight possibility of [2].
So, here is a solution. Let fixdep directly write to a .*.cmd file,
but allow makefiles to include it only when its corresponding target
exists.
This effectively reverts commit 2982c953570b ("kbuild: remove redundant
$(wildcard ...) for cmd_files calculation"), and commit 00d78ab2ba75
("kbuild: remove dead code in cmd_files calculation in top Makefile")
because now we must check the presence of targets.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-30 09:05:22 +08:00
|
|
|
scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
|
2018-11-30 09:05:28 +08:00
|
|
|
rm -f $(depfile)
|
kbuild: add fine grained build dependencies for exported symbols
Like with kconfig options, we now have the ability to compile in and
out individual EXPORT_SYMBOL() declarations based on the content of
include/generated/autoksyms.h. However we don't want the entire
world to be rebuilt whenever that file is touched.
Let's apply the same build dependency trick used for CONFIG_* symbols
where the time stamp of empty files whose paths matching those symbols
is used to trigger fine grained rebuilds. In our case the key is the
symbol name passed to EXPORT_SYMBOL().
However, unlike config options, we cannot just use fixdep to parse
the source code for EXPORT_SYMBOL(ksym) because several variants exist
and parsing them all in a separate tool, and keeping it in synch, is
not trivially maintainable. Furthermore, there are variants such as
EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
that are instanciated via a macro for which we can't easily determine
the actual exported symbol name(s) short of actually running the
preprocessor on them.
Storing the symbol name string in a special ELF section doesn't work
for targets that output assembly or preprocessed source.
So the best way is really to leverage the preprocessor by having it
output actual symbol names anchored by a special sequence that can be
easily filtered out. Then the list of symbols is simply fed to fixdep
to be merged with the other dependencies.
That implies the preprocessor is executed twice for each source file.
A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
instance that was filtered apart from stderr by the build system with
a sed script during the actual compilation pass. Unfortunately the
preprocessor/compiler diagnostic output isn't stable between versions
and this solution, although more efficient, was deemed too fragile.
Because of the lowercasing performed by fixdep, there might be name
collisions triggering spurious rebuilds for similar symbols. But this
shouldn't be a big issue in practice. (This is the case for CONFIG_*
symbols and I didn't want to be different here, whatever the original
reason for doing so.)
To avoid needless build overhead, the exported symbol name gathering is
performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-23 02:41:57 +08:00
|
|
|
|
2005-07-26 04:10:36 +08:00
|
|
|
# Usage: $(call if_changed_rule,foo)
|
2007-02-09 05:48:51 +08:00
|
|
|
# Will check if $(cmd_foo) or any of the prerequisites changed,
|
|
|
|
# and if so will execute $(rule_foo).
|
2021-08-13 14:30:04 +08:00
|
|
|
if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:)
|
2006-07-24 01:37:44 +08:00
|
|
|
|
2006-08-09 03:35:14 +08:00
|
|
|
###
|
2017-08-02 10:31:06 +08:00
|
|
|
# why - tell why a target got built
|
2006-08-09 03:35:14 +08:00
|
|
|
# enabled by make V=2
|
|
|
|
# Output (listed in the order they are checked):
|
|
|
|
# (1) - due to target is PHONY
|
|
|
|
# (2) - due to target missing
|
|
|
|
# (3) - due to: file1.h file2.h
|
|
|
|
# (4) - due to command line change
|
|
|
|
# (5) - due to missing .cmd file
|
|
|
|
# (6) - due to target not in $(targets)
|
|
|
|
# (1) PHONY targets are always build
|
|
|
|
# (2) No target, so we better build it
|
|
|
|
# (3) Prerequisite is newer than target
|
|
|
|
# (4) The command line stored in the file named dir/.target.cmd
|
|
|
|
# differed from actual command line. This happens when compiler
|
|
|
|
# options changes
|
|
|
|
# (5) No dir/.target.cmd file (used to store command line)
|
|
|
|
# (6) No dir/.target.cmd file and target not listed in $(targets)
|
|
|
|
# This is a good hint that there is a bug in the kbuild file
|
|
|
|
ifeq ($(KBUILD_VERBOSE),2)
|
|
|
|
why = \
|
|
|
|
$(if $(filter $@, $(PHONY)),- due to target is PHONY, \
|
|
|
|
$(if $(wildcard $@), \
|
2019-11-07 23:09:45 +08:00
|
|
|
$(if $(newer-prereqs),- due to: $(newer-prereqs), \
|
2019-06-23 00:07:03 +08:00
|
|
|
$(if $(cmd-check), \
|
2006-08-09 03:35:14 +08:00
|
|
|
$(if $(cmd_$@),- due to command line change, \
|
|
|
|
$(if $(filter $@, $(targets)), \
|
|
|
|
- due to missing .cmd file, \
|
|
|
|
- due to $(notdir $@) not in $$(targets) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
), \
|
|
|
|
- due to target missing \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
|
|
|
echo-why = $(call escsq, $(strip $(why)))
|
|
|
|
endif
|
2015-08-14 23:17:16 +08:00
|
|
|
|
|
|
|
###############################################################################
|
2018-07-20 15:46:33 +08:00
|
|
|
|
|
|
|
# delete partially updated (i.e. corrupted) files on error
|
|
|
|
.DELETE_ON_ERROR:
|
2018-12-01 08:27:15 +08:00
|
|
|
|
|
|
|
# do not delete intermediate files automatically
|
|
|
|
.SECONDARY:
|