From 57647cac622f94e14b5708b87d1d79c446b0eb88 Mon Sep 17 00:00:00 2001 From: Bertrand Jacquin Date: Sat, 6 Mar 2021 20:25:46 +0000 Subject: [PATCH] MINOR: build: force CC to set a return code when probing options gcc returns non zero code if an option is not supported (tested from 6.5 to 10.2). $ gcc -Wfoobar -E -xc - -o /dev/null < /dev/null > /dev/null 2>&1 ; echo $? 1 clang always return 0 if an option in not recognized unless -Werror is also passed, preventing a correct probing of options supported by the compiler (tested with clang 6.0.1 to 11.1.0). $ clang -Wfoobar -E -xc - -o /dev/null < /dev/null > /dev/null 2>&1 ; echo $? 0 $ clang -Werror -Wfoobar -E -xc - -o /dev/null < /dev/null > /dev/null 2>&1 ; echo $? 1 Please note today this is not visible since clang 11 exit with SIGABRT or with return code 1 on older version due to bad file descriptor from file descriptor handling $ clang -Wfoobar -E -xc - -o /dev/null < /dev/null 2>&0 ; echo $? Aborted (core dumped) 134 $ clang -Wfoobar -E -xc - -o /dev/null < /dev/null ; echo $? warning: unknown warning option '-Wfoobar'; did you mean '-Wformat'? [-Wunknown-warning-option] 1 warning generated. 0 $ clang-11 -Werror -Wfoobar -E -xc - -o /dev/null < /dev/null ; echo $? error: unknown warning option '-Wfoobar'; did you mean '-Wformat'? [-Werror,-Wunknown-warning-option] 1 This specific issue is being tracked with clang upstream in https://bugs.llvm.org/show_bug.cgi?id=49463 --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 77960ba4ca..0867047fdc 100644 --- a/Makefile +++ b/Makefile @@ -126,16 +126,16 @@ endif # Usage: CFLAGS += $(call cc-opt,option). Eg: $(call cc-opt,-fwrapv) # Note: ensure the referencing variable is assigned using ":=" and not "=" to # call it only once. -cc-opt = $(shell set -e; if $(CC) $(1) -E -xc - -o /dev/null &0 2>&0; then echo "$(1)"; fi;) +cc-opt = $(shell set -e; if $(CC) -Werror $(1) -E -xc - -o /dev/null &0 2>&0; then echo "$(1)"; fi;) # same but emits $2 if $1 is not supported -cc-opt-alt = $(shell set -e; if $(CC) $(1) -E -xc - -o /dev/null &0 2>&0; then echo "$(1)"; else echo "$(2)"; fi;) +cc-opt-alt = $(shell set -e; if $(CC) -Werror $(1) -E -xc - -o /dev/null &0 2>&0; then echo "$(1)"; else echo "$(2)"; fi;) # Disable a warning when supported by the compiler. Don't put spaces around the # warning! And don't use cc-opt which doesn't always report an error until # another one is also returned. # Usage: CFLAGS += $(call cc-nowarn,warning). Eg: $(call cc-opt,format-truncation) -cc-nowarn = $(shell set -e; if $(CC) -W$(1) -E -xc - -o /dev/null &0 2>&0; then echo "-Wno-$(1)"; fi;) +cc-nowarn = $(shell set -e; if $(CC) -Werror -W$(1) -E -xc - -o /dev/null &0 2>&0; then echo "-Wno-$(1)"; fi;) #### Installation options. DESTDIR =