From 5b8ec08d57fa932b769e590ecfe6a471910c05ec Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 8 Sep 2014 10:21:18 +0200 Subject: build: Detect compiler (gcc or clang) and filter out compiler flags Create a make variable $(COMPILER) which is set to either `gcc' or `clang' depending on the compiler used. Use this variable to filter out command line options not supported by clang (for now only -fno-delete-null-pointer-checks). Compiler detection snippet extracted from the Linux kernel Makefile. Signed-off-by: Tobias Klauser --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 72f0585..90387ab 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,16 @@ else DEBUG := 0 endif +# Compiler detection +ifneq ($(CC),) +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else +COMPILER := gcc +endif +export COMPILER +endif + # For packaging purposes, you might want to call your own: # make CFLAGS="" CFLAGS_DEF = -std=gnu99 @@ -83,7 +93,9 @@ endif CFLAGS_DEF += -fomit-frame-pointer CFLAGS_DEF += -fno-strict-aliasing CFLAGS_DEF += -fasynchronous-unwind-tables +ifneq ($(COMPILER), clang) CFLAGS_DEF += -fno-delete-null-pointer-checks +endif CFLAGS_MIN = -D_REENTRANT CFLAGS_MIN += -D_LARGEFILE_SOURCE -- cgit v1.2.3-54-g00ecf