diff options
author | Jean-Philippe Brucker <jean-philippe@linaro.org> | 2020-03-12 17:19:45 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-04-29 14:52:19 +0200 |
commit | ed8af51b600fd16d22c6663a241547c3a9d7f2b4 (patch) | |
tree | cefe5aea5aaf30a1d96de97184aba405825ea509 | |
parent | b9943741c26e1e597edc142066f428540d1f1207 (diff) | |
download | busybox-w32-ed8af51b600fd16d22c6663a241547c3a9d7f2b4.tar.gz busybox-w32-ed8af51b600fd16d22c6663a241547c3a9d7f2b4.tar.bz2 busybox-w32-ed8af51b600fd16d22c6663a241547c3a9d7f2b4.zip |
build system: remove KBUILD_STR()
When using GNU Make >=4.3, the KBUILD_STR() definition interferes badly
with dependency checks during build, and forces a complete rebuild every
time Make runs.
In if_changed_rule, Kconfig checks if the command used to build a file
has changed since last execution. The previous command is stored in the
generated .<file>.o.cmd file. For example applets/.applets.o.cmd defines
a "cmd_applets/applets.o" variable:
cmd_applets/applets.o := gcc ... -D"KBUILD_STR(s)=#s" ...
Here the '#' should be escaped with a backslash, otherwise GNU Make
interprets it as starting a comment, and ignore the rest of the
variable. As a result of this truncation, the previous command doesn't
equal the new command and Make rebuilds each target.
The problem started to appear when GNU Make 4.3 (released January 2020),
introduced a backward-incompatible fix to macros containing a '#'. While
the above use of '#', a simple Make variable, still needs to be escaped,
a '#' within a function invocation doesn't need to be escaped anymore.
As Martin Dorey explained on the GNU Make discussion [1], the above
declaration is generated from make-cmd, defined as:
make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))
Since GNU Make 4.3, the first argument of subst should not have a
backslash. make-cmd now looks for literally \# and doesn't find it, and
as a result doesn't add the backslash when generating .o.cmd files.
[1] http://savannah.gnu.org/bugs/?20513
We could fix it by changing make-cmd to "$(subst #,\#,...)", but to
avoid compatibility headaches, simply get rid of the KBUILD_STR
definition, as done in Linux by b42841b7bb62 ("kbuild: Get rid of
KBUILD_STR"). Quote the string arguments directly rather than asking the
preprocessor to quote them.
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | Makefile.flags | 2 | ||||
-rw-r--r-- | scripts/Kbuild.include | 1 | ||||
-rw-r--r-- | scripts/Makefile.IMA | 1 | ||||
-rw-r--r-- | scripts/Makefile.lib | 8 | ||||
-rwxr-xr-x | scripts/trylink | 3 |
5 files changed, 6 insertions, 9 deletions
diff --git a/Makefile.flags b/Makefile.flags index e378fbad9..bed766b8a 100644 --- a/Makefile.flags +++ b/Makefile.flags | |||
@@ -15,7 +15,7 @@ CPPFLAGS += \ | |||
15 | -include include/autoconf.h \ | 15 | -include include/autoconf.h \ |
16 | -D_GNU_SOURCE -DNDEBUG \ | 16 | -D_GNU_SOURCE -DNDEBUG \ |
17 | $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \ | 17 | $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \ |
18 | -D"BB_VER=KBUILD_STR($(BB_VER))" | 18 | -DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote) |
19 | 19 | ||
20 | CFLAGS += $(call cc-option,-Wall,) | 20 | CFLAGS += $(call cc-option,-Wall,) |
21 | CFLAGS += $(call cc-option,-Wshadow,) | 21 | CFLAGS += $(call cc-option,-Wshadow,) |
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 6ec1809a2..5b4db5c2c 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include | |||
@@ -4,6 +4,7 @@ | |||
4 | # Convinient variables | 4 | # Convinient variables |
5 | comma := , | 5 | comma := , |
6 | squote := ' | 6 | squote := ' |
7 | quote := " | ||
7 | empty := | 8 | empty := |
8 | space := $(empty) $(empty) | 9 | space := $(empty) $(empty) |
9 | 10 | ||
diff --git a/scripts/Makefile.IMA b/scripts/Makefile.IMA index f155108d7..1e3005864 100644 --- a/scripts/Makefile.IMA +++ b/scripts/Makefile.IMA | |||
@@ -49,7 +49,6 @@ OBJCOPY = $(CROSS_COMPILE)objcopy | |||
49 | OBJDUMP = $(CROSS_COMPILE)objdump | 49 | OBJDUMP = $(CROSS_COMPILE)objdump |
50 | 50 | ||
51 | CFLAGS := $(CFLAGS) | 51 | CFLAGS := $(CFLAGS) |
52 | CPPFLAGS += -D"KBUILD_STR(s)=\#s" #-Q | ||
53 | 52 | ||
54 | # We need some generic definitions | 53 | # We need some generic definitions |
55 | include $(srctree)/scripts/Kbuild.include | 54 | include $(srctree)/scripts/Kbuild.include |
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 3e54ea712..d8d768a28 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
@@ -81,10 +81,10 @@ obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) | |||
81 | # Note: It's possible that one object gets potentially linked into more | 81 | # Note: It's possible that one object gets potentially linked into more |
82 | # than one module. In that case KBUILD_MODNAME will be set to foo_bar, | 82 | # than one module. In that case KBUILD_MODNAME will be set to foo_bar, |
83 | # where foo and bar are the name of the modules. | 83 | # where foo and bar are the name of the modules. |
84 | name-fix = $(subst $(comma),_,$(subst -,_,$1)) | 84 | name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) |
85 | basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(*F)))" | 85 | basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(*F)) |
86 | modname_flags = $(if $(filter 1,$(words $(modname))),\ | 86 | modname_flags = $(if $(filter 1,$(words $(modname))),\ |
87 | -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") | 87 | -DKBUILD_MODNAME=$(call name-fix,$(modname))) |
88 | 88 | ||
89 | _c_flags = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) | 89 | _c_flags = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) |
90 | _a_flags = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o) | 90 | _a_flags = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o) |
@@ -110,7 +110,7 @@ endif | |||
110 | 110 | ||
111 | c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ | 111 | c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ |
112 | $(__c_flags) $(modkern_cflags) \ | 112 | $(__c_flags) $(modkern_cflags) \ |
113 | -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) | 113 | $(basename_flags) $(modname_flags) |
114 | 114 | ||
115 | a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ | 115 | a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ |
116 | $(__a_flags) $(modkern_aflags) | 116 | $(__a_flags) $(modkern_aflags) |
diff --git a/scripts/trylink b/scripts/trylink index bb6b2de2f..6b74f092d 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
@@ -50,9 +50,6 @@ check_cc() { | |||
50 | echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c | 50 | echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c |
51 | # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :( | 51 | # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :( |
52 | # Was using "-xc /dev/null", but we need a valid C program. | 52 | # Was using "-xc /dev/null", but we need a valid C program. |
53 | # "eval" may be needed if CFLAGS can contain | ||
54 | # '... -D"BB_VER=KBUILD_STR(1.N.M)" ...' | ||
55 | # and we need shell to process quotes! | ||
56 | $CC $CFLAGS $LDFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1 | 53 | $CC $CFLAGS $LDFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1 |
57 | exitcode=$? | 54 | exitcode=$? |
58 | rm -f "$tempname" "$tempname".c "$tempname".o | 55 | rm -f "$tempname" "$tempname".c "$tempname".o |