Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makefiles/cflags.inc.mk: handle optional cflags #12123

Merged
merged 4 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpu/esp32/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ CFLAGS += -DLOG_TAG_IN_BRACKETS
CFLAGS += -Wno-unused-parameter -Wformat=0
CFLAGS += -mlongcalls -mtext-section-literals -fstrict-volatile-bitfields
CFLAGS += -fdata-sections -ffunction-sections -fzero-initialized-in-bss

OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation

ASFLAGS += --longcalls --text-section-literals

ifneq ($(CONFIGS),)
Expand Down
4 changes: 4 additions & 0 deletions cpu/esp8266/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ else
FFLAGS += 0 $(FLASHFILE)-0x00000.bin
FFLAGS += 0x10000 $(FLASHFILE)-0x10000.bin; esptool.py -p $(PORT) run
endif

OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation
3 changes: 3 additions & 0 deletions makefiles/arch/atmega.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ ifeq ($(LTO),1)
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
LINKFLAGS += -Wno-error
endif

OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation
3 changes: 3 additions & 0 deletions makefiles/arch/mips.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ export LINKFLAGS += $(MIPS_HAL_LDFLAGS)
export LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts
export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT)
export LINKFLAGS += -Wl,--gc-sections

OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation
4 changes: 4 additions & 0 deletions makefiles/arch/msp430.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
ASFLAGS += $(CFLAGS_CPU) --defsym $(CPU_MODEL)=1 $(CFLAGS_DBG)
# export linker flags
export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections -static -lgcc

OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation
33 changes: 10 additions & 23 deletions makefiles/cflags.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,19 @@ endif
# 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.
ifeq ($(shell $(CC) -fno-delete-null-pointer-checks -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
ifeq ($(shell LANG=C $(CC) -fno-delete-null-pointer-checks -E - 2>&1 1>/dev/null </dev/null | grep warning: | grep -- -fno-delete-null-pointer-checks),)
CFLAGS += -fno-delete-null-pointer-checks
OPTIONAL_CFLAGS += -fno-delete-null-pointer-checks

ifneq ($(shell $(CXX) -fno-delete-null-pointer-checks -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
CXXUWFLAGS += -fno-delete-null-pointer-checks
else
ifneq ($(shell LANG=C $(CXX) -fno-delete-null-pointer-checks -E - 2>&1 1>/dev/null </dev/null | grep warning: | grep -- -fno-delete-null-pointer-checks),)
CXXUWFLAGS += -fno-delete-null-pointer-checks
endif
endif
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) -Werror $(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)
$(eval $(call cflags_test_and_add,-fdiagnostics-color))
OPTIONAL_CFLAGS += -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.
$(foreach flag,-Wstrict-prototypes -Wold-style-definition,$(eval $(call cflags_test_and_add,$(flag))))
OPTIONAL_CFLAGS += -Wstrict-prototypes
OPTIONAL_CFLAGS += -Wold-style-definition

# Unwanted flags for c++
CXXUWFLAGS += -std=%
Expand All @@ -59,7 +41,9 @@ CFLAGS += -fno-common
# Enable all default warnings and all extra warnings
CFLAGS += -Wall -Wextra
# Enable additional checks for printf/scanf format strings
$(foreach flag,-Wformat=2 -Wformat-overflow -Wformat-truncation,$(eval $(call cflags_test_and_add,$(flag))))
OPTIONAL_CFLAGS += -Wformat=2
OPTIONAL_CFLAGS += -Wformat-overflow
OPTIONAL_CFLAGS += -Wformat-truncation

# Warn if a user-supplied include directory does not exist.
CFLAGS += -Wmissing-include-dirs
Expand All @@ -70,6 +54,9 @@ ifeq (,$(filter -DDEVELHELP,$(CFLAGS)))
endif
endif

# Add the optional flags that are not architecture/toolchain blacklisted
CFLAGS += $(filter-out $(OPTIONAL_CFLAGS_BLACKLIST),$(OPTIONAL_CFLAGS))

# 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)
Expand Down
4 changes: 4 additions & 0 deletions makefiles/toolchain/llvm.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ ifneq (,$(TARGET_ARCH))
INCLUDES += $(GCC_C_INCLUDES)
CXXINCLUDES += $(GCC_CXX_INCLUDES)
endif

OPTIONAL_CFLAGS_BLACKLIST += -fno-delete-null-pointer-checks
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation