All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Makefile: Fix POSIX grep alternation regex
@ 2024-11-11 19:37 Igor Melnikov
  2024-11-11 23:13 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Igor Melnikov @ 2024-11-11 19:37 UTC (permalink / raw)
  To: opensbi

grep -e "-mstrict-align\|-mno-unaligned-access" makes use of GNU grep's
backslash-escaped alternation operator \| which is available in basic
regular expression syntax (BRE).

However, in POSIX grep's BRE | is an ordinary character which, when
backslash-escaped, matches itself. Therefore, the search pattern becomes
a plain string '-mstrict-align|-mno-unaligned-access', which obviously
never matches the expected error and CC_SUPPORT_STRICT _ALIGN is always
set to y.

When cross-compiling with LLVM on amd64-unknown-openbsd7.6 host for
riscv64-unknown-elf target this results in a compilation error:

clang: error: unsupported option '-mno-unaligned-access' for target
'riscv64-unknown-elf'

Using grep -E for extended regular expression syntax with non-escaped
alternation operator | lets both versions interpret the pattern
 unambiguously and the check to function properly on systems with POSIX
 grep as well.

Signed-off-by: Igor Melnikov <imel@purelymail.com>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index dae282c..6371f6f 100644
--- a/Makefile
+++ b/Makefile
@@ -184,10 +184,10 @@ OPENSBI_LD_EXCLUDE_LIBS := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_
 CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep -e "-save-restore" >/dev/null && echo n || echo y)
 
 # Check whether the compiler supports -m(no-)strict-align
-CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -e "-mstrict-align\|-mno-unaligned-access" >/dev/null && echo n || echo y)
+CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -Ee "-mstrict-align|-mno-unaligned-access" >/dev/null && echo n || echo y)
 
 # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions
-CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y)
+CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -E "zicsr|zifencei" > /dev/null && echo n || echo y)
 
 ifneq ($(OPENSBI_LD_PIE),y)
 $(error Your linker does not support creating PIEs, opensbi requires this.)
-- 
2.46.1



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

* [PATCH] Makefile: Fix POSIX grep alternation regex
  2024-11-11 19:37 [PATCH] Makefile: Fix POSIX grep alternation regex Igor Melnikov
@ 2024-11-11 23:13 ` Andreas Schwab
  2024-11-14 11:46   ` Igor Melnikov
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2024-11-11 23:13 UTC (permalink / raw)
  To: opensbi

On Nov 11 2024, Igor Melnikov wrote:

> Using grep -E for extended regular expression syntax with non-escaped
> alternation operator | lets both versions interpret the pattern
>  unambiguously and the check to function properly on systems with POSIX
>  grep as well.

Alternatively, you can use multiple -e options.  This works even with
traditional grep implementations.

-- 
Andreas Schwab, schwab at linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


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

* [PATCH] Makefile: Fix POSIX grep alternation regex
  2024-11-11 23:13 ` Andreas Schwab
@ 2024-11-14 11:46   ` Igor Melnikov
  2024-11-28  6:40     ` Anup Patel
  0 siblings, 1 reply; 4+ messages in thread
From: Igor Melnikov @ 2024-11-14 11:46 UTC (permalink / raw)
  To: opensbi

On Tue, Nov 12, 2024 at 12:13:14AM +0100, Andreas Schwab wrote:
 
> Alternatively, you can use multiple -e options.  This works even with
> traditional grep implementations.
 
This might be a bit more elegant. Should I re-submit the patch?


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

* [PATCH] Makefile: Fix POSIX grep alternation regex
  2024-11-14 11:46   ` Igor Melnikov
@ 2024-11-28  6:40     ` Anup Patel
  0 siblings, 0 replies; 4+ messages in thread
From: Anup Patel @ 2024-11-28  6:40 UTC (permalink / raw)
  To: opensbi

On Thu, Nov 14, 2024 at 5:30?PM Igor Melnikov <imel@purelymail.com> wrote:
>
> On Tue, Nov 12, 2024 at 12:13:14AM +0100, Andreas Schwab wrote:
>
> > Alternatively, you can use multiple -e options.  This works even with
> > traditional grep implementations.
>
> This might be a bit more elegant. Should I re-submit the patch?

Yes, please re-submit with the modification as v2 patch.

Regards,
Anup


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

end of thread, other threads:[~2024-11-28  6:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-11 19:37 [PATCH] Makefile: Fix POSIX grep alternation regex Igor Melnikov
2024-11-11 23:13 ` Andreas Schwab
2024-11-14 11:46   ` Igor Melnikov
2024-11-28  6:40     ` Anup Patel

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.