All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kbuild: single-quote the format string of printf
@ 2023-08-29 11:35 ` Masahiro Yamada
  0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2023-08-29 11:35 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, Masahiro Yamada, Christophe Leroy,
	Michael Ellerman, Nathan Chancellor, Nicholas Piggin,
	Nick Desaulniers, Nicolas Schier, linuxppc-dev

Use single-quotes to avoid escape sequences (\\n).

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

 Makefile              | 8 ++++----
 arch/powerpc/Makefile | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 87a9eef3fb4b..d09600f7a036 100644
--- a/Makefile
+++ b/Makefile
@@ -1643,12 +1643,12 @@ help:
 	@echo  ''
 	@$(if $(boards), \
 		$(foreach b, $(boards), \
-		printf "  %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
+		printf '  %-27s - Build for %s\n' $(b) $(subst _defconfig,,$(b));) \
 		echo '')
 	@$(if $(board-dirs), \
 		$(foreach b, $(board-dirs), \
-		printf "  %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
-		printf "  %-16s - Show all of the above\\n" help-boards; \
+		printf '  %-16s - Show %s-specific targets\n' help-$(b) $(b);) \
+		printf '  %-16s - Show all of the above\n' help-boards; \
 		echo '')
 
 	@echo  '  make V=n   [targets] 1: verbose build'
@@ -1684,7 +1684,7 @@ $(help-board-dirs): help-%:
 	@echo  'Architecture specific targets ($(SRCARCH) $*):'
 	@$(if $(boards-per-dir), \
 		$(foreach b, $(boards-per-dir), \
-		printf "  %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
+		printf '  %-24s - Build for %s\n' $*/$(b) $(subst _defconfig,,$(b));) \
 		echo '')
 
 
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index dac7ca153886..f49ac05eae20 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -353,7 +353,7 @@ define archhelp
   echo '  (minus the .dts extension).'
   echo
   $(foreach cfg,$(generated_configs),
-    printf "  %-27s - Build for %s\\n" $(cfg) $(subst _defconfig,,$(cfg));)
+    printf '  %-27s - Build for %s\n' $(cfg) $(subst _defconfig,,$(cfg));)
 endef
 
 PHONY += install
-- 
2.39.2


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

* [PATCH] kbuild: single-quote the format string of printf
@ 2023-08-29 11:35 ` Masahiro Yamada
  0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2023-08-29 11:35 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Nicolas Schier, Masahiro Yamada, Nick Desaulniers, linux-kernel,
	Nicholas Piggin, Nathan Chancellor, linuxppc-dev

Use single-quotes to avoid escape sequences (\\n).

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

 Makefile              | 8 ++++----
 arch/powerpc/Makefile | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 87a9eef3fb4b..d09600f7a036 100644
--- a/Makefile
+++ b/Makefile
@@ -1643,12 +1643,12 @@ help:
 	@echo  ''
 	@$(if $(boards), \
 		$(foreach b, $(boards), \
-		printf "  %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
+		printf '  %-27s - Build for %s\n' $(b) $(subst _defconfig,,$(b));) \
 		echo '')
 	@$(if $(board-dirs), \
 		$(foreach b, $(board-dirs), \
-		printf "  %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
-		printf "  %-16s - Show all of the above\\n" help-boards; \
+		printf '  %-16s - Show %s-specific targets\n' help-$(b) $(b);) \
+		printf '  %-16s - Show all of the above\n' help-boards; \
 		echo '')
 
 	@echo  '  make V=n   [targets] 1: verbose build'
@@ -1684,7 +1684,7 @@ $(help-board-dirs): help-%:
 	@echo  'Architecture specific targets ($(SRCARCH) $*):'
 	@$(if $(boards-per-dir), \
 		$(foreach b, $(boards-per-dir), \
-		printf "  %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
+		printf '  %-24s - Build for %s\n' $*/$(b) $(subst _defconfig,,$(b));) \
 		echo '')
 
 
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index dac7ca153886..f49ac05eae20 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -353,7 +353,7 @@ define archhelp
   echo '  (minus the .dts extension).'
   echo
   $(foreach cfg,$(generated_configs),
-    printf "  %-27s - Build for %s\\n" $(cfg) $(subst _defconfig,,$(cfg));)
+    printf '  %-27s - Build for %s\n' $(cfg) $(subst _defconfig,,$(cfg));)
 endef
 
 PHONY += install
-- 
2.39.2


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

* Re: [PATCH] kbuild: single-quote the format string of printf
  2023-08-29 11:35 ` Masahiro Yamada
@ 2023-08-29 12:00   ` Nicolas Schier
  -1 siblings, 0 replies; 7+ messages in thread
