2012-02-26 17:35:26

by Bernhard Walle

[permalink] [raw]
Subject: [PATCH] scripts/Kbuild.include: Fix portability problem of "echo -e"

"echo -e" is a GNU extension. When cross-compiling the kernel on a
BSD-like operating system (Mac OS X in my case), this doesn't work.

One could install a GNU version of echo, put that in the $PATH before
the system echo and use "/usr/bin/env echo", but the solution with
printf is simpler.

Since it is no disadvantage on Linux, I hope that gets accepted even if
cross-compiling the Linux kernel on another Unix operating system is
quite a rare use case.

Signed-off-by: Bernhard Walle <[email protected]>
---
scripts/Kbuild.include | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index d897278..6a3ee98 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -104,7 +104,7 @@ as-option = $(call try-run,\
# Usage: cflags-y += $(call as-instr,instr,option1,option2)

as-instr = $(call try-run,\
- /bin/echo -e "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
+ printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))

# cc-option
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
--
1.7.9


2012-02-26 17:48:09

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] scripts/Kbuild.include: Fix portability problem of "echo -e"

On Sun, Feb 26, 2012 at 06:35:18PM +0100, Bernhard Walle wrote:
> "echo -e" is a GNU extension. When cross-compiling the kernel on a
> BSD-like operating system (Mac OS X in my case), this doesn't work.
>
> One could install a GNU version of echo, put that in the $PATH before
> the system echo and use "/usr/bin/env echo", but the solution with
> printf is simpler.
>
> Since it is no disadvantage on Linux, I hope that gets accepted even if
> cross-compiling the Linux kernel on another Unix operating system is
> quite a rare use case.
>
> Signed-off-by: Bernhard Walle <[email protected]>
> ---
> scripts/Kbuild.include | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index d897278..6a3ee98 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -104,7 +104,7 @@ as-option = $(call try-run,\
> # Usage: cflags-y += $(call as-instr,instr,option1,option2)
>
> as-instr = $(call try-run,\
> - /bin/echo -e "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
> + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
>
> # cc-option
> # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)

Roman Zippel removed use of printf in this patch: beda9f3a13bbb22cde92a45f230a02ef2afef6a9

I cannot remember why - but it would be good if you could dig up
why - just so we do not hit an old issue again.

Sam

2012-02-26 17:52:57

by Bernhard Walle

[permalink] [raw]
Subject: Re: [PATCH] scripts/Kbuild.include: Fix portability problem of "echo -e"

Am 26.02.12 18:48, schrieb Sam Ravnborg:
>> > --- a/scripts/Kbuild.include
>> > +++ b/scripts/Kbuild.include
>> > @@ -104,7 +104,7 @@ as-option = $(call try-run,\
>> > # Usage: cflags-y += $(call as-instr,instr,option1,option2)
>> >
>> > as-instr = $(call try-run,\
>> > - /bin/echo -e "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
>> > + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
>> >
>> > # cc-option
>> > # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
> Roman Zippel removed use of printf in this patch: beda9f3a13bbb22cde92a45f230a02ef2afef6a9
>
> I cannot remember why - but it would be good if you could dig up
> why - just so we do not hit an old issue again.

Well, he used printf "$(1)", that's different from printf "%b\n" "$(1)"
since format strings inside $(1) would be interpreted.

But maybe Roman can comment on that? Cc'ing him.


Regards,
Bernhard


2012-02-26 21:05:54

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] scripts/Kbuild.include: Fix portability problem of "echo -e"

On Sun, Feb 26, 2012 at 06:51:34PM +0100, Bernhard Walle wrote:
> Am 26.02.12 18:48, schrieb Sam Ravnborg:
> >> > --- a/scripts/Kbuild.include
> >> > +++ b/scripts/Kbuild.include
> >> > @@ -104,7 +104,7 @@ as-option = $(call try-run,\
> >> > # Usage: cflags-y += $(call as-instr,instr,option1,option2)
> >> >
> >> > as-instr = $(call try-run,\
> >> > - /bin/echo -e "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
> >> > + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
> >> >
> >> > # cc-option
> >> > # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
> > Roman Zippel removed use of printf in this patch: beda9f3a13bbb22cde92a45f230a02ef2afef6a9
> >
> > I cannot remember why - but it would be good if you could dig up
> > why - just so we do not hit an old issue again.
>
> Well, he used printf "$(1)", that's different from printf "%b\n" "$(1)"
> since format strings inside $(1) would be interpreted.
Makes good sense.

>
> But maybe Roman can comment on that? Cc'ing him.
Would be good to hear from Roman - but he has been MIA for some years now :-(

Sam

2012-02-28 23:37:38

by Andreas Bießmann

[permalink] [raw]
Subject: Re: [PATCH] scripts/Kbuild.include: Fix portability problem of "echo -e"


On 26.02.12 18:35, Bernhard Walle wrote:
> "echo -e" is a GNU extension. When cross-compiling the kernel on a
> BSD-like operating system (Mac OS X in my case), this doesn't work.
>
> One could install a GNU version of echo, put that in the $PATH before
> the system echo and use "/usr/bin/env echo", but the solution with
> printf is simpler.
>
> Since it is no disadvantage on Linux, I hope that gets accepted even if
> cross-compiling the Linux kernel on another Unix operating system is
> quite a rare use case.
>
> Signed-off-by: Bernhard Walle <[email protected]>

Tested-by: Andreas Bie?mann <[email protected]>

Without that patch cross-compiling kernel for omap2 devices on BSD-style
hosts is broken.
For x86 targets the impact is not that hard but CFI is omitted even
though it is supported by assembler (in one case this led to a devious
error message pointing to a assembler bug in my cross toolchain).

So please consider applying this patch.