All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile
@ 2021-05-17  7:03 Masahiro Yamada
  2021-05-17  7:03 ` [PATCH 2/4] init: use $(call cmd,) for generating include/generated/compile.h Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Masahiro Yamada @ 2021-05-17  7:03 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Arnd Bergmann, Masahiro Yamada, Michal Marek, linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile           | 15 ++++++++++++---
 scripts/mkmakefile | 17 -----------------
 2 files changed, 12 insertions(+), 20 deletions(-)
 delete mode 100755 scripts/mkmakefile

diff --git a/Makefile b/Makefile
index 15b6476d0f89..50776cc3e894 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
deleted file mode 100755
index 1cb174751429..000000000000
--- a/scripts/mkmakefile
+++ /dev/null
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] init: use $(call cmd,) for generating include/generated/compile.h
  2021-05-17  7:03 [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
@ 2021-05-17  7:03 ` Masahiro Yamada
  2021-05-17  7:03 ` [PATCH 3/4] kbuild: sink stdout from cmd for silent build Masahiro Yamada
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2021-05-17  7:03 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Arnd Bergmann, Masahiro Yamada, Song Liu, linux-kernel

The 'cmd' macro shows the short log only when $(quiet) is quiet_.
Do not do it manually.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 init/Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/init/Makefile b/init/Makefile
index 6bc37f64b361..2846113677ee 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -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)
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] kbuild: sink stdout from cmd for silent build
  2021-05-17  7:03 [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
  2021-05-17  7:03 ` [PATCH 2/4] init: use $(call cmd,) for generating include/generated/compile.h Masahiro Yamada
@ 2021-05-17  7:03 ` Masahiro Yamada
  2021-05-17  7:03 ` [PATCH 4/4] kbuild: clean up ${quiet} checks in shell scripts Masahiro Yamada
  2021-05-26 14:29 ` [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2021-05-17  7:03 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Arnd Bergmann, Masahiro Yamada, Michal Marek, linux-kernel

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 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/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.

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/20210514135752.2910387-1-arnd@kernel.org/

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Kbuild.include | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 82dd1b65b7a8..f247e691562d 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -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
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] kbuild: clean up ${quiet} checks in shell scripts
  2021-05-17  7:03 [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
  2021-05-17  7:03 ` [PATCH 2/4] init: use $(call cmd,) for generating include/generated/compile.h Masahiro Yamada
  2021-05-17  7:03 ` [PATCH 3/4] kbuild: sink stdout from cmd for silent build Masahiro Yamada
@ 2021-05-17  7:03 ` Masahiro Yamada
  2021-05-26 14:29 ` [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2021-05-17  7:03 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Arnd Bergmann, Masahiro Yamada, Alexey Dobriyan, Denis Efremov,
	Michal Marek, linux-kernel

There 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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 kernel/gen_kheaders.sh  | 4 +---
 scripts/link-vmlinux.sh | 4 +---
 scripts/mkcompile_h     | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/kernel/gen_kheaders.sh b/kernel/gen_kheaders.sh
index 34a1dc2abc7d..1966a749e0d9 100755
--- a/kernel/gen_kheaders.sh
+++ b/kernel/gen_kheaders.sh
@@ -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
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index f4de4c97015b..3b342b0b0b38 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -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.
diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
index 4ae735039daf..06bbf4c2c66c 100755
--- a/scripts/mkcompile_h
+++ b/scripts/mkcompile_h
@@ -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
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile
  2021-05-17  7:03 [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
                   ` (2 preceding siblings ...)
  2021-05-17  7:03 ` [PATCH 4/4] kbuild: clean up ${quiet} checks in shell scripts Masahiro Yamada
@ 2021-05-26 14:29 ` Masahiro Yamada
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2021-05-26 14:29 UTC (permalink / raw)
  To: Linux Kbuild mailing list
  Cc: Arnd Bergmann, Michal Marek, Linux Kernel Mailing List

On Mon, May 17, 2021 at 4:03 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> 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.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---

Applied to linux-kbuild.


>  Makefile           | 15 ++++++++++++---
>  scripts/mkmakefile | 17 -----------------
>  2 files changed, 12 insertions(+), 20 deletions(-)
>  delete mode 100755 scripts/mkmakefile
>
> diff --git a/Makefile b/Makefile
> index 15b6476d0f89..50776cc3e894 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
> diff --git a/scripts/mkmakefile b/scripts/mkmakefile
> deleted file mode 100755
> index 1cb174751429..000000000000
> --- a/scripts/mkmakefile
> +++ /dev/null
> @@ -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
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-26 14:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  7:03 [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada
2021-05-17  7:03 ` [PATCH 2/4] init: use $(call cmd,) for generating include/generated/compile.h Masahiro Yamada
2021-05-17  7:03 ` [PATCH 3/4] kbuild: sink stdout from cmd for silent build Masahiro Yamada
2021-05-17  7:03 ` [PATCH 4/4] kbuild: clean up ${quiet} checks in shell scripts Masahiro Yamada
2021-05-26 14:29 ` [PATCH 1/4] kbuild: merge scripts/mkmakefile to top Makefile Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.