Skip to content

Commit

Permalink
Always determine manually whether CC is clang
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sjaeckel committed Oct 5, 2023
1 parent d3a297c commit c486732
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions makefile_include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c486732

Please sign in to comment.