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
|
|
|
|
kbuild: add test-{ge,gt,le,lt} macros
JIRA: https://issues.redhat.com/browse/RHEL-25415
Conflicts: arch/risc not supported in RHEL9
commit fccb3d3eda8d19b893e1fd18e8c70b78784b2a72
Author: Masahiro Yamada <masahiroy@kernel.org>
Date: Sun Dec 11 11:46:47 2022 +0900
kbuild: add test-{ge,gt,le,lt} macros
GNU Make 4.4 introduced $(intcmp ...), which is useful to compare two
integers without forking a new process.
Add test-{ge,gt,le,lt} macros, which work more efficiently with GNU
Make >= 4.4. For older Make versions, they fall back to the 'test'
shell command.
The first two parameters to $(intcmp ...) must not be empty. To avoid
the syntax error, I appended '0' to them. Fortunately, '00' is treated
as '0'. This is needed because CONFIG options may expand to an empty
string when the kernel configuration is not included.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com> # RISC-V
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2023-07-25 13:48:31 +00:00
|
|
|
###
|
|
|
|
# Comparison macros.
|
|
|
|
# Usage: $(call test-lt, $(CONFIG_LLD_VERSION), 150000)
|
|
|
|
#
|
|
|
|
# Use $(intcmp ...) if supported. (Make >= 4.4)
|
|
|
|
# Otherwise, fall back to the 'test' shell command.
|
|
|
|
ifeq ($(intcmp 1,0,,,y),y)
|
|
|
|
test-ge = $(intcmp $(strip $1)0, $(strip $2)0,,y,y)
|
|
|
|
test-gt = $(intcmp $(strip $1)0, $(strip $2)0,,,y)
|
|
|
|
else
|
|
|
|
test-ge = $(shell test $(strip $1)0 -ge $(strip $2)0 && echo y)
|
|
|
|
test-gt = $(shell test $(strip $1)0 -gt $(strip $2)0 && echo y)
|
|
|
|
endif
|
|
|
|
test-le = $(call test-ge, $2, $1)
|
|
|
|
test-lt = $(call test-gt, $2, $1)
|
|
|
|
|
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 $@)
|
|
|
|
|
2024-07-11 12:15:42 +00:00
|
|
|
###
|
|
|
|
# Name of target with a '.tmp_' as filename prefix. foo/bar.o => foo/.tmp_bar.o
|
|
|
|
tmp-target = $(dir $@).tmp_$(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)
|
|
|
|
|
2024-04-22 19:46:37 +00:00
|
|
|
###
|
|
|
|
# The path to Kbuild or Makefile. Kbuild has precedence over Makefile.
|
kbuild: use $(src) instead of $(srctree)/$(src) for source directory
JIRA: https://issues.redhat.com/browse/RHEL-107194
commit b1992c3772e69a6fd0e3fc81cd4d2820c8b6eca0
Author: Masahiro Yamada <masahiroy@kernel.org>
Date: Sat Apr 27 23:55:02 2024 +0900
kbuild: use $(src) instead of $(srctree)/$(src) for source directory
Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for
checked-in source files. It is merely a convention without any functional
difference. In fact, $(obj) and $(src) are exactly the same, as defined
in scripts/Makefile.build:
src := $(obj)
When the kernel is built in a separate output directory, $(src) does
not accurately reflect the source directory location. While Kbuild
resolves this discrepancy by specifying VPATH=$(srctree) to search for
source files, it does not cover all cases. For example, when adding a
header search path for local headers, -I$(srctree)/$(src) is typically
passed to the compiler.
This introduces inconsistency between upstream and downstream Makefiles
because $(src) is used instead of $(srctree)/$(src) for the latter.
To address this inconsistency, this commit changes the semantics of
$(src) so that it always points to the directory in the source tree.
Going forward, the variables used in Makefiles will have the following
meanings:
$(obj) - directory in the object tree
$(src) - directory in the source tree (changed by this commit)
$(objtree) - the top of the kernel object tree
$(srctree) - the top of the kernel source tree
Consequently, $(srctree)/$(src) in upstream Makefiles need to be replaced
with $(src).
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Conflicts:
There is a extensive list of fixes/conflicts due the amount of files originally
changed by this commit, plus the difference of rhel-9 code against upstream. All
conflicts/differences are listed below:
- Context difference at Documentation/Makefile since RHEL 9 does not have the
change "docs: allow to pass extra DOCS_CSS themes via make" and later changes.
- Conflict at Documentation/devicetree/bindings/Makefile, patch find_cmd instead
of find_all_cmd since RHEL-9 doesn't have "dt-bindings: Consider
DT_SCHEMA_FILES when finding all json-schema", "dt-bindings: kbuild: Split
targets out to separate rules" and later changes.
- Conflict at Documentation/kbuild/makefiles.rst due different identation since
RHEL-9 doesn't have the change "docs/kbuild/makefiles: clean up indentation
and whitespace"
- Patched additional $(srctree)/$(src) references at:
* arch/arm/mach-davinci/Makefile
* arch/arm/mach-omap2/Makefile
* arch/arm/mach-spear/Makefile
* arch/arm/plat-pxa/Makefile
* arch/arm/plat-versatile/Makefile
* arch/ia64/kernel/Makefile
* arch/nds32/boot/Makefile
* arch/nds32/kernel/vdso/Makefile
* drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile
* drivers/net/ethernet/hisilicon/hns3/hns3vf/Makefile
* drivers/staging/rtl8188eu/Makefile
* drivers/staging/unisys/visorhba/Makefile
* drivers/staging/unisys/visornic/Makefile
* scripts/gcc-plugins/Makefile
Since RHEL-9 does not have later upstream changes that dropped/made those
references uneeded.
- Conflict at arch/arm/mach-s3c/Makefile since RHEL-9 doesn't have
"ARM: s3c: remove s3c24xx specific hacks" and related changes. Also,
extra locations needed patching because of not having the changes
"ARM: s3c: remove all s3c24xx support" and "ARM: s3c: fix include path".
Due lacking the last change also arch/arm/mach-s3c/Makefile.s3c64xx needs
additional two places patched as well.
- Conflict at arch/arm/plat-orion/Makefile since RHEL-9 doesn't have
the commit "ARM: orion: fix include path" and its previous related
changes.
- Dropped changes for arch/loongarch since it doesn't exist on rhel-9
- Dropped changes to arch/parisc/kernel/{vdso32,vdso64}/Makefile since RHEL 9
does not have the change "parisc: Add vDSO support" and later updates to it.
- Dropped change to arch/riscv/kernel/compat_vdso/Makefile since RHEL 9 does
not have the change "riscv: compat: vdso: Add COMPAT_VDSO base code implementation"
- Dropped change to arch/riscv/kvm/Makefile since there is no KVM support/commits
in RHEL 9 for riscv.
- Apply change for arch/riscv/kernel/vdso/Makefile in a different place since
RHEL-9 does not have the change "riscv: explicitly use symbol offsets for VDSO"
which changed the location of the $(srctree)/$(src) reference
- Dropped change to certs/Makefile related to check-blacklist-hashes.awk since
that script was only added with commit "certs: Check that builtin blacklist
hashes are valid" which is not backported/available in RHEL 9 code right now.
- Dropped change to drivers/md/dm-vdo/Makefile since dm-vdo was never backported
to RHEL-9 main.
- Dropped change to drivers/net/ethernet/fungible/funeth/Makefile since fungible
ethernet driver/devices code is not available/backported to RHEL-9.
- Fixed conflict at drivers/net/ethernet/hisilicon/hns3/Makefile since RHEL-9
does not have the change "net: hns3: refactor hns3 makefile to support
hns3_common module"
- Fixed conflict at drivers/net/wireless/intel/iwlwifi/mvm/Makefile due already
backported commit "wifi: iwlwifi: mvm: implement link grading"
- Dropped change to init/Makefile since we are not backporting
"kbuild: build init/built-in.a just once" that introduced the section patched.
- Dropped change to rust/Makefile since there is no rust support backported
to RHEL-9.
- Fixed conflict at scripts/dtc/Makefile since RHEL-9 does not have the change
"dt-bindings: kbuild: Use DTB files for validation"
- Dropped change to security/tomoyo/Makefile since it's not needed, it's just
reverting the change "tomoyo: fix broken dependency on *.conf.default" which
was never applied to RHEL-9. However, we also bring a different change/patch
location since RHEL-9 does not have the change "tomoyo: Omit use of bin2c".
- Dropped change to usr/include/Makefile since "kbuild: move headers_check.pl to
usr/include/" is not being backported to RHEL-9.
- Misc/minor context differences at other places.
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2025-08-14 22:50:14 +00:00
|
|
|
kbuild-file = $(or $(wildcard $(src)/Kbuild),$(src)/Makefile)
|
2024-04-22 19:46:37 +00:00
|
|
|
|
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
|
2024-04-03 20:03:44 +00:00
|
|
|
$(check-FORCE)
|
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)';)
|
|
|
|
|
kbuild: sink stdout from cmd for silent build
When building with 'make -s', no output to stdout should be printed.
As Arnd Bergmann reported [1], mkimage shows the detailed information
of the generated images.
I think this should be suppressed by the 'cmd' macro instead of by
individual scripts.
Insert 'exec >/dev/null;' in order to redirect stdout to /dev/null for
silent builds.
[Note about this implementation]
'exec >/dev/null;' may look somewhat tricky, but this has a reason.
Appending '>/dev/null' at the end of command line is a common way for
redirection, so I first tried this:
cmd = @set -e; $(echo-cmd) $(cmd_$(1)) >/dev/null
... but it would not work if $(cmd_$(1)) itself contains a redirection.
For example, cmd_wrap in scripts/Makefile.asm-generic redirects the
output from the 'echo' command into the target file.
It would be expanded into:
echo "#include <asm-generic/$*.h>" > $@ >/dev/null
Then, the target file gets empty because the string will go to /dev/null
instead of $@.
Next, I tried this:
cmd = @set -e; $(echo-cmd) { $(cmd_$(1)); } >/dev/null
The form above would be expanded into:
{ echo "#include <asm-generic/$*.h>" > $@; } >/dev/null
This works as expected. However, it would be a syntax error if
$(cmd_$(1)) is empty.
When CONFIG_TRIM_UNUSED_KSYMS is disabled, $(call cmd,gen_ksymdeps) in
scripts/Makefile.build would be expanded into:
set -e; { ; } >/dev/null
..., which causes an syntax error.
I also tried this:
cmd = @set -e; $(echo-cmd) ( $(cmd_$(1)) ) >/dev/null
... but this causes a syntax error for the same reason.
So, finally I adopted:
cmd = @set -e; $(echo-cmd) exec >/dev/null; $(cmd_$(1))
[1]: https://lore.kernel.org/lkml/20210514135752.2910387-1-arnd@kernel.org/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-05-17 07:03:13 +00:00
|
|
|
# sink stdout for 'make -s'
|
|
|
|
redirect :=
|
|
|
|
quiet_redirect :=
|
|
|
|
silent_redirect := exec >/dev/null;
|
|
|
|
|
2007-02-06 01:18:21 +00:00
|
|
|
# printing commands
|
kbuild: sink stdout from cmd for silent build
When building with 'make -s', no output to stdout should be printed.
As Arnd Bergmann reported [1], mkimage shows the detailed information
of the generated images.
I think this should be suppressed by the 'cmd' macro instead of by
individual scripts.
Insert 'exec >/dev/null;' in order to redirect stdout to /dev/null for
silent builds.
[Note about this implementation]
'exec >/dev/null;' may look somewhat tricky, but this has a reason.
Appending '>/dev/null' at the end of command line is a common way for
redirection, so I first tried this:
cmd = @set -e; $(echo-cmd) $(cmd_$(1)) >/dev/null
... but it would not work if $(cmd_$(1)) itself contains a redirection.
For example, cmd_wrap in scripts/Makefile.asm-generic redirects the
output from the 'echo' command into the target file.
It would be expanded into:
echo "#include <asm-generic/$*.h>" > $@ >/dev/null
Then, the target file gets empty because the string will go to /dev/null
instead of $@.
Next, I tried this:
cmd = @set -e; $(echo-cmd) { $(cmd_$(1)); } >/dev/null
The form above would be expanded into:
{ echo "#include <asm-generic/$*.h>" > $@; } >/dev/null
This works as expected. However, it would be a syntax error if
$(cmd_$(1)) is empty.
When CONFIG_TRIM_UNUSED_KSYMS is disabled, $(call cmd,gen_ksymdeps) in
scripts/Makefile.build would be expanded into:
set -e; { ; } >/dev/null
..., which causes an syntax error.
I also tried this:
cmd = @set -e; $(echo-cmd) ( $(cmd_$(1)) ) >/dev/null
... but this causes a syntax error for the same reason.
So, finally I adopted:
cmd = @set -e; $(echo-cmd) exec >/dev/null; $(cmd_$(1))
[1]: https://lore.kernel.org/lkml/20210514135752.2910387-1-arnd@kernel.org/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-05-17 07:03:13 +00:00
|
|
|
cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(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
|
|
|
|
2024-04-03 20:03:44 +00:00
|
|
|
# It is a typical mistake to forget the FORCE prerequisite. Check it here so
|
|
|
|
# no more breakage will slip in.
|
|
|
|
check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequisite is missing))
|
|
|
|
|
|
|
|
if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE)
|
2024-04-03 20:03:44 +00:00
|
|
|
|
2007-02-06 01:18:21 +00:00
|
|
|
# Execute command if command has changed or prerequisite(s) are updated.
|
2024-04-03 20:03:44 +00:00
|
|
|
if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:)
|
|
|
|
|
|
|
|
cmd_and_savecmd = \
|
2018-11-30 01:05:29 +00:00
|
|
|
$(cmd); \
|
2024-04-03 20:03:44 +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.
|
2024-04-03 20:03:44 +00:00
|
|
|
if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
|
kbuild: add fine grained build dependencies for exported symbols
Like with kconfig options, we now have the ability to compile in and
out individual EXPORT_SYMBOL() declarations based on the content of
include/generated/autoksyms.h. However we don't want the entire
world to be rebuilt whenever that file is touched.
Let's apply the same build dependency trick used for CONFIG_* symbols
where the time stamp of empty files whose paths matching those symbols
is used to trigger fine grained rebuilds. In our case the key is the
symbol name passed to EXPORT_SYMBOL().
However, unlike config options, we cannot just use fixdep to parse
the source code for EXPORT_SYMBOL(ksym) because several variants exist
and parsing them all in a separate tool, and keeping it in synch, is
not trivially maintainable. Furthermore, there are variants such as
EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
that are instanciated via a macro for which we can't easily determine
the actual exported symbol name(s) short of actually running the
preprocessor on them.
Storing the symbol name string in a special ELF section doesn't work
for targets that output assembly or preprocessed source.
So the best way is really to leverage the preprocessor by having it
output actual symbol names anchored by a special sequence that can be
easily filtered out. Then the list of symbols is simply fed to fixdep
to be merged with the other dependencies.
That implies the preprocessor is executed twice for each source file.
A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
instance that was filtered apart from stderr by the build system with
a sed script during the actual compilation pass. Unfortunately the
preprocessor/compiler diagnostic output isn't stable between versions
and this solution, although more efficient, was deemed too fragile.
Because of the lowercasing performed by fixdep, there might be name
collisions triggering spurious rebuilds for similar symbols. But this
shouldn't be a big issue in practice. (This is the case for CONFIG_*
symbols and I didn't want to be different here, whatever the original
reason for doing so.)
To avoid needless build overhead, the exported symbol name gathering is
performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-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).
|
2024-04-03 20:03:44 +00:00
|
|
|
if_changed_rule = $(if $(if-changed-cond),$(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
|
2023-07-26 19:12:57 +00:00
|
|
|
ifneq ($(findstring 2, $(KBUILD_VERBOSE)),)
|
2006-08-08 19:35:14 +00:00
|
|
|
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:
|