Skip to content

Commit

Permalink
mkcompile_h: use printf for LINUX_COMPILE_BY
Browse files Browse the repository at this point in the history
Commit 858805b ("kbuild: add $(BASH) to run scripts with
bash-extension") shed light on portability issues. Here is another one.

Since commit f077260 ("Fix handling of backlash character in
LINUX_COMPILE_BY name"), we must escape a backslash contained in
LINUX_COMPILE_BY. This is not working on such distros as Ubuntu.

As the POSIX spec [1] says, if any of the operands contain a backslash
( '\' ) character, the results are implementation-defined.

The actual shell of /bin/sh could be bash, dash, etc. depending on
distros, and the behavior of builtin echo command is different among
them.

The bash builtin echo, unless -e is given, copies the arguments to
stdout without expanding escape sequences (BSD-like behavior).

The dash builtin echo, in contrast, adopts System V behavior, which
does expand escape sequences without any option given.

Even non-builtin /bin/echo behaves differently depending on the system.
Due to these variations, echo is considered as a non-portable command.
Using printf is the common solution to avoid the portability issue.

[1] https://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html

Fixes: 858805b ("kbuild: add $(BASH) to run scripts with bash-extension")
Reported-by: XXing Wei <[email protected]>
Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y committed Dec 14, 2019
1 parent e819365 commit c8f3dea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/mkcompile_h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"

echo \#define UTS_VERSION \"$UTS_VERSION\"

echo \#define LINUX_COMPILE_BY \"$LINUX_COMPILE_BY\"
printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"

echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
Expand Down

0 comments on commit c8f3dea

Please sign in to comment.