Skip to contentSkip to conversation

Makefile: avoid non-standard sed expressions

PATCH In review Mark Kettenis 5 participants 6 messages Nov 26, 2024 – Nov 30, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 22953bdabd8..7933ade6eff 100644
@@ -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))
Signature · 1 line
2.47.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Mark Kettenis

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")
---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 22953bdabd8..7933ade6eff 100644

Makefile include include/host_arch.h · line 24

Quoted 5 lines
Makefile +1 -1
@@ -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.

Tested-by on v1 1/1
#2 lore raw
In reply to Mark Kettenis

Hi Mark,

Quoted 7 lines · Mark Kettenis

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")

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

#3 lore raw
Quoted 2 lines

Date: Wed, 27 Nov 2024 13:42:50 +0100
From: Quentin Schulz <[email protected]>

Hi Quentin,

Quoted 9 lines

Hi Mark,

Quoted 6 lines · Mark Kettenis

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.

Quoted 8 lines
Quoted 1 line
Fixes 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache")

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

Quoted 4 lines

Thanks!
Quentin

#4 lore raw

Hi Mark,

Quoted 23 lines · Mark Kettenis
Quoted 2 lines

Date: Wed, 27 Nov 2024 13:42:50 +0100
From: Quentin Schulz <[email protected]>

Hi Quentin,

Quoted 9 lines

Hi Mark,

Quoted 6 lines · Mark Kettenis

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.

Quoted 8 lines
Quoted 1 line
Fixes 04b1d84221d5 ("Makefile: fix empty MK_ARCH when using ccache")

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?

Quoted 8 lines

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

#5 lore raw
In reply to Mark Kettenis
Quoted 8 lines · Mark Kettenis

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!

Signature · 1 line
Tom