From: Nicolas Schier @ 2023-08-29 12:00 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, linux-kernel, Christophe Leroy, Michael Ellerman,
	Nathan Chancellor, Nicholas Piggin, Nick Desaulniers,
	linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 4691 bytes --]

On Tue 29 Aug 2023 20:35:31 GMT, Masahiro Yamada wrote:
> Use single-quotes to avoid escape sequences (\\n).
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---

Is this really necessary?  Testing w/ GNU Make 4.3, bash 5.2.15 or
dash 0.5.12-6 and a stupid Makefile snippet I cannot see any difference 
between these three:

print:
	@printf "hello med single-backslash and double quotes\n"
	@printf 'hello med single-backslash and single quotes\n'
	@printf "hello med double-backslash and double quotes\\n"

Only double-backslash+n in single-quotes does not work, for obvious 
reasons.

Is this some compatibility to older make versions or other shells?

Iff it is, we should have several cases that are actually broken right 
now:

$ git grep -Hrne 'printf.*".*\\n' '**/Makefile*' '**/Kbuild*' 
arch/mips/Makefile:480:   printf "  %-24s - Build generic kernel for $(call describe_generic_defconfig,$(cfg))\n" $(cfg);)
arch/mips/Makefile:486:   printf "  %-24s - Build $($(cfg)-y)\n" $(cfg);)
samples/bpf/Makefile:238:HDR_PROBE := $(shell printf "$(pound)include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
samples/hid/Makefile:76:HDR_PROBE := $(shell printf "$(pound)include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
scripts/Makefile.compiler:41:   printf "%b\n" "$(1)" | $(CC) -Werror $(CLANG_FLAGS) $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
scripts/Makefile.lib:437:printf "%08x\n" $$dec_size |                                           \
scripts/Makefile.modfinal:43:           printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
scripts/Makefile.modfinal:45:           printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \
security/tomoyo/Makefile:11:    printf '\t"";\n';) \
tools/testing/selftests/Makefile:263:           [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
tools/testing/selftests/Makefile:264:           printf "Emit Tests for $$TARGET\n"; \
tools/testing/selftests/nolibc/Makefile:136:             if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
tools/testing/selftests/nolibc/Makefile:155:             if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
tools/testing/selftests/nolibc/Makefile:163:             if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
tools/testing/selftests/wireguard/qemu/Makefile:335:    printf 'CONFIG_NR_CPUS=$(NR_CPUS)\nCONFIG_INITRAMFS_SOURCE="$(BUILD_PATH)/init-cpio-spec.txt"\n' >> $(KERNEL_BUILD_PATH)/minimal.config

I assume, that changing '\\n' occurrences in all Makefiles to '\n' 
should be enough; but only a cosmetic change.  Or did I miss some
point?

Kind regards,
Nicolas


> 
>  Makefile              | 8 ++++----
>  arch/powerpc/Makefile | 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 87a9eef3fb4b..d09600f7a036 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1643,12 +1643,12 @@ help:
>  	@echo  ''
>  	@$(if $(boards), \
>  		$(foreach b, $(boards), \
> -		printf "  %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
> +		printf '  %-27s - Build for %s\n' $(b) $(subst _defconfig,,$(b));) \
>  		echo '')
>  	@$(if $(board-dirs), \
>  		$(foreach b, $(board-dirs), \
> -		printf "  %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
> -		printf "  %-16s - Show all of the above\\n" help-boards; \
> +		printf '  %-16s - Show %s-specific targets\n' help-$(b) $(b);) \
> +		printf '  %-16s - Show all of the above\n' help-boards; \
>  		echo '')
>  
>  	@echo  '  make V=n   [targets] 1: verbose build'
> @@ -1684,7 +1684,7 @@ $(help-board-dirs): help-%:
>  	@echo  'Architecture specific targets ($(SRCARCH) $*):'
>  	@$(if $(boards-per-dir), \
>  		$(foreach b, $(boards-per-dir), \
> -		printf "  %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
> +		printf '  %-24s - Build for %s\n' $*/$(b) $(subst _defconfig,,$(b));) \
>  		echo '')
>  
>  
> diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
> index dac7ca153886..f49ac05eae20 100644
> --- a/arch/powerpc/Makefile
> +++ b/arch/powerpc/Makefile
> @@ -353,7 +353,7 @@ define archhelp
>    echo '  (minus the .dts extension).'
>    echo
>    $(foreach cfg,$(generated_configs),
> -    printf "  %-27s - Build for %s\\n" $(cfg) $(subst _defconfig,,$(cfg));)
> +    printf '  %-27s - Build for %s\n' $(cfg) $(subst _defconfig,,$(cfg));)
>  endef
>  
>  PHONY += install
> -- 
> 2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] kbuild: single-quote the format string of printf
@ 2023-08-29 12:00   ` Nicolas Schier
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Schier @ 2023-08-29 12:00 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Nick Desaulniers, linux-kernel, Nicholas Piggin,
	Nathan Chancellor, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 4691 bytes --]

On Tue 29 Aug 2023 20:35:31 GMT, Masahiro Yamada wrote:
> Use single-quotes to avoid escape sequences (\\n).
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---

Is this really necessary?  Testing w/ GNU Make 4.3, bash 5.2.15 or
dash 0.5.12-6 and a stupid Makefile snippet I cannot see any difference 
between these three:

print:
	@printf "hello med single-backslash and double quotes\n"
	@printf 'hello med single-backslash and single quotes\n'
	@printf "hello med double-backslash and double quotes\\n"

Only double-backslash+n in single-quotes does not work, for obvious 
reasons.

Is this some compatibility to older make versions or other shells?

Iff it is, we should have several cases that are actually broken right 
now:

$ git grep -Hrne 'printf.*".*\\n' '**/Makefile*' '**/Kbuild*' 
arch/mips/Makefile:480:   printf "  %-24s - Build generic kernel for $(call describe_generic_defconfig,$(cfg))\n" $(cfg);)
arch/mips/Makefile:486:   printf "  %-24s - Build $($(cfg)-y)\n" $(cfg);)
samples/bpf/Makefile:238:HDR_PROBE := $(shell printf "$(pound)include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
samples/hid/Makefile:76:HDR_PROBE := $(shell printf "$(pound)include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
scripts/Makefile.compiler:41:   printf "%b\n" "$(1)" | $(CC) -Werror $(CLANG_FLAGS) $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3))
scripts/Makefile.lib:437:printf "%08x\n" $$dec_size |                                           \
scripts/Makefile.modfinal:43:           printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
scripts/Makefile.modfinal:45:           printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \
security/tomoyo/Makefile:11:    printf '\t"";\n';) \
tools/testing/selftests/Makefile:263:           [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
tools/testing/selftests/Makefile:264:           printf "Emit Tests for $$TARGET\n"; \
tools/testing/selftests/nolibc/Makefile:136:             if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
tools/testing/selftests/nolibc/Makefile:155:             if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
tools/testing/selftests/nolibc/Makefile:163:             if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
tools/testing/selftests/wireguard/qemu/Makefile:335:    printf 'CONFIG_NR_CPUS=$(NR_CPUS)\nCONFIG_INITRAMFS_SOURCE="$(BUILD_PATH)/init-cpio-spec.txt"\n' >> $(KERNEL_BUILD_PATH)/minimal.config

I assume, that changing '\\n' occurrences in all Makefiles to '\n' 
should be enough; but only a cosmetic change.  Or did I miss some
point?

Kind regards,
Nicolas


> 
>  Makefile              | 8 ++++----
>  arch/powerpc/Makefile | 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 87a9eef3fb4b..d09600f7a036 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1643,12 +1643,12 @@ help:
>  	@echo  ''
>  	@$(if $(boards), \
>  		$(foreach b, $(boards), \
> -		printf "  %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
> +		printf '  %-27s - Build for %s\n' $(b) $(subst _defconfig,,$(b));) \
>  		echo '')
>  	@$(if $(board-dirs), \
>  		$(foreach b, $(board-dirs), \
> -		printf "  %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
> -		printf "  %-16s - Show all of the above\\n" help-boards; \
> +		printf '  %-16s - Show %s-specific targets\n' help-$(b) $(b);) \
> +		printf '  %-16s - Show all of the above\n' help-boards; \
>  		echo '')
>  
>  	@echo  '  make V=n   [targets] 1: verbose build'
> @@ -1684,7 +1684,7 @@ $(help-board-dirs): help-%:
>  	@echo  'Architecture specific targets ($(SRCARCH) $*):'
>  	@$(if $(boards-per-dir), \
>  		$(foreach b, $(boards-per-dir), \
> -		printf "  %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
> +		printf '  %-24s - Build for %s\n' $*/$(b) $(subst _defconfig,,$(b));) \
>  		echo '')
>  
>  
> diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
> index dac7ca153886..f49ac05eae20 100644
> --- a/arch/powerpc/Makefile
> +++ b/arch/powerpc/Makefile
> @@ -353,7 +353,7 @@ define archhelp
>    echo '  (minus the .dts extension).'
>    echo
>    $(foreach cfg,$(generated_configs),
> -    printf "  %-27s - Build for %s\\n" $(cfg) $(subst _defconfig,,$(cfg));)
> +    printf '  %-27s - Build for %s\n' $(cfg) $(subst _defconfig,,$(cfg));)
>  endef
>  
>  PHONY += install
> -- 
> 2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] kbuild: single-quote the format string of printf
  2023-08-29 12:00   ` Nicolas Schier
