kbuild: refactor silent mode detection
Subsystems (6)
PATCH 1/5 kbuild: refactor silent mode detection
Factor out $(findstring s,...).
---
Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
@@ -100,12 +100,12 @@ endif # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. ifeq ($(filter 3.%,$(MAKE_VERSION)),) -silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) +short-opts := $(firstword -$(MAKEFLAGS)) else -silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS))) +short-opts := $(filter-out --%,$(MAKEFLAGS)) endif -ifeq ($(silence),s) +ifneq ($(findstring s,$(short-opts)),) quiet=silent_ KBUILD_VERBOSE = 0 endif
Signature · 1 line
2.34.1
PATCH 2/5 kbuild: print short log in addition to the whole command with V=1
"make V=1" prints the whole command instead of the short log, but I think it is nicer to print both so that you can easily spot the build rule of your interest.
This commit changes V=1 to print the short log (the line starts with '#'), followed by the full log.
In parallel builds, the short/full logs from the same build rule may be interspersed. To avoid it, please add -Otarget along with the -j<N> option. Kbuild will never set -Otarget by default because Make would buffer the logs and lose the escape sequences. (Modern compilers print warnings and errors in color, but only when they write to a terminal.)
This is also a preparation for supporting V=12 because V=2 appends the reason for rebuilding to the short log.
---
Makefile | 18 +++++++----------- scripts/Kbuild.include | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 24 deletions(-)
Makefile +7 -11
@@ -56,22 +56,18 @@ unexport GREP_OPTIONS # Beautify output # --------------------------------------------------------------------------- # -# Normally, we echo the whole command before executing it. By making -# that echo $($(quiet)$(cmd)), we now have the possibility to set -# $(quiet) to choose other forms of output instead, e.g. +# Most of build commands in Kbuild start with "cmd_". You can optionally define +# "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from +# that command is printed by default. # -# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@ -# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< -# -# If $(quiet) is empty, the whole command will be printed. -# If it is set to "quiet_", only the short version will be printed. -# If it is set to "silent_", nothing will be printed at all, since -# the variable $(silent_cmd_cc_o_c) doesn't exist. +# e.g.) +# quiet_cmd_depmod = DEPMOD $(MODLIB) +# cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE) # # A simple variant is to prefix commands with $(Q) - that's useful # for commands that shall be hidden in non-verbose mode. # -# $(Q)ln $@ :< +# $(Q)$(MAKE) $(build)=scripts/basic # # If KBUILD_VERBOSE equals 0 then the above command will be hidden. # If KBUILD_VERBOSE equals 1 then the above command is displayed.
scripts/Kbuild.include +13 -13
@@ -125,15 +125,15 @@ dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj # $(Q)$(MAKE) $(clean)=dir clean := -f $(srctree)/scripts/Makefile.clean obj -# echo command. -# Short version is used, if $(quiet) equals `quiet_', otherwise full one. -echo-cmd = $(if $($(quiet)cmd_$(1)),\ - echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) - -# sink stdout for 'make -s' - redirect := - quiet_redirect := -silent_redirect := exec >/dev/null; +# pring log +# +# If quiet is "silent_", print nothing and sink stdout +# If quiet is "quiet_", print short log +# If quiet is empty, print short log and whole command +silent_log_print = exec >/dev/null; + quiet_log_print = $(if $(quiet_cmd_$1), echo ' $(call escsq,$(quiet_cmd_$1)$(why))';) + log_print = echo '$(pound) $(call escsq,$(or $(quiet_cmd_$1),cmd_$1 $@))'; \ + echo ' $(call escsq,$(cmd_$1))'; # Delete the target on interruption #
@@ -156,8 +156,8 @@ delete-on-interrupt = \ $(foreach sig, HUP INT QUIT TERM PIPE, \ trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);)) -# printing commands -cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(delete-on-interrupt) $(cmd_$(1)) +# print and execute commands +cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:) ### # if_changed - execute command if any prerequisite is newer than
@@ -234,7 +234,7 @@ if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:) # (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 = \ +_why = \ $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ $(if $(wildcard $@), \ $(if $(newer-prereqs),- due to: $(newer-prereqs), \
@@ -251,7 +251,7 @@ why = \ ) \ ) -echo-why = $(call escsq, $(strip $(why))) +why = $(space)$(strip $(_why)) endif ###############################################################################
Signature · 1 line
2.34.1
Re: [PATCH 2/5] kbuild: print short log in addition to the whole command with V=1
Quoted 16 lines · Masahiro Yamada
"make V=1" prints the whole command instead of the short log, but I think it is nicer to print both so that you can easily spot the build rule of your interest.
This commit changes V=1 to print the short log (the line starts with '#'), followed by the full log.
In parallel builds, the short/full logs from the same build rule may be interspersed. To avoid it, please add -Otarget along with the -j<N> option.
Kbuildwill never set -Otarget by default because Make would buffer the logs and lose the escape sequences. (Modern compilers print warnings and errors in color, but only when they write to a terminal.)This is also a preparation for supporting V=12 because V=2 appends the reason for rebuilding to the short log.
Quoted 6 lines
Signed-off-by Masahiro Yamada <[email protected]>---
Makefile | 18 +++++++----------- scripts/Kbuild.include | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 24 deletions(-)
I think this is really helpful, thanks!
PATCH 3/5 kbuild: do not print extra logs for V=2
In reply to Masahiro YamadaSome scripts increase the verbose level when V=1, but others when not V=0.
I think the former is correct because V=2 is not a log level but a switch to print the reason for rebuilding.
---
Documentation/Makefile | 2 +- arch/powerpc/kernel/prom_init_check.sh | 9 ++++----- certs/extract-cert.c | 9 ++++++--- scripts/asn1_compiler.c | 4 ++-- scripts/kernel-doc | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-)
Documentation/Makefile +1 -1
@@ -28,7 +28,7 @@ BUILDDIR = $(obj)/output PDFLATEX = xelatex LATEXOPTS = -interaction=batchmode -no-shell-escape -ifeq ($(KBUILD_VERBOSE),0) +ifeq ($(findstring 1, $(KBUILD_VERBOSE)),) SPHINXOPTS += "-q" endif
arch/powerpc/kernel/prom_init_check.sh +4 -5
@@ -51,11 +51,10 @@ do # a leading . on the name, so strip it off here. UNDEF="${UNDEF#.}" - if [ $KBUILD_VERBOSE ]; then - if [ $KBUILD_VERBOSE -ne 0 ]; then - echo "Checking prom_init.o symbol '$UNDEF'" - fi - fi + case "$KBUILD_VERBOSE" in + *1*) + echo "Checking prom_init.o symbol '$UNDEF'" ;; + esac OK=0 for WHITE in $WHITELIST
certs/extract-cert.c +6 -3
@@ -78,7 +78,7 @@ static void drain_openssl_errors(void)static const char *key_pass;static BIO *wb;static char *cert_dst; -static int kbuild_verbose; +static bool verbose;static void write_cert (X509 *x509) {
@@ -90,19 +90,22 @@ static void write_cert(X509 *x509) }X509_NAME_oneline (X509_get_subject_name (x509), buf,sizeof (buf));ERR (!i2d_X509_bio (wb, x509),"%s" , cert_dst); -if (kbuild_verbose) +if (verbose)fprintf (stderr,"Extracted cert: %s\n" , buf); }int main (int argc,char **argv) {char *cert_src; +char *kbuild_verbose;OpenSSL_add_all_algorithms ();ERR_load_crypto_strings ();ERR_clear_error (); - kbuild_verbose =atoi (getenv ("KBUILD_VERBOSE" )?:"0" ); + kbuild_verbose =getenv ("KBUILD_VERBOSE" ); +if (kbuild_verbose &&strchr (kbuild_verbose,'1' )) + verbose = true; key_pass =getenv ("KBUILD_SIGN_PIN" );
scripts/asn1_compiler.c +2 -2
@@ -567,8 +567,8 @@ int main(int argc, char **argv)int fd; kbuild_verbose =getenv ("KBUILD_VERBOSE" ); -if (kbuild_verbose) - verbose_opt =atoi (kbuild_verbose); +if (kbuild_verbose &&strchr (kbuild_verbose,'1' )) + verbose_opt = true;while (argc >4 ) {if (strcmp (argv[1 ],"-v" ) ==0 )
scripts/kernel-doc +2 -2
@@ -175,8 +175,8 @@ my $declaration_start_line; my ($type, $declaration_name, $return_type); my ($newsection, $newcontents, $prototype, $brcount, %source_map); -if (defined($ENV{'KBUILD_VERBOSE'})) { - $verbose = "$ENV{'KBUILD_VERBOSE'}"; +if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { + $verbose = 1; } if (defined($ENV{'KCFLAGS'})) {
Signature · 1 line
2.34.1
Re: [PATCH 3/5] kbuild: do not print extra logs for V=2
Quoted 7 lines · Masahiro Yamada
Some scripts increase the verbose level when V=1, but others when not V=0.
I think the former is correct because V=2 is not a log level but a switch to print the reason for rebuilding.
Signed-off-by Masahiro Yamada <[email protected]>
Quoted 9 lines
---
Documentation/Makefile | 2 +- arch/powerpc/kernel/prom_init_check.sh | 9 ++++----- certs/extract-cert.c | 9 ++++++--- scripts/asn1_compiler.c | 4 ++-- scripts/kernel-doc | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-)
PATCH 4/5 kbuild: allow to combine multiple V= levels
In reply to Masahiro YamadaCommit a6de553da01c ("kbuild: Allow to combine multiple W= levels") supported W=123 to enable all the extra warning groups.
I think a similar idea is applicable to the V= option.
V=1 echos the whole command
V=2 prints the reason for rebuilding
These are orthogonal, and can be enabled at the same time.
This commit supports V=12 to enable both of them.
---
Makefile | 18 +++++++++--------- arch/x86/tools/Makefile | 2 +- scripts/Kbuild.include | 4 ++-- scripts/tags.sh | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
Makefile +9 -9
@@ -69,9 +69,8 @@ unexport GREP_OPTIONS # # $(Q)$(MAKE) $(build)=scripts/basic # -# If KBUILD_VERBOSE equals 0 then the above command will be hidden. -# If KBUILD_VERBOSE equals 1 then the above command is displayed. -# If KBUILD_VERBOSE equals 2 then give the reason why each target is rebuilt. +# If KBUILD_VERBOSE contains 1, the whole command is echoed. +# If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed. # # To put more focus on warnings, be less verbose as default # Use 'make V=1' to see the full commands
@@ -83,12 +82,12 @@ ifndef KBUILD_VERBOSE KBUILD_VERBOSE = 0 endif -ifeq ($(KBUILD_VERBOSE),1) +quiet = quiet_ +Q = @ + +ifneq ($(findstring 1, $(KBUILD_VERBOSE)),) quiet = Q = -else - quiet=quiet_ - Q = @ endif # If the user is running make -s (silent mode), suppress echoing of
@@ -1762,8 +1761,9 @@ help: printf " %-16s - Show all of the above\\n" help-boards; \ echo '') - @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' - @echo ' make V=2 [targets] 2 => give reason for rebuild of target' + @echo ' make V=n [targets] 0: quiet build (default), 1: verbose build' + @echo ' 2: give reason for rebuild of target' + @echo ' V=1 and V=2 can be combined with V=12' @echo ' make O=dir [targets] Locate all output files in "dir", including .config' @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' @echo ' (sparse by default)'
arch/x86/tools/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 PHONY += posttest -ifeq ($(KBUILD_VERBOSE),1) +ifneq ($(findstring 1, $(KBUILD_VERBOSE)),) posttest_verbose = -v else posttest_verbose =
scripts/Kbuild.include +2 -2
@@ -132,7 +132,7 @@ clean := -f $(srctree)/scripts/Makefile.clean obj # If quiet is empty, print short log and whole command silent_log_print = exec >/dev/null; quiet_log_print = $(if $(quiet_cmd_$1), echo ' $(call escsq,$(quiet_cmd_$1)$(why))';) - log_print = echo '$(pound) $(call escsq,$(or $(quiet_cmd_$1),cmd_$1 $@))'; \ + log_print = echo '$(pound) $(call escsq,$(or $(quiet_cmd_$1),cmd_$1 $@)$(why))'; \ echo ' $(call escsq,$(cmd_$1))'; # Delete the target on interruption
@@ -233,7 +233,7 @@ if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:) # (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) +ifneq ($(findstring 2, $(KBUILD_VERBOSE)),) _why = \ $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ $(if $(wildcard $@), \
scripts/tags.sh +1 -1
@@ -8,7 +8,7 @@ # Uses the following environment variables: # SUBARCH, SRCARCH, srctree -if [ "$KBUILD_VERBOSE" = "1" ]; then +if [[ "$KBUILD_VERBOSE" =~ 1 ]]; then set -x fi
Signature · 1 line
2.34.1
Re: [PATCH 4/5] kbuild: allow to combine multiple V= levels
Quoted 12 lines · Masahiro Yamada
Commit
a6de553da01c("kbuild: Allow to combine multiple W= levels") supported W=123 to enable all the extra warning groups.I think a similar idea is applicable to the V= option.
V=1 echos the whole command
V=2 prints the reason for rebuildingThese are orthogonal, and can be enabled at the same time.
This commit supports V=12 to enable both of them.
Quoted 9 lines
Signed-off-by Masahiro Yamada <[email protected]>---
Makefile | 18 +++++++++--------- arch/x86/tools/Makefile | 2 +- scripts/Kbuild.include | 4 ++-- scripts/tags.sh | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
PATCH 5/5 kbuild: drop V=0 support
In reply to Masahiro YamadaThe top Makefile sets KBUILD_VERBOSE to 0 by default, it looks weird now because V=1 and V=2 can be OR'ed as V=12. The default should be empty.
---
Documentation/kbuild/makefiles.rst | 4 ++-- Makefile | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
Documentation/kbuild/makefiles.rst +2 -2
@@ -523,7 +523,7 @@ more details, with real examples. $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ @$(kecho) ' Kernel: $(boot)/$@ is ready' - When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand + When kbuild is executing with KBUILD_VERBOSE unset, then only a shorthand of a command is normally displayed. To enable this behaviour for custom commands kbuild requires two variables to be set::
@@ -544,7 +544,7 @@ more details, with real examples. GEN lib/crc32table.h - will be displayed with "make KBUILD_VERBOSE=0". + will be displayed with "make KBUILD_VERBOSE=". 3.12 Command change detection -----------------------------
Makefile +2 -5
@@ -78,9 +78,6 @@ unexport GREP_OPTIONS ifeq ("$(origin V)", "command line") KBUILD_VERBOSE = $(V) endif -ifndef KBUILD_VERBOSE - KBUILD_VERBOSE = 0 -endif quiet = quiet_ Q = @
@@ -102,7 +99,7 @@ endif ifneq ($(findstring s,$(short-opts)),) quiet=silent_ -KBUILD_VERBOSE = 0 +override KBUILD_VERBOSE := endif export quiet Q KBUILD_VERBOSE
@@ -1761,7 +1758,7 @@ help: printf " %-16s - Show all of the above\\n" help-boards; \ echo '') - @echo ' make V=n [targets] 0: quiet build (default), 1: verbose build' + @echo ' make V=n [targets] 1: verbose build' @echo ' 2: give reason for rebuild of target' @echo ' V=1 and V=2 can be combined with V=12' @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
Signature · 1 line
2.34.1
Re: [PATCH 5/5] kbuild: drop V=0 support
Quoted 11 lines · Masahiro Yamada
The top
MakefilesetsKBUILD_VERBOSEto 0 by default, it looks weird now because V=1 and V=2 can be OR'ed as V=12. The default should be empty.Signed-off-by Masahiro Yamada <[email protected]>---
Documentation/kbuild/makefiles.rst | 4 ++-- Makefile | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
Quoted 4 lines · Masahiro Yamada
Factor out $(findstring s,...).
Signed-off-by Masahiro Yamada <[email protected]>
Thanks for the patch!
Quoted 28 lines
---
Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Makefile +3
-4@@ -100,12 +100,12 @@ endif # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. ifeq ($(filter 3.%,$(MAKE_VERSION)),) -silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) +short-opts := $(firstword -$(MAKEFLAGS)) else -silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS))) +short-opts := $(filter-out --%,$(MAKEFLAGS)) endif -ifeq ($(silence),s) +ifneq ($(findstring s,$(short-opts)),) quiet=silent_ KBUILD_VERBOSE = 0 endif --2.34.1
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 7 lines · Masahiro Yamada
Factor out $(findstring s,...).
Signed-off-by Masahiro Yamada <[email protected]>---
Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)