Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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. If you want to avoid it, please add -Otarget option.
Kbuild will never set it 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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Nicolas Schier <nicolas@fjasle.eu>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

+20 -24
+7 -11
Makefile
··· 56 56 # Beautify output 57 57 # --------------------------------------------------------------------------- 58 58 # 59 - # Normally, we echo the whole command before executing it. By making 60 - # that echo $($(quiet)$(cmd)), we now have the possibility to set 61 - # $(quiet) to choose other forms of output instead, e.g. 59 + # Most of build commands in Kbuild start with "cmd_". You can optionally define 60 + # "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from 61 + # that command is printed by default. 62 62 # 63 - # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@ 64 - # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 65 - # 66 - # If $(quiet) is empty, the whole command will be printed. 67 - # If it is set to "quiet_", only the short version will be printed. 68 - # If it is set to "silent_", nothing will be printed at all, since 69 - # the variable $(silent_cmd_cc_o_c) doesn't exist. 63 + # e.g.) 64 + # quiet_cmd_depmod = DEPMOD $(MODLIB) 65 + # cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE) 70 66 # 71 67 # A simple variant is to prefix commands with $(Q) - that's useful 72 68 # for commands that shall be hidden in non-verbose mode. 73 69 # 74 - # $(Q)ln $@ :< 70 + # $(Q)$(MAKE) $(build)=scripts/basic 75 71 # 76 72 # If KBUILD_VERBOSE equals 0 then the above command will be hidden. 77 73 # If KBUILD_VERBOSE equals 1 then the above command is displayed.
+13 -13
scripts/Kbuild.include
··· 125 125 # $(Q)$(MAKE) $(clean)=dir 126 126 clean := -f $(srctree)/scripts/Makefile.clean obj 127 127 128 - # echo command. 129 - # Short version is used, if $(quiet) equals `quiet_', otherwise full one. 130 - echo-cmd = $(if $($(quiet)cmd_$(1)),\ 131 - echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 132 - 133 - # sink stdout for 'make -s' 134 - redirect := 135 - quiet_redirect := 136 - silent_redirect := exec >/dev/null; 128 + # pring log 129 + # 130 + # If quiet is "silent_", print nothing and sink stdout 131 + # If quiet is "quiet_", print short log 132 + # If quiet is empty, print short log and whole command 133 + silent_log_print = exec >/dev/null; 134 + quiet_log_print = $(if $(quiet_cmd_$1), echo ' $(call escsq,$(quiet_cmd_$1)$(why))';) 135 + log_print = echo '$(pound) $(call escsq,$(or $(quiet_cmd_$1),cmd_$1 $@))'; \ 136 + echo ' $(call escsq,$(cmd_$1))'; 137 137 138 138 # Delete the target on interruption 139 139 # ··· 156 156 $(foreach sig, HUP INT QUIT TERM PIPE, \ 157 157 trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);)) 158 158 159 - # printing commands 160 - cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(delete-on-interrupt) $(cmd_$(1)) 159 + # print and execute commands 160 + cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:) 161 161 162 162 ### 163 163 # if_changed - execute command if any prerequisite is newer than ··· 234 234 # (6) No dir/.target.cmd file and target not listed in $(targets) 235 235 # This is a good hint that there is a bug in the kbuild file 236 236 ifeq ($(KBUILD_VERBOSE),2) 237 - why = \ 237 + _why = \ 238 238 $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ 239 239 $(if $(wildcard $@), \ 240 240 $(if $(newer-prereqs),- due to: $(newer-prereqs), \ ··· 251 251 ) \ 252 252 ) 253 253 254 - echo-why = $(call escsq, $(strip $(why))) 254 + why = $(space)$(strip $(_why)) 255 255 endif 256 256 257 257 ###############################################################################