@ 2023-08-30 11:33     ` Masahiro Yamada
  -1 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2023-08-30 11:33 UTC (permalink / raw)
  To: Nicolas Schier
  Cc: linux-kbuild, Nick Desaulniers, linux-kernel, Nicholas Piggin,
	Nathan Chancellor, linuxppc-dev

On Wed, Aug 30, 2023 at 10:00 AM Nicolas Schier <nicolas@fjasle.eu> wrote:
>
> On Tue 29 Aug 2023 20:35:31 GMT, Masahiro Yamada wrote:
> > Use single-quotes to avoid escape sequences (\\n).
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
>
> Is this really necessary?  Testing w/ GNU Make 4.3, bash 5.2.15 or
> dash 0.5.12-6 and a stupid Makefile snippet I cannot see any difference
> between these three:
>
> print:
>         @printf "hello med single-backslash and double quotes\n"
>         @printf 'hello med single-backslash and single quotes\n'
>         @printf "hello med double-backslash and double quotes\\n"
>
> Only double-backslash+n in single-quotes does not work, for obvious
> reasons.


You are right.

I was misunderstanding the backslash-escaping in double-quotes.

I always used single-quotes when I wanted to avoid
escape sequences.

The following POSIX spec applies here:


  2.2.3 Double-Quotes

  The <backslash> shall retain its special meaning as an escape character
  (see Escape Character (Backslash)) only when followed by one of the
  following characters when considered special:

  $   `   "   \   <newline>




