2019-05-30 12:03:44 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2005-07-25 20:10:36 +00:00
|
|
|
####
|
|
|
|
# kbuild: Generic definitions
|
|
|
|
|
2007-02-08 21:48:51 +00:00
|
|
|
# Convenient variables
|
2005-07-25 20:10:36 +00:00
|
|
|
comma := ,
|
2014-03-20 02:08:20 +00:00
|
|
|
quote := "
|
2006-01-06 21:35:59 +00:00
|
|
|
squote := '
|
2005-07-25 20:10:36 +00: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 06:48:26 +00: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-08 21:35:28 +00:00
|
|
|
pound := \#
|
2005-07-25 20:10:36 +00:00
|
|
|
|
2006-07-23 17:37:44 +00:00
|
|
|
###
|
|
|
|
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
|
|
|
|
dot-target = $(dir $@).$(notdir $@)
|
|
|
|
|
2005-07-25 20:10:36 +00:00
|
|
|
###
|
2020-04-23 14:23:53 +00:00
|
|
|
# The temporary file to save gcc -MMD generated dependencies must not
|
2005-07-25 20:10:36 +00:00
|
|
|
# contain a comma
|
2006-07-23 17:37:44 +00:00
|
|
|
depfile = $(subst $(comma),_,$(dot-target).d)
|
2005-07-25 20:10:36 +00:00
|
|
|
|
2006-07-01 07:58:02 +00:00
|
|
|
###
|
|
|
|
# filename of target with directory and extension stripped
|
|
|
|
basetarget = $(basename $(notdir $@))
|
|
|
|
|
2019-01-17 10:02:43 +00:00
|
|
|
###
|
|
|
|
# real prerequisites without phony targets
|
|
|
|
real-prereqs = $(filter-out $(PHONY), $^)
|
|
|
|
|
2006-01-06 21:35:59 +00:00
|
|
|
###
|
|
|
|
# Escape single quote for use in echo statements
|
|
|
|
escsq = $(subst $(squote),'\$(squote)',$1)
|
|
|
|
|
2019-12-19 08:33:27 +00:00
|
|
|
###
|
|
|
|
# Quote a string to pass it to C files. foo => '"foo"'
|
|
|
|
stringify = $(squote)$(quote)$1$(quote)$(squote)
|
|
|
|
|
2008-11-06 08:31:34 +00:00
|
|
|
###
|
|
|
|
# Easy method for doing a status message
|
|
|
|
kecho := :
|
|
|
|
quiet_kecho := echo
|
|
|
|
silent_kecho := :
|
|
|
|
kecho := $($(quiet)kecho)
|
|
|
|
|
2005-07-25 20:10:36 +00:00
|
|
|
###
|
|
|
|
# filechk is used to check if the content of a generated file is updated.
|
|
|
|
# Sample usage:
|
2019-01-03 01:16:54 +00:00
|
|
|
#
|
|
|
|
# filechk_sample = echo $(KERNELRELEASE)
|
|
|
|
# version.h: FORCE
|
2005-07-25 20:10:36 +00:00
|
|
|
# $(call filechk,sample)
|
2019-01-03 01:16:54 +00:00
|
|
|
#
|
2005-07-25 20:10:36 +00: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
|
2020-01-10 05:02:24 +00: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-25 20:10:36 +00:00
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
2007-02-08 21:48:51 +00:00
|
|
|
###
|
2005-07-25 20:10:36 +00:00
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(build)=dir
|
2014-09-09 11:03:58 +00:00
|
|
|
build := -f $(srctree)/scripts/Makefile.build obj
|
2005-07-25 20:10:36 +00:00
|
|
|
|
2014-09-03 13:29:24 +00:00
|
|
|
###
|
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(dtbinst)=dir
|
2018-09-12 04:52:54 +00:00
|
|
|
dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
|
2014-09-03 13:29:24 +00:00
|
|
|
|
2014-11-26 10:31:13 +00: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 01:18:21 +00:00
|
|
|
# echo command.
|
|
|
|
# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
|
2007-02-07 22:04:35 +00:00
|
|
|
echo-cmd = $(if $($(quiet)cmd_$(1)),\
|
2007-02-06 01:18:21 +00:00
|
|
|
echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
|
|
|
|
|
|
|
|
# printing commands
|
2018-11-30 01:05:27 +00:00
|
|
|
cmd = @set -e; $(echo-cmd) $(cmd_$(1))
|
2005-07-25 20:10:36 +00:00
|
|
|
|
|
|
|
###
|
2007-02-06 01:18:21 +00:00
|
|
|
# if_changed - execute command if any prerequisite is newer than
|
2005-07-25 20:10:36 +00: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-12 17:52:48 +00:00
|
|
|
# See Documentation/kbuild/makefiles.rst for more info
|
2005-07-25 20:10:36 +00:00
|
|
|
|
|
|
|
ifneq ($(KBUILD_NOCMDDEP),1)
|
2019-06-22 16:07:03 +00: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 06:48:26 +00:00
|
|
|
# string if equal. User may override this check using make KBUILD_NOCMDDEP=1
|
2019-06-22 16:07:03 +00: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 06:48:26 +00:00
|
|
|
$(subst $(space),$(space_escape),$(strip $(cmd_$1))))
|
2011-05-16 14:37:34 +00:00
|
|
|
else
|
2019-06-22 16:07:03 +00:00
|
|
|
cmd-check = $(if $(strip $(cmd_$@)),,1)
|
2005-07-25 20:10:36 +00:00
|
|
|
endif
|
|
|
|
|
2014-08-07 19:39:57 +00: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-08 21:35:28 +00:00
|
|
|
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
|
2014-08-07 19:39:57 +00: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-08 21:35:28 +00:00
|
|
|
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
|
2006-01-30 09:04:27 +00: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 15:09:44 +00: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-23 17:37:44 +00:00
|
|
|
# PHONY targets skipped in both cases.
|
2019-11-07 15:09:45 +00:00
|
|
|
newer-prereqs = $(filter-out $(PHONY),$?)
|
2006-07-23 17:37:44 +00:00
|
|
|
|
2007-02-06 01:18:21 +00:00
|
|
|
# Execute command if command has changed or prerequisite(s) are updated.
|
2019-11-07 15:09:45 +00:00
|
|
|
if_changed = $(if $(newer-prereqs)$(cmd-check), \
|
2018-11-30 01:05:29 +00:00
|
|
|
$(cmd); \
|
kbuild: suppress annoying "... is up to date." message
Under certain conditions, Kbuild shows "... is up to date" where
if_changed or friends are used.
For example, the incremental build of ARM64 Linux shows this message
when the kernel image has not been updated.
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
CHK kernel/config_data.h
make[1]: `arch/arm64/boot/Image.gz' is up to date.
Building modules, stage 2.
MODPOST 0 modules
The following is the build rule in arch/arm64/boot/Makefile:
$(obj)/Image.gz: $(obj)/Image FORCE
$(call if_changed,gzip)
If the Image.gz is newer than the Image and the command line has not
changed (i.e., $(any-prereq) and $(arg-check) are both empty), the
build rule $(call if_changed,gzip) is evaluated to be empty, then
GNU Make reports the target is up to date. In order to make GNU Make
quiet, we need to give it something to do, for example, "@:". This
should be fixed in the Kbuild core part rather than in each Makefile.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
2016-03-03 08:36:30 +00:00
|
|
|
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
|
2005-07-25 20:10:36 +00:00
|
|
|
|
2007-02-06 01:18:21 +00:00
|
|
|
# Execute the command and also postprocess generated .d dependencies file.
|
2019-11-07 15:09:45 +00:00
|
|
|
if_changed_dep = $(if $(newer-prereqs)$(cmd-check),$(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-22 18:41:57 +00:00
|
|
|
|
2016-02-17 20:50:06 +00:00
|
|
|
cmd_and_fixdep = \
|
2018-11-30 01:05:27 +00: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 01:05:22 +00:00
|
|
|
scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
|
2018-11-30 01:05:28 +00: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-22 18:41:57 +00:00
|
|
|
|
2005-07-25 20:10:36 +00:00
|
|
|
# Usage: $(call if_changed_rule,foo)
|
2007-02-08 21:48:51 +00:00
|
|
|
# Will check if $(cmd_foo) or any of the prerequisites changed,
|
|
|
|
# and if so will execute $(rule_foo).
|
2019-11-07 15:09:45 +00:00
|
|
|
if_changed_rule = $(if $(newer-prereqs)$(cmd-check),$(rule_$(1)),@:)
|
2006-07-23 17:37:44 +00:00
|
|
|
|
2006-08-08 19:35:14 +00:00
|
|
|
###
|
2017-08-02 02:31:06 +00:00
|
|
|
# why - tell why a target got built
|
2006-08-08 19:35:14 +00: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 15:09:45 +00:00
|
|
|
$(if $(newer-prereqs),- due to: $(newer-prereqs), \
|
2019-06-22 16:07:03 +00:00
|
|
|
$(if $(cmd-check), \
|
2006-08-08 19:35:14 +00: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 15:17:16 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# When a Kconfig string contains a filename, it is suitable for
|
|
|
|
# passing to shell commands. It is surrounded by double-quotes, and
|
|
|
|
# any double-quotes or backslashes within it are escaped by
|
|
|
|
# backslashes.
|
|
|
|
#
|
|
|
|
# This is no use for dependencies or $(wildcard). We need to strip the
|
|
|
|
# surrounding quotes and the escaping from quotes and backslashes, and
|
|
|
|
# we *do* need to escape any spaces in the string. So, for example:
|
|
|
|
#
|
|
|
|
# Usage: $(eval $(call config_filename,FOO))
|
|
|
|
#
|
|
|
|
# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option,
|
|
|
|
# transformed as described above to be suitable for use within the
|
|
|
|
# makefile.
|
|
|
|
#
|
|
|
|
# Also, if the filename is a relative filename and exists in the source
|
|
|
|
# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to
|
|
|
|
# be prefixed to *both* command invocation and dependencies.
|
|
|
|
#
|
|
|
|
# Note: We also print the filenames in the quiet_cmd_foo text, and
|
|
|
|
# perhaps ought to have a version specially escaped for that purpose.
|
|
|
|
# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good
|
|
|
|
# enough. It'll strip the quotes in the common case where there's no
|
|
|
|
# space and it's a simple filename, and it'll retain the quotes when
|
|
|
|
# there's a space. There are some esoteric cases in which it'll print
|
|
|
|
# the wrong thing, but we don't really care. The actual dependencies
|
|
|
|
# and commands *do* get it right, with various combinations of single
|
|
|
|
# and double quotes, backslashes and spaces in the filenames.
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
define config_filename
|
|
|
|
ifneq ($$(CONFIG_$(1)),"")
|
|
|
|
$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1)))))))
|
|
|
|
ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME)))
|
|
|
|
else
|
|
|
|
ifeq ($$(wildcard $$($(1)_FILENAME)),)
|
|
|
|
ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),)
|
|
|
|
$(1)_SRCPREFIX := $(srctree)/
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endef
|
|
|
|
#
|
|
|
|
###############################################################################
|
2018-07-20 07:46:33 +00:00
|
|
|
|
|
|
|
# delete partially updated (i.e. corrupted) files on error
|
|
|
|
.DELETE_ON_ERROR:
|
2018-12-01 00:27:15 +00:00
|
|
|
|
|
|
|
# do not delete intermediate files automatically
|
|
|
|
.SECONDARY:
|