[PATCH] Makefile: avoid non-standard sed expressions

The '?' that is used in the sed expression that determines MK_ARCH is part of the extended regular expression syntax, but the default behaviour of sed as specified by POSIX is to use only basic regular expression syntax. Use the equivalent '{0,1}' instead as suggested by the OpenBSD re_format(7) man page.
Fixes: 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache") Signed-off-by: Mark Kettenis kettenis@openbsd.org --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index 22953bdabd8..7933ade6eff 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ include include/host_arch.h ifeq ("", "$(CROSS_COMPILE)") MK_ARCH="${shell uname -m}" else - MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^(ccache)?[[:space:]]*([^/]*/)*([^-]*)-[^[:space:]]*/\3/p'}" + MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^(ccache){0,1}[[:space:]]*([^/]*/)*([^-]*)-[^[:space:]]*/\3/p'}" endif unexport HOST_ARCH ifeq ("x86_64", $(MK_ARCH))

On 11/26/24 8:12 PM, Mark Kettenis wrote:
The '?' that is used in the sed expression that determines MK_ARCH is part of the extended regular expression syntax, but the default behaviour of sed as specified by POSIX is to use only basic regular expression syntax. Use the equivalent '{0,1}' instead as suggested by the OpenBSD re_format(7) man page.
Fixes: 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache") Signed-off-by: Mark Kettenis kettenis@openbsd.org
Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index 22953bdabd8..7933ade6eff 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ include include/host_arch.h ifeq ("", "$(CROSS_COMPILE)") MK_ARCH="${shell uname -m}" else
- MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^(ccache)?[[:space:]]*([^/]*/)*([^-]*)-[^[:space:]]*/\3/p'}"
- MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^(ccache){0,1}[[:space:]]*([^/]*/)*([^-]*)-[^[:space:]]*/\3/p'}"
Interesting, and noted too, thanks.
Reviewed-by: Marek Vasut marex@denx.de

Hi Mark,
On 11/26/24 8:12 PM, Mark Kettenis wrote:
The '?' that is used in the sed expression that determines MK_ARCH is part of the extended regular expression syntax, but the default behaviour of sed as specified by POSIX is to use only basic regular expression syntax. Use the equivalent '{0,1}' instead as suggested by the OpenBSD re_format(7) man page.
Fixes: 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache")
Tested-by: Quentin Schulz quentin.schulz@cherry.de
Considering that it's not the first time someone breaks this by making it non-POSIX, can you add a comment just above with a link to the re_format(7) man page so people are at least more aware than they are right now?
Thanks! Quentin

Date: Wed, 27 Nov 2024 13:42:50 +0100 From: Quentin Schulz quentin.schulz@cherry.de
Hi Quentin,
Hi Mark,
On 11/26/24 8:12 PM, Mark Kettenis wrote:
The '?' that is used in the sed expression that determines MK_ARCH is part of the extended regular expression syntax, but the default behaviour of sed as specified by POSIX is to use only basic regular expression syntax. Use the equivalent '{0,1}' instead as suggested by the OpenBSD re_format(7) man page.
Fixes: 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache")
Tested-by: Quentin Schulz quentin.schulz@cherry.de
Considering that it's not the first time someone breaks this by making it non-POSIX, can you add a comment just above with a link to the re_format(7) man page so people are at least more aware than they are right now?
It is unfortunate that GNU sed has these extensions that are enabled by default. Just mentioning the OpenBSD man page is probably not going to help, but I guess I could put in a link to
https://man.openbsd.org/re_format
with a comment that only BREs should be used.
Cheers,
Mark
Thanks! Quentin

Hi Mark,
On 11/28/24 12:25 PM, Mark Kettenis wrote:
Date: Wed, 27 Nov 2024 13:42:50 +0100 From: Quentin Schulz quentin.schulz@cherry.de
Hi Quentin,
Hi Mark,
On 11/26/24 8:12 PM, Mark Kettenis wrote:
The '?' that is used in the sed expression that determines MK_ARCH is part of the extended regular expression syntax, but the default behaviour of sed as specified by POSIX is to use only basic regular expression syntax. Use the equivalent '{0,1}' instead as suggested by the OpenBSD re_format(7) man page.
Fixes: 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache")
Tested-by: Quentin Schulz quentin.schulz@cherry.de
Considering that it's not the first time someone breaks this by making it non-POSIX, can you add a comment just above with a link to the re_format(7) man page so people are at least more aware than they are right now?
It is unfortunate that GNU sed has these extensions that are enabled by default. Just mentioning the OpenBSD man page is probably not going to help, but I guess I could put in a link to
https://man.openbsd.org/re_format
with a comment that only BREs should be used.
What about adding --posix to the sed command. GNU sed has it, would that work with OpenBSD and is it enough? At least with GNU sed, ? doesn't work with --posix, and I had to replace it with {0,1} to make it work.
BREs don't seem to be entirely supported according to the manpage for GNU sed, c.f. https://www.man7.org/linux/man-pages/man1/sed.1.html#REGULAR_EXPRESSIONS so not sure it's a better than no hint :/
Cheers, Quentin

On Tue, 26 Nov 2024 20:12:14 +0100, Mark Kettenis wrote:
The '?' that is used in the sed expression that determines MK_ARCH is part of the extended regular expression syntax, but the default behaviour of sed as specified by POSIX is to use only basic regular expression syntax. Use the equivalent '{0,1}' instead as suggested by the OpenBSD re_format(7) man page.
[...]
Applied to u-boot/master, thanks!
participants (5)
-
Marek Vasut
-
Mark Kettenis
-
Mark Kettenis
-
Quentin Schulz
-
Tom Rini