kbuild: merge scripts/mkmakefile to top Makefile
PATCH 1/4 kbuild: merge scripts/mkmakefile to top Makefile
scripts/mkmakefile is simple enough to be merged in the Makefile.
Use $(call cmd,...) to show the log instead of doing it in the shell script.
---
Makefile | 15 ++++++++++++--- scripts/mkmakefile | 17 ----------------- 2 files changed, 12 insertions(+), 20 deletions(-) delete mode 100755 scripts/mkmakefile
Makefile +12 -3
@@ -544,14 +544,24 @@ scripts_basic: $(Q)rm -f .tmp_quiet_recordmcount PHONY += outputmakefile +ifdef building_out_of_srctree # Before starting out-of-tree build, make sure the source tree is clean. # outputmakefile generates a Makefile in the output directory, if using a # separate output directory. This allows convenient use of make in the # output directory. # At the same time when output Makefile generated, generate .gitignore to # ignore whole output directory -outputmakefile: -ifdef building_out_of_srctree + +quiet_cmd_makefile = GEN $@ + cmd_makefile = { \ + echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \ + echo "include $(srctree)/Makefile"; \ + } > $@ + +Makefile: FORCE + $(call cmd,makefile) + +outputmakefile: Makefile $(Q)if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
@@ -562,7 +572,6 @@ ifdef building_out_of_srctree false; \ fi $(Q)ln -fsn $(srctree) source - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) $(Q)test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore endif
scripts/mkmakefile deleted +0 -17
@@ -1,17 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 -# Generates a small Makefile used in the root of the output -# directory, to allow make to be started from there. -# The Makefile also allow for more convinient build of external modules - -# Usage -# $1 - Kernel src directory - -if [ "${quiet}" != "silent_" ]; then - echo " GEN Makefile" -fi - -cat << EOF > Makefile -# Automatically generated by $0: don't edit -include $1/Makefile -EOF
Signature · 1 line
2.27.0
PATCH 2/4 init: use $(call cmd,) for generating include/generated/compile.h
The 'cmd' macro shows the short log only when $(quiet) is quiet_. Do not do it manually.
---
init/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
init/Makefile +6 -6
@@ -27,11 +27,11 @@ $(obj)/version.o: include/generated/compile.h # mkcompile_h will make sure to only update the # actual file if its content has changed. - chk_compile.h = : - quiet_chk_compile.h = echo ' CHK $@' -silent_chk_compile.h = : -include/generated/compile.h: FORCE - @$($(quiet)chk_compile.h) - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ +quiet_cmd_compile.h = CHK $@ + cmd_compile.h = \ + $(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ "$(CONFIG_PREEMPT_RT)" $(CONFIG_CC_VERSION_TEXT) "$(LD)" + +include/generated/compile.h: FORCE + $(call cmd,compile.h)
Signature · 1 line
2.27.0
PATCH 3/4 kbuild: sink stdout from cmd for silent build
In reply to Masahiro YamadaWhen 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 done 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.
At first, I tried this:
cmd = @set -e; $(echo-cmd) $(cmd_$(1)) >/dev/null
Appending '>/dev/null' is a commonly used way for redirection, 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.
'$(cmd_$(1)) >/dev/null' 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/nullThe 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.
The following does not work for the same reason.
cmd = @set -e; $(echo-cmd) ( $(cmd_$(1)) ) >/dev/null
So, finally I adopted:
cmd = @set -e; $(echo-cmd) exec >/dev/null; $(cmd_$(1))
[1]: https://lore.kernel.org/lkml/[email protected]/
---
scripts/Kbuild.include | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/Kbuild.include +6 -1
@@ -90,8 +90,13 @@ clean := -f $(srctree)/scripts/Makefile.clean obj 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; + # printing commands -cmd = @set -e; $(echo-cmd) $(cmd_$(1)) +cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(cmd_$(1)) ### # if_changed - execute command if any prerequisite is newer than
Signature · 1 line
2.27.0
PATCH 4/4 kbuild: clean up ${quiet} checks in shell scripts
In reply to Masahiro YamadaThere were efforts to make 'make -s' really silent when it is a warning-free build.
The conventional way was to let scripts check ${quiet}, and if it is 'silent_', suppress the output by their own.
With the previous commit, the 'cmd' takes care of it now. The 'cmd' is also invoked from if_changed, if_changed_dep, and if_changed_rule.
You can omit ${quiet} checks in shell scripts when they are invoked from the 'cmd' macro.
---
kernel/gen_kheaders.sh | 4 +--- scripts/link-vmlinux.sh | 4 +--- scripts/mkcompile_h | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-)
kernel/gen_kheaders.sh +1 -3
@@ -56,9 +56,7 @@ if [ -f kernel/kheaders.md5 ] && exit fi -if [ "${quiet}" != "silent_" ]; then - echo " GEN $tarfile" -fi +echo " GEN $tarfile" rm -rf $cpio_dir mkdir $cpio_dir
scripts/link-vmlinux.sh +1 -3
@@ -38,9 +38,7 @@ LDFLAGS_vmlinux="$3" # Will be supressed by "make -s" info() { - if [ "${quiet}" != "silent_" ]; then - printf " %-7s %s\n" "${1}" "${2}" - fi + printf " %-7s %s\n" "${1}" "${2}" } # Generate a linker script to ensure correct ordering of initcalls.
scripts/mkcompile_h +1 -3
@@ -9,8 +9,6 @@ PREEMPT_RT=$5 CC_VERSION="$6" LD=$7 -vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } - # Do not expand names set -f
@@ -82,7 +80,7 @@ if [ -r $TARGET ] && \ cmp -s .tmpver.1 .tmpver.2; then rm -f .tmpcompile else - vecho " UPD $TARGET" + echo " UPD $TARGET" mv -f .tmpcompile $TARGET fi rm -f .tmpver.1 .tmpver.2
Signature · 1 line
2.27.0
Quoted 8 lines · Masahiro Yamada
scripts/mkmakefileis simple enough to be merged in theMakefile.Use $(call cmd,...) to show the log instead of doing it in the shell script.
Signed-off-by Masahiro Yamada <[email protected]>---
Applied to linux-kbuild.
Quoted 70 lines
Makefile | 15 ++++++++++++--- scripts/mkmakefile | 17 ----------------- 2 files changed, 12 insertions(+), 20 deletions(-) delete mode 100755 scripts/mkmakefileMakefile +12
-3@@ -544,14 +544,24 @@ scripts_basic: $(Q)rm -f .tmp_quiet_recordmcount PHONY += outputmakefile +ifdef building_out_of_srctree # Before starting out-of-tree build, make sure the source tree is clean. # outputmakefile generates a Makefile in the output directory, if using a # separate output directory. This allows convenient use of make in the # output directory. # At the same time when output Makefile generated, generate .gitignore to # ignore whole output directory -outputmakefile: -ifdef building_out_of_srctree + +quiet_cmd_makefile = GEN $@ + cmd_makefile = { \ + echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \ + echo "include $(srctree)/Makefile"; \ + } > $@ + +Makefile: FORCE + $(call cmd,makefile) + +outputmakefile: Makefile $(Q)if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \@@ -562,7 +572,6 @@ ifdef building_out_of_srctree false; \ fi $(Q)ln -fsn $(srctree) source - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) $(Q)test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore endifscripts/mkmakefile deleted +0
-18@@ -1,17 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 -# Generates a small Makefile used in the root of the output -# directory, to allow make to be started from there. -# The Makefile also allow for more convinient build of external modules - -# Usage -# $1 - Kernel src directory - -if [ "${quiet}" != "silent_" ]; then - echo " GEN Makefile" -fi - -cat << EOF > Makefile -# Automatically generated by $0: don't edit -include $1/Makefile -EOF --2.27.0
Signature · 2 lines
Best Regards Masahiro Yamada