2014-05-07 13:02:22 +02:00
|
|
|
# Test if the input language was specified externally.
|
|
|
|
# Otherwise test if the compiler unterstands the "-std=c99" flag, and use it if so.
|
|
|
|
ifeq ($(filter -std=%,$(CFLAGS)),)
|
2016-09-05 21:51:48 +02:00
|
|
|
ifeq ($(shell $(CC) -std=c99 -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
|
|
|
|
CFLAGS += -std=c99
|
2014-09-28 14:56:29 +02:00
|
|
|
endif
|
2014-05-07 13:02:22 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Add `-fno-delete-null-pointer-checks` flag iff the compiler supports it.
|
|
|
|
# GCC removes moves tests whether `x == NULL`, if previously `x` or even `x->y` was accessed.
|
|
|
|
# 0x0 might be a sane memory location for embedded systems, so the test must not be removed.
|
|
|
|
# Right now clang does not use the *delete-null-pointer* optimization, and does not understand the parameter.
|
|
|
|
# Related issues: #628, #664.
|
2019-08-28 19:46:47 +02:00
|
|
|
OPTIONAL_CFLAGS += -fno-delete-null-pointer-checks
|
2014-09-28 14:56:29 +02:00
|
|
|
|
2017-08-07 10:20:30 +02:00
|
|
|
# Use colored compiler output if the compiler supports this and if this is not
|
|
|
|
# disabled by the user
|
|
|
|
ifeq ($(CC_NOCOLOR),0)
|
2019-08-28 19:46:47 +02:00
|
|
|
OPTIONAL_CFLAGS += -fdiagnostics-color
|
2017-07-10 16:31:41 +02:00
|
|
|
endif
|
|
|
|
|
2014-05-07 13:02:46 +02:00
|
|
|
# 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.
|
2019-08-28 19:46:47 +02:00
|
|
|
OPTIONAL_CFLAGS += -Wstrict-prototypes
|
|
|
|
OPTIONAL_CFLAGS += -Wold-style-definition
|
2014-06-25 03:17:20 +02:00
|
|
|
|
|
|
|
# Unwanted flags for c++
|
2014-09-28 14:56:29 +02:00
|
|
|
CXXUWFLAGS += -std=%
|
2018-06-14 23:38:36 +02:00
|
|
|
CXXUWFLAGS += -Wstrict-prototypes -Wold-style-definition
|
2014-11-03 11:50:01 +01:00
|
|
|
|
2016-02-08 16:07:22 +01:00
|
|
|
ifeq ($(LTO),1)
|
|
|
|
$(warning Building with Link-Time-Optimizations is currently an experimental feature. Expect broken binaries.)
|
|
|
|
LTOFLAGS = -flto
|
2018-03-22 16:20:19 +01:00
|
|
|
LINKFLAGS += $(LTOFLAGS)
|
2014-11-03 11:50:01 +01:00
|
|
|
endif
|
2015-01-23 19:24:55 +01:00
|
|
|
|
|
|
|
# Forbid common symbols to prevent accidental aliasing.
|
|
|
|
CFLAGS += -fno-common
|
2015-01-20 21:34:17 +01:00
|
|
|
|
2018-06-14 23:32:04 +02:00
|
|
|
# Enable all default warnings and all extra warnings
|
|
|
|
CFLAGS += -Wall -Wextra
|
2018-06-14 22:45:35 +02:00
|
|
|
# Enable additional checks for printf/scanf format strings
|
2019-08-28 19:46:47 +02:00
|
|
|
OPTIONAL_CFLAGS += -Wformat=2
|
|
|
|
OPTIONAL_CFLAGS += -Wformat-overflow
|
|
|
|
OPTIONAL_CFLAGS += -Wformat-truncation
|
2015-07-06 12:27:10 +02:00
|
|
|
|
2018-01-25 15:40:39 +01:00
|
|
|
# Warn if a user-supplied include directory does not exist.
|
|
|
|
CFLAGS += -Wmissing-include-dirs
|
|
|
|
|
2015-07-22 15:30:08 +02:00
|
|
|
ifeq (,$(filter -DDEVELHELP,$(CFLAGS)))
|
2015-09-24 23:51:05 +02:00
|
|
|
ifneq (1,$(FORCE_ASSERTS))
|
|
|
|
CFLAGS += -DNDEBUG
|
|
|
|
endif
|
2015-07-22 15:30:08 +02:00
|
|
|
endif
|
|
|
|
|
2019-08-28 19:40:17 +02:00
|
|
|
# Add the optional flags that are not architecture/toolchain blacklisted
|
|
|
|
CFLAGS += $(filter-out $(OPTIONAL_CFLAGS_BLACKLIST),$(OPTIONAL_CFLAGS))
|
|
|
|
|
2015-01-20 21:34:17 +01:00
|
|
|
# Default ARFLAGS for platforms which do not specify it.
|
|
|
|
# Note: make by default provides ARFLAGS=rv which we want to override
|
|
|
|
ifeq ($(origin ARFLAGS),default)
|
|
|
|
ARFLAGS = rcs
|
|
|
|
endif
|