From c48673234c03e5226c767ed54bd55a15290aecac Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 4 Oct 2023 15:33:13 +0200 Subject: [PATCH] Always determine manually whether CC is clang This is required 1. when cross-compiling 2. to enable/disable the specific compiler warnings Tested on `bash`, `dash`, `zsh` and FreeBSD `sh`. Signed-off-by: Steffen Jaeckel --- makefile_include.mk | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/makefile_include.mk b/makefile_include.mk index f933b36b6..e4e7ad34a 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -13,16 +13,15 @@ ifndef CROSS_COMPILE CROSS_COMPILE:= endif -# We only need to go through this dance of determining the right compiler if we're using -# cross compilation, otherwise $(CC) is fine as-is. +ifneq (,$(shell printf "#ifdef __clang__\nCLANG\n#endif\n" | $(CC) -E - | grep CLANG)) + CC_IS_CLANG := 1 +else + CC_IS_CLANG := 0 +endif # Clang + ifneq (,$(CROSS_COMPILE)) ifeq ($(origin CC),default) -CSTR := "\#ifdef __clang__\nCLANG\n\#endif\n" -ifeq ($(PLATFORM),FreeBSD) - # XXX: FreeBSD needs extra escaping for some reason - CSTR := $$$(CSTR) -endif -ifneq (,$(shell echo $(CSTR) | $(CC) -E - | grep CLANG)) +ifeq ($(CC_IS_CLANG), 1) CC := $(CROSS_COMPILE)clang else CC := $(CROSS_COMPILE)gcc @@ -124,7 +123,7 @@ LTC_CFLAGS += -Os -DLTC_SMALL_CODE endif # LTC_SMALL -ifneq ($(findstring clang,$(CC)),) +ifeq ($(CC_IS_CLANG), 1) LTC_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header LTC_CFLAGS += -Wno-missing-field-initializers -Wno-missing-braces -Wno-incomplete-setjmp-declaration -Wno-cast-align LTC_CFLAGS += -Wno-declaration-after-statement