2019-05-30 08:03:44 -04:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2005-07-25 16:10:36 -04:00
|
|
|
####
|
|
|
|
# kbuild: Generic definitions
|
|
|
|
|
2007-02-08 16:48:51 -05:00
|
|
|
# Convenient variables
|
2005-07-25 16:10:36 -04:00
|
|
|
comma := ,
|
2014-03-19 22:08:20 -04:00
|
|
|
quote := "
|
2006-01-06 16:35:59 -05:00
|
|
|
squote := '
|
2005-07-25 16:10:36 -04: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 02:48:26 -04: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 17:35:28 -04:00
|
|
|
pound := \#
|
2005-07-25 16:10:36 -04:00
|
|
|
|
2006-07-23 13:37:44 -04:00
|
|
|
###
|
|
|
|
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
|
|
|
|
dot-target = $(dir $@).$(notdir $@)
|
|
|
|
|
2005-07-25 16:10:36 -04:00
|
|
|
###
|
|
|
|
# The temporary file to save gcc -MD generated dependencies must not
|
|
|
|
# contain a comma
|
2006-07-23 13:37:44 -04:00
|
|
|
depfile = $(subst $(comma),_,$(dot-target).d)
|
2005-07-25 16:10:36 -04:00
|
|
|
|
2006-07-01 03:58:02 -04:00
|
|
|
###
|
|
|
|
# filename of target with directory and extension stripped
|
|
|
|
basetarget = $(basename $(notdir $@))
|
|
|
|
|
2019-01-17 05:02:43 -05:00
|
|
|
###
|
|
|
|
# real prerequisites without phony targets
|
|
|
|
real-prereqs = $(filter-out $(PHONY), $^)
|
|
|
|
|
2006-01-06 16:35:59 -05:00
|
|
|
###
|
|
|
|
# Escape single quote for use in echo statements
|
|
|
|
escsq = $(subst $(squote),'\$(squote)',$1)
|
|
|
|
|
2008-11-06 03:31:34 -05:00
|
|
|
###
|
|
|
|
# Easy method for doing a status message
|
|
|
|
kecho := :
|
|
|
|
quiet_kecho := echo
|
|
|
|
silent_kecho := :
|
|
|
|
kecho := $($(quiet)kecho)
|
|
|
|
|
2005-07-25 16:10:36 -04:00
|
|
|
###
|
|
|
|
# filechk is used to check if the content of a generated file is updated.
|
|
|
|
# Sample usage:
|
2019-01-02 20:16:54 -05:00
|
|
|
#
|
|
|
|
# filechk_sample = echo $(KERNELRELEASE)
|
|
|
|
# version.h: FORCE
|
2005-07-25 16:10:36 -04:00
|
|
|
# $(call filechk,sample)
|
2019-01-02 20:16:54 -05:00
|
|
|
#
|
2005-07-25 16:10:36 -04: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
|
|
|
|
# - stdin is piped in from the first prerequisite ($<) so one has
|
|
|
|
# to specify a valid file as first prerequisite (often the kbuild file)
|
|
|
|
define filechk
|
2020-01-10 00:02:24 -05: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 16:10:36 -04:00
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
2006-01-22 07:34:15 -05:00
|
|
|
######
|
2006-02-18 04:03:40 -05:00
|
|
|
# gcc support functions
|
2019-06-12 13:52:48 -04:00
|
|
|
# See documentation in Documentation/kbuild/makefiles.rst
|
2006-01-22 07:34:15 -05:00
|
|
|
|
2007-10-19 15:46:01 -04:00
|
|
|
# cc-cross-prefix
|
|
|
|
# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
|
2019-02-19 23:23:56 -05:00
|
|
|
# Return first <prefix> where a <prefix>gcc is found in PATH.
|
|
|
|
# If no gcc found in PATH with listed prefixes return nothing
|
kbuild: use more portable 'command -v' for cc-cross-prefix
To print the pathname that will be used by shell in the current
environment, 'command -v' is a standardized way. [1]
'which' is also often used in scripts, but it is less portable.
When I worked on commit bd55f96fa9fc ("kbuild: refactor cc-cross-prefix
implementation"), I was eager to use 'command -v' but it did not work.
(The reason is explained below.)
I kept 'which' as before but got rid of '> /dev/null 2>&1' as I
thought it was no longer needed. Sorry, I was wrong.
It works well on my Ubuntu machine, but Alexey Brodkin reports noisy
warnings on CentOS7 when 'which' fails to find the given command in
the PATH environment.
$ which foo
which: no foo in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
Given that behavior of 'which' depends on system (and it may not be
installed by default), I want to try 'command -v' once again.
The specification [1] clearly describes the behavior of 'command -v'
when the given command is not found:
Otherwise, no output shall be written and the exit status shall reflect
that the name was not found.
However, we need a little magic to use 'command -v' from Make.
$(shell ...) passes the argument to a subshell for execution, and
returns the standard output of the command.
Here is a trick. GNU Make may optimize this by executing the command
directly instead of forking a subshell, if no shell special characters
are found in the command and omitting the subshell will not change the
behavior.
In this case, no shell special character is used. So, Make will try
to run it directly. However, 'command' is a shell-builtin command,
then Make would fail to find it in the PATH environment:
$ make ARCH=m68k defconfig
make: command: Command not found
make: command: Command not found
make: command: Command not found
In fact, Make has a table of shell-builtin commands because it must
ask the shell to execute them.
Until recently, 'command' was missing in the table.
This issue was fixed by the following commit:
| commit 1af314465e5dfe3e8baa839a32a72e83c04f26ef
| Author: Paul Smith <psmith@gnu.org>
| Date: Sun Nov 12 18:10:28 2017 -0500
|
| * job.c: Add "command" as a known shell built-in.
|
| This is not a POSIX shell built-in but it's common in UNIX shells.
| Reported by Nick Bowler <nbowler@draconx.ca>.
Because the latest release is GNU Make 4.2.1 in 2016, this commit is
not included in any released versions. (But some distributions may
have back-ported it.)
We need to trick Make to spawn a subshell. There are various ways to
do so:
1) Use a shell special character '~' as dummy
$(shell : ~; command -v $(c)gcc)
2) Use a variable reference that always expands to the empty string
(suggested by David Laight)
$(shell command$${x:+} -v $(c)gcc)
3) Use redirect
$(shell command -v $(c)gcc 2>/dev/null)
I chose 3) to not confuse people. The stderr would not be polluted
anyway, but it will provide extra safety, and is easy to understand.
Tested on Make 3.81, 3.82, 4.0, 4.1, 4.2, 4.2.1
[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
Fixes: bd55f96fa9fc ("kbuild: refactor cc-cross-prefix implementation")
Cc: linux-stable <stable@vger.kernel.org> # 5.1
Reported-by: Alexey Brodkin <abrodkin@synopsys.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Tested-by: Alexey Brodkin <abrodkin@synopsys.com>
2019-06-06 00:13:58 -04:00
|
|
|
#
|
|
|
|
# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
|
|
|
|
# would try to directly execute the shell builtin 'command'. This workaround
|
|
|
|
# should be kept for a long time since this issue was fixed only after the
|
|
|
|
# GNU Make 4.2.1 release.
|
2019-07-09 02:13:00 -04:00
|
|
|
cc-cross-prefix = $(firstword $(foreach c, $(1), \
|
|
|
|
$(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
|
2007-10-19 15:46:01 -04:00
|
|
|
|
2007-02-08 16:48:51 -05:00
|
|
|
# output directory for tests below
|
2020-06-14 10:43:40 -04:00
|
|
|
TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
|
2007-02-08 16:48:51 -05:00
|
|
|
|
|
|
|
# try-run
|
|
|
|
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
|
2017-08-01 22:31:06 -04:00
|
|
|
# Exit code chooses option. "$$TMP" serves as a temporary file and is
|
|
|
|
# automatically cleaned up.
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
try-run = $(shell set -e; \
|
2020-06-14 10:43:40 -04:00
|
|
|
TMP=$(TMPOUT)/tmp; \
|
|
|
|
TMPO=$(TMPOUT)/tmp.o; \
|
|
|
|
mkdir -p $(TMPOUT); \
|
|
|
|
trap "rm -rf $(TMPOUT)" EXIT; \
|
2007-02-08 16:48:51 -05:00
|
|
|
if ($(1)) >/dev/null 2>&1; \
|
|
|
|
then echo "$(2)"; \
|
|
|
|
else echo "$(3)"; \
|
2020-06-14 10:43:40 -04:00
|
|
|
fi)
|
2006-12-10 05:18:41 -05:00
|
|
|
|
2006-01-22 07:34:15 -05:00
|
|
|
# as-option
|
2007-02-07 17:04:35 -05:00
|
|
|
# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
|
2007-02-08 16:48:51 -05:00
|
|
|
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
as-option = $(call try-run,\
|
2012-10-02 10:42:36 -04:00
|
|
|
$(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
|
2006-01-22 07:34:15 -05:00
|
|
|
|
2006-09-26 04:52:30 -04:00
|
|
|
# as-instr
|
2007-02-07 17:04:35 -05:00
|
|
|
# Usage: cflags-y += $(call as-instr,instr,option1,option2)
|
2007-02-08 16:48:51 -05:00
|
|
|
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
as-instr = $(call try-run,\
|
2012-10-02 10:42:36 -04:00
|
|
|
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
|
2006-09-26 04:52:30 -04:00
|
|
|
|
2017-06-21 19:28:03 -04:00
|
|
|
# __cc-option
|
|
|
|
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
__cc-option = $(call try-run,\
|
2017-06-21 19:28:03 -04:00
|
|
|
$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
|
|
|
|
|
2016-06-18 02:28:34 -04:00
|
|
|
# Do not attempt to build with gcc plugins during cc-option tests.
|
|
|
|
# (And this uses delayed resolution so the flags will be up to date.)
|
2018-12-19 05:27:05 -05:00
|
|
|
CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
|
2016-06-18 02:28:34 -04:00
|
|
|
|
2006-01-22 07:34:15 -05:00
|
|
|
# cc-option
|
2007-02-07 17:04:35 -05:00
|
|
|
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
|
2007-02-08 16:48:51 -05:00
|
|
|
|
2017-06-21 19:28:03 -04:00
|
|
|
cc-option = $(call __cc-option, $(CC),\
|
|
|
|
$(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
|
|
|
|
|
2006-01-22 07:34:15 -05:00
|
|
|
# cc-option-yn
|
2007-02-07 17:04:35 -05:00
|
|
|
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
cc-option-yn = $(call try-run,\
|
2017-03-31 16:38:13 -04:00
|
|
|
$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
|
2006-01-22 07:34:15 -05:00
|
|
|
|
2011-05-02 06:51:15 -04:00
|
|
|
# cc-disable-warning
|
|
|
|
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
cc-disable-warning = $(call try-run,\
|
2017-03-31 16:38:13 -04:00
|
|
|
$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
|
2011-05-02 06:51:15 -04:00
|
|
|
|
2006-01-22 07:34:15 -05:00
|
|
|
# cc-ifversion
|
|
|
|
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
|
2019-03-01 02:10:21 -05:00
|
|
|
cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
|
2006-01-22 07:34:15 -05:00
|
|
|
|
2009-09-19 04:31:45 -04:00
|
|
|
# ld-option
|
2018-08-23 19:20:39 -04:00
|
|
|
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
|
|
|
|
ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
|
2009-09-19 04:31:45 -04:00
|
|
|
|
2014-02-08 03:01:13 -05:00
|
|
|
# ld-version
|
|
|
|
# Note this is mainly for HJ Lu's 3 number binutil versions
|
kbuild: remove kbuild cache
The kbuild cache was introduced to remember the result of shell
commands, some of which are expensive to compute, such as
$(call cc-option,...).
However, this turned out not so clever as I had first expected.
Actually, it is problematic. For example, "$(CC) -print-file-name"
is cached. If the compiler is updated, the stale search path causes
build error, which is difficult to figure out. Another problem
scenario is cache files could be touched while install targets are
running under the root permission. We can patch them if desired,
but the build infrastructure is getting uglier and uglier.
Now, we are going to move compiler flag tests to the configuration
phase. If this is completed, the result of compiler tests will be
naturally cached in the .config file. We will not have performance
issues of incremental building since this testing only happens at
Kconfig time.
To start this work with a cleaner code base, remove the kbuild
cache first.
Revert the following commits:
Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary")
Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines")
Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler")
Commit 3298b690b21c ("kbuild: Add a cache for generated variables")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2018-05-28 05:21:38 -04:00
|
|
|
ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
|
2014-02-08 03:01:13 -05:00
|
|
|
|
|
|
|
# ld-ifversion
|
|
|
|
# Usage: $(call ld-ifversion, -ge, 22252, y)
|
2014-12-25 00:31:27 -05:00
|
|
|
ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
|
2014-02-08 03:01:13 -05:00
|
|
|
|
2007-02-05 20:18:21 -05:00
|
|
|
######
|
[PATCH] vDSO hash-style fix
The latest toolchains can produce a new ELF section in DSOs and
dynamically-linked executables. The new section ".gnu.hash" replaces
".hash", and allows for more efficient runtime symbol lookups by the
dynamic linker. The new ld option --hash-style={sysv|gnu|both} controls
whether to produce the old ".hash", the new ".gnu.hash", or both. In some
new systems such as Fedora Core 6, gcc by default passes --hash-style=gnu
to the linker, so that a standard invocation of "gcc -shared" results in
producing a DSO with only ".gnu.hash". The new ".gnu.hash" sections need
to be dealt with the same way as ".hash" sections in all respects; only the
dynamic linker cares about their contents. To work with older dynamic
linkers (i.e. preexisting releases of glibc), a binary must have the old
".hash" section. The --hash-style=both option produces binaries that a new
dynamic linker can use more efficiently, but an old dynamic linker can
still handle.
The new section runs afoul of the custom linker scripts used to build vDSO
images for the kernel. On ia64, the failure mode for this is a boot-time
panic because the vDSO's PT_IA_64_UNWIND segment winds up ill-formed.
This patch addresses the problem in two ways.
First, it mentions ".gnu.hash" in all the linker scripts alongside ".hash".
This produces correct vDSO images with --hash-style=sysv (or old tools),
with --hash-style=gnu, or with --hash-style=both.
Second, it passes the --hash-style=sysv option when building the vDSO
images, so that ".gnu.hash" is not actually produced. This is the most
conservative choice for compatibility with any old userland. There is some
concern that some ancient glibc builds (though not any known old production
system) might choke on --hash-style=both binaries. The optimizations
provided by the new style of hash section do not really matter for a DSO
with a tiny number of symbols, as the vDSO has. If someone wants to use
=gnu or =both for their vDSO builds and worry less about that
compatibility, just change the option and the linker script changes will
make any choice work fine.
Signed-off-by: Roland McGrath <roland@redhat.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Andi Kleen <ak@muc.de>
Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-07-30 06:04:06 -04:00
|
|
|
|
2007-02-08 16:48:51 -05:00
|
|
|
###
|
2005-07-25 16:10:36 -04:00
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(build)=dir
|
2014-09-09 07:03:58 -04:00
|
|
|
build := -f $(srctree)/scripts/Makefile.build obj
|
2005-07-25 16:10:36 -04:00
|
|
|
|
2009-12-07 10:38:33 -05:00
|
|
|
###
|
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(modbuiltin)=dir
|
2014-09-09 07:03:58 -04:00
|
|
|
modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj
|
2009-12-07 10:38:33 -05:00
|
|
|
|
2014-09-03 09:29:24 -04:00
|
|
|
###
|
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(dtbinst)=dir
|
2018-09-12 00:52:54 -04:00
|
|
|
dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
|
2014-09-03 09:29:24 -04:00
|
|
|
|
2014-11-26 05:31:13 -05:00
|
|
|
###
|
|
|
|
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
|
|
|
|
# Usage:
|
|
|
|
# $(Q)$(MAKE) $(clean)=dir
|
|
|
|
clean := -f $(srctree)/scripts/Makefile.clean obj
|
|
|
|
|
2007-02-05 20:18:21 -05:00
|
|
|
# echo command.
|
|
|
|
# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
|
2007-02-07 17:04:35 -05:00
|
|
|
echo-cmd = $(if $($(quiet)cmd_$(1)),\
|
2007-02-05 20:18:21 -05:00
|
|
|
echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
|
|
|
|
|
kbuild: sink stdout from cmd for silent build
[ Upstream commit 174a1dcc96429efce4ef7eb2f5c4506480da2182 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-05-17 03:03:13 -04:00
|
|
|
# sink stdout for 'make -s'
|
|
|
|
redirect :=
|
|
|
|
quiet_redirect :=
|
|
|
|
silent_redirect := exec >/dev/null;
|
|
|
|
|
kbuild: remove the target in signal traps when interrupted
[ Upstream commit a7f3257da8a86b96fb9bf1bba40ae0bbd7f1885a ]
When receiving some signal, GNU Make automatically deletes the target if
it has already been changed by the interrupted recipe.
If the target is possibly incomplete due to interruption, it must be
deleted so that it will be remade from scratch on the next run of make.
Otherwise, the target would remain corrupted permanently because its
timestamp had already been updated.
Thanks to this behavior of Make, you can stop the build any time by
pressing Ctrl-C, and just run 'make' to resume it.
Kbuild also relies on this feature, but it is equivalently important
for any build systems that make decisions based on timestamps (if you
want to support Ctrl-C reliably).
However, this does not always work as claimed; Make immediately dies
with Ctrl-C if its stderr goes into a pipe.
[Test Makefile]
foo:
echo hello > $@
sleep 3
echo world >> $@
[Test Result]
$ make # hit Ctrl-C
echo hello > foo
sleep 3
^Cmake: *** Deleting file 'foo'
make: *** [Makefile:3: foo] Interrupt
$ make 2>&1 | cat # hit Ctrl-C
echo hello > foo
sleep 3
^C$ # 'foo' is often left-over
The reason is because SIGINT is sent to the entire process group.
In this example, SIGINT kills 'cat', and 'make' writes the message to
the closed pipe, then dies with SIGPIPE before cleaning the target.
A typical bad scenario (as reported by [1], [2]) is to save build log
by using the 'tee' command:
$ make 2>&1 | tee log
This can be problematic for any build systems based on Make, so I hope
it will be fixed in GNU Make. The maintainer of GNU Make stated this is
a long-standing issue and difficult to fix [3]. It has not been fixed
yet as of writing.
So, we cannot rely on Make cleaning the target. We can do it by
ourselves, in signal traps.
As far as I understand, Make takes care of SIGHUP, SIGINT, SIGQUIT, and
SITERM for the target removal. I added the traps for them, and also for
SIGPIPE just in case cmd_* rule prints something to stdout or stderr
(but I did not observe an actual case where SIGPIPE was triggered).
[Note 1]
The trap handler might be worth explaining.
rm -f $@; trap - $(sig); kill -s $(sig) $$
This lets the shell kill itself by the signal it caught, so the parent
process can tell the child has exited on the signal. Generally, this is
a proper manner for handling signals, in case the calling program (like
Bash) may monitor WIFSIGNALED() and WTERMSIG() for WCE although this may
not be a big deal here because GNU Make handles SIGHUP, SIGINT, SIGQUIT
in WUE and SIGTERM in IUE.
IUE - Immediate Unconditional Exit
WUE - Wait and Unconditional Exit
WCE - Wait and Cooperative Exit
For details, see "Proper handling of SIGINT/SIGQUIT" [4].
[Note 2]
Reverting 392885ee82d3 ("kbuild: let fixdep directly write to .*.cmd
files") would directly address [1], but it only saves if_changed_dep.
As reported in [2], all commands that use redirection can potentially
leave an empty (i.e. broken) target.
[Note 3]
Another (even safer) approach might be to always write to a temporary
file, and rename it to $@ at the end of the recipe.
<command> > $(tmp-target)
mv $(tmp-target) $@
It would require a lot of Makefile changes, and result in ugly code,
so I did not take it.
[Note 4]
A little more thoughts about a pattern rule with multiple targets (or
a grouped target).
%.x %.y: %.z
<recipe>
When interrupted, GNU Make deletes both %.x and %.y, while this solution
only deletes $@. Probably, this is not a big deal. The next run of make
will execute the rule again to create $@ along with the other files.
[1]: https://lore.kernel.org/all/YLeot94yAaM4xbMY@gmail.com/
[2]: https://lore.kernel.org/all/20220510221333.2770571-1-robh@kernel.org/
[3]: https://lists.gnu.org/archive/html/help-make/2021-06/msg00001.html
[4]: https://www.cons.org/cracauer/sigint.html
Fixes: 392885ee82d3 ("kbuild: let fixdep directly write to .*.cmd files")
Reported-by: Ingo Molnar <mingo@kernel.org>
Reported-by: Rob Herring <robh@kernel.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-06 20:48:09 -04:00
|
|
|
# Delete the target on interruption
|
|
|
|
#
|
|
|
|
# GNU Make automatically deletes the target if it has already been changed by
|
|
|
|
# the interrupted recipe. So, you can safely stop the build by Ctrl-C (Make
|
|
|
|
# will delete incomplete targets), and resume it later.
|
|
|
|
#
|
|
|
|
# However, this does not work when the stderr is piped to another program, like
|
|
|
|
# $ make >&2 | tee log
|
|
|
|
# Make dies with SIGPIPE before cleaning the targets.
|
|
|
|
#
|
|
|
|
# To address it, we clean the target in signal traps.
|
|
|
|
#
|
|
|
|
# Make deletes the target when it catches SIGHUP, SIGINT, SIGQUIT, SIGTERM.
|
|
|
|
# So, we cover them, and also SIGPIPE just in case.
|
|
|
|
#
|
|
|
|
# Of course, this is unneeded for phony targets.
|
|
|
|
delete-on-interrupt = \
|
|
|
|
$(if $(filter-out $(PHONY), $@), \
|
|
|
|
$(foreach sig, HUP INT QUIT TERM PIPE, \
|
|
|
|
trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);))
|
|
|
|
|
2007-02-05 20:18:21 -05:00
|
|
|
# printing commands
|
kbuild: remove the target in signal traps when interrupted
[ Upstream commit a7f3257da8a86b96fb9bf1bba40ae0bbd7f1885a ]
When receiving some signal, GNU Make automatically deletes the target if
it has already been changed by the interrupted recipe.
If the target is possibly incomplete due to interruption, it must be
deleted so that it will be remade from scratch on the next run of make.
Otherwise, the target would remain corrupted permanently because its
timestamp had already been updated.
Thanks to this behavior of Make, you can stop the build any time by
pressing Ctrl-C, and just run 'make' to resume it.
Kbuild also relies on this feature, but it is equivalently important
for any build systems that make decisions based on timestamps (if you
want to support Ctrl-C reliably).
However, this does not always work as claimed; Make immediately dies
with Ctrl-C if its stderr goes into a pipe.
[Test Makefile]
foo:
echo hello > $@
sleep 3
echo world >> $@
[Test Result]
$ make # hit Ctrl-C
echo hello > foo
sleep 3
^Cmake: *** Deleting file 'foo'
make: *** [Makefile:3: foo] Interrupt
$ make 2>&1 | cat # hit Ctrl-C
echo hello > foo
sleep 3
^C$ # 'foo' is often left-over
The reason is because SIGINT is sent to the entire process group.
In this example, SIGINT kills 'cat', and 'make' writes the message to
the closed pipe, then dies with SIGPIPE before cleaning the target.
A typical bad scenario (as reported by [1], [2]) is to save build log
by using the 'tee' command:
$ make 2>&1 | tee log
This can be problematic for any build systems based on Make, so I hope
it will be fixed in GNU Make. The maintainer of GNU Make stated this is
a long-standing issue and difficult to fix [3]. It has not been fixed
yet as of writing.
So, we cannot rely on Make cleaning the target. We can do it by
ourselves, in signal traps.
As far as I understand, Make takes care of SIGHUP, SIGINT, SIGQUIT, and
SITERM for the target removal. I added the traps for them, and also for
SIGPIPE just in case cmd_* rule prints something to stdout or stderr
(but I did not observe an actual case where SIGPIPE was triggered).
[Note 1]
The trap handler might be worth explaining.
rm -f $@; trap - $(sig); kill -s $(sig) $$
This lets the shell kill itself by the signal it caught, so the parent
process can tell the child has exited on the signal. Generally, this is
a proper manner for handling signals, in case the calling program (like
Bash) may monitor WIFSIGNALED() and WTERMSIG() for WCE although this may
not be a big deal here because GNU Make handles SIGHUP, SIGINT, SIGQUIT
in WUE and SIGTERM in IUE.
IUE - Immediate Unconditional Exit
WUE - Wait and Unconditional Exit
WCE - Wait and Cooperative Exit
For details, see "Proper handling of SIGINT/SIGQUIT" [4].
[Note 2]
Reverting 392885ee82d3 ("kbuild: let fixdep directly write to .*.cmd
files") would directly address [1], but it only saves if_changed_dep.
As reported in [2], all commands that use redirection can potentially
leave an empty (i.e. broken) target.
[Note 3]
Another (even safer) approach might be to always write to a temporary
file, and rename it to $@ at the end of the recipe.
<command> > $(tmp-target)
mv $(tmp-target) $@
It would require a lot of Makefile changes, and result in ugly code,
so I did not take it.
[Note 4]
A little more thoughts about a pattern rule with multiple targets (or
a grouped target).
%.x %.y: %.z
<recipe>
When interrupted, GNU Make deletes both %.x and %.y, while this solution
only deletes $@. Probably, this is not a big deal. The next run of make
will execute the rule again to create $@ along with the other files.
[1]: https://lore.kernel.org/all/YLeot94yAaM4xbMY@gmail.com/
[2]: https://lore.kernel.org/all/20220510221333.2770571-1-robh@kernel.org/
[3]: https://lists.gnu.org/archive/html/help-make/2021-06/msg00001.html
[4]: https://www.cons.org/cracauer/sigint.html
Fixes: 392885ee82d3 ("kbuild: let fixdep directly write to .*.cmd files")
Reported-by: Ingo Molnar <mingo@kernel.org>
Reported-by: Rob Herring <robh@kernel.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-06 20:48:09 -04:00
|
|
|
cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(delete-on-interrupt) $(cmd_$(1))
|
2005-07-25 16:10:36 -04:00
|
|
|
|
|
|
|
###
|
2007-02-05 20:18:21 -05:00
|
|
|
# if_changed - execute command if any prerequisite is newer than
|
2005-07-25 16:10:36 -04: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 13:52:48 -04:00
|
|
|
# See Documentation/kbuild/makefiles.rst for more info
|
2005-07-25 16:10:36 -04:00
|
|
|
|
|
|
|
ifneq ($(KBUILD_NOCMDDEP),1)
|
2019-06-22 12:07:03 -04: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 02:48:26 -04:00
|
|
|
# string if equal. User may override this check using make KBUILD_NOCMDDEP=1
|
2019-06-22 12:07:03 -04: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 02:48:26 -04:00
|
|
|
$(subst $(space),$(space_escape),$(strip $(cmd_$1))))
|
2011-05-16 10:37:34 -04:00
|
|
|
else
|
2019-06-22 12:07:03 -04:00
|
|
|
cmd-check = $(if $(strip $(cmd_$@)),,1)
|
2005-07-25 16:10:36 -04:00
|
|
|
endif
|
|
|
|
|
2014-08-07 15:39:57 -04: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 17:35:28 -04:00
|
|
|
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
|
2014-08-07 15:39:57 -04: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 17:35:28 -04:00
|
|
|
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
|
2006-01-30 04:04:27 -05:00
|
|
|
|
2006-07-23 13:37:44 -04:00
|
|
|
# Find any prerequisites that is newer than target or that does not exist.
|
|
|
|
# PHONY targets skipped in both cases.
|
2019-06-22 12:07:04 -04:00
|
|
|
any-prereq = $(filter-out $(PHONY),$?)$(filter-out $(PHONY) $(wildcard $^),$^)
|
2006-07-23 13:37:44 -04:00
|
|
|
|
2007-02-05 20:18:21 -05:00
|
|
|
# Execute command if command has changed or prerequisite(s) are updated.
|
2019-06-22 12:07:05 -04:00
|
|
|
if_changed = $(if $(any-prereq)$(cmd-check), \
|
2018-11-29 20:05:29 -05: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 03:36:30 -05:00
|
|
|
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
|
2005-07-25 16:10:36 -04:00
|
|
|
|
2007-02-05 20:18:21 -05:00
|
|
|
# Execute the command and also postprocess generated .d dependencies file.
|
2019-06-22 12:07:05 -04:00
|
|
|
if_changed_dep = $(if $(any-prereq)$(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 13:41:57 -05:00
|
|
|
|
2016-02-17 15:50:06 -05:00
|
|
|
cmd_and_fixdep = \
|
2018-11-29 20:05:27 -05: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-29 20:05:22 -05:00
|
|
|
scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
|
2018-11-29 20:05:28 -05: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 13:41:57 -05:00
|
|
|
|
2005-07-25 16:10:36 -04:00
|
|
|
# Usage: $(call if_changed_rule,foo)
|
2007-02-08 16:48:51 -05:00
|
|
|
# Will check if $(cmd_foo) or any of the prerequisites changed,
|
|
|
|
# and if so will execute $(rule_foo).
|
2019-06-22 12:07:05 -04:00
|
|
|
if_changed_rule = $(if $(any-prereq)$(cmd-check),$(rule_$(1)),@:)
|
2006-07-23 13:37:44 -04:00
|
|
|
|
2006-08-08 15:35:14 -04:00
|
|
|
###
|
2017-08-01 22:31:06 -04:00
|
|
|
# why - tell why a target got built
|
2006-08-08 15:35:14 -04: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-06-22 12:07:04 -04:00
|
|
|
$(if $(any-prereq),- due to: $(any-prereq), \
|
2019-06-22 12:07:03 -04:00
|
|
|
$(if $(cmd-check), \
|
2006-08-08 15:35:14 -04: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 11:17:16 -04: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 03:46:33 -04:00
|
|
|
|
|
|
|
# delete partially updated (i.e. corrupted) files on error
|
|
|
|
.DELETE_ON_ERROR:
|
2018-11-30 19:27:15 -05:00
|
|
|
|
|
|
|
# do not delete intermediate files automatically
|
|
|
|
.SECONDARY:
|