Browse Source

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 <[email protected]>
Steffen Jaeckel 2 years ago
parent
commit
c48673234c
1 changed files with 8 additions and 9 deletions
  1. 8 9
      makefile_include.mk

+ 8 - 9
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