diff --git a/makefiles/cflags.inc.mk b/makefiles/cflags.inc.mk index 160469fbc8d0d92658500b95058e1cceedbd2e45..edd578b69d4a4693f1bf1f2485db7d19d0898e86 100644 --- a/makefiles/cflags.inc.mk +++ b/makefiles/cflags.inc.mk @@ -25,21 +25,23 @@ ifeq ($(shell $(CC) -fno-delete-null-pointer-checks -E - 2>/dev/null >/dev/null endif endif +# Template for testing a compiler flag and adding it to CFLAGS (errors usually +# happens when using older toolchains which do not support the given flags) +define cflags_test_and_add + ifeq ($(shell $(CC) $(1) -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) + CFLAGS += $(1) + endif +endef # Use colored compiler output if the compiler supports this and if this is not # disabled by the user ifeq ($(CC_NOCOLOR),0) - ifeq ($(shell $(CC) -fdiagnostics-color -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) - CFLAGS += -fdiagnostics-color - endif + $(eval $(call cflags_test_and_add,-fdiagnostics-color)) endif # Fast-out on old style function definitions. # They cause unreadable error compiler errors on missing semicolons. # Worse yet they hide errors by accepting wildcard argument types. -ifeq ($(shell $(CC) -Wstrict-prototypes -Werror=strict-prototypes -Wold-style-definition -Werror=old-style-definition -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) - # duplicated parameters don't hurt - CFLAGS += -Wstrict-prototypes -Wold-style-definition -endif +$(foreach flag,-Wstrict-prototypes -Wold-style-definition,$(eval $(call cflags_test_and_add,$(flag)))) # Unwanted flags for c++ CXXUWFLAGS += -std=%