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 <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel 2023-10-04 15:33:13 +02:00 committed by Jamie Reece Wilson
parent 4be2367a5a
commit 61f764d37f

View File

@ -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