https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html


All of "\\n", "\n", '\n' are the same.



-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH] kbuild: single-quote the format string of printf
@ 2023-08-30 11:33     ` Masahiro Yamada
  0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2023-08-30 11:33 UTC (permalink / raw)
  To: Nicolas Schier
  Cc: linux-kbuild, linux-kernel, Christophe Leroy, Michael Ellerman,
	Nathan Chancellor, Nicholas Piggin, Nick Desaulniers,
	linuxppc-dev

On Wed, Aug 30, 2023 at 10:00 AM Nicolas Schier <nicolas@fjasle.eu> wrote:
>
> On Tue 29 Aug 2023 20:35:31 GMT, Masahiro Yamada wrote:
> > Use single-quotes to avoid escape sequences (\\n).
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
>
> Is this really necessary?  Testing w/ GNU Make 4.3, bash 5.2.15 or
> dash 0.5.12-6 and a stupid Makefile snippet I cannot see any difference
> between these three:
>
> print:
>         @printf "hello med single-backslash and double quotes\n"
>         @printf 'hello med single-backslash and single quotes\n'
>         @printf "hello med double-backslash and double quotes\\n"
>
> Only double-backslash+n in single-quotes does not work, for obvious
> reasons.


You are right.

I was misunderstanding the backslash-escaping in double-quotes.

I always used single-quotes when I wanted to avoid
escape sequences.

The following POSIX spec applies here:


  2.2.3 Double-Quotes

  The <backslash> shall retain its special meaning as an escape character
  (see Escape Character (Backslash)) only when followed by one of the
  following characters when considered special:

  $   `   "   \   <newline>




https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html


All of "\\n", "\n", '\n' are the same.



-- 
Best Regards
Masahiro Yamada

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

* RE: [PATCH] kbuild: single-quote the format string of printf
  2023-08-30 11:33     ` Masahiro Yamada
  (?)
@ 2023-08-30 13:00     ` David Laight
  -1 siblings, 0 replies; 7+ messages in thread
From: David Laight @ 2023-08-30 13:00 UTC (permalink / raw)
  To: 'Masahiro Yamada', Nicolas Schier
  Cc: linux-kbuild, Nick Desaulniers, linux-kernel, Nicholas Piggin,
	Nathan Chancellor, linuxppc-dev

...
> All of "\\n", "\n", '\n' are the same.

and \\n (without any quote characters at all).

Personally I'd use 'format' for printf.
To make it obvious that nothing is to be expanded.
But it isn't really worth changing existing 'stuff'.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

end of thread, other threads:[~2023-08-30 19:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-29 11:35 [PATCH] kbuild: single-quote the format string of printf Masahiro Yamada
2023-08-29 11:35 ` Masahiro Yamada
2023-08-29 12:00 ` Nicolas Schier
2023-08-29 12:00   ` Nicolas Schier
2023-08-30 11:33   ` Masahiro Yamada
2023-08-30 11:33     ` Masahiro Yamada
2023-08-30 13:00     ` David Laight

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.