1 # From linux.git/scripts/Kbuild.include
4 # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
5 # Exit code chooses option. "$$TMP" is can be used as temporary file and
6 # is automatically cleaned up.
7 try-run = $(shell set -e; \
8 TMP="$(TMPOUT).$$$$.tmp"; \
9 TMPO="$(TMPOUT).$$$$.o"; \
10 if ($(1)) >/dev/null 2>&1; \
14 rm -f "$$TMP" "$$TMPO")
17 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
19 cc-option = $(call try-run,\
20 $(CC) $(CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
22 # From linux.git/scripts/Makefile.extrawarn
23 # ==========================================================================
27 # W=1 - warnings that may be relevant and does not occur too often
28 # W=2 - warnings that occur quite often but may still be relevant
29 # W=3 - the more obscure warnings, can most likely be ignored
31 # $(call cc-option, -W...) handles gcc -W.. options which
32 # are not supported by all versions of the compiler
33 # ==========================================================================
35 ifeq ("$(origin W)", "command line")
36 export BUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
39 ifdef BUILD_ENABLE_EXTRA_GCC_CHECKS
42 warning-1 := -Wextra -Wunused -Wno-unused-parameter
43 warning-1 += -Wmissing-declarations
44 warning-1 += -Wmissing-format-attribute
45 warning-1 += $(call cc-option, -Wmissing-prototypes)
46 warning-1 += -Wold-style-definition
47 warning-1 += $(call cc-option, -Wmissing-include-dirs)
48 warning-1 += $(call cc-option, -Wunused-but-set-variable)
49 warning-1 += $(call cc-disable-warning, missing-field-initializers)
51 warning-2 := -Waggregate-return
52 warning-2 += -Wcast-align
53 warning-2 += -Wdisabled-optimization
54 warning-2 += -Wnested-externs
56 warning-2 += $(call cc-option, -Wlogical-op)
57 warning-2 += $(call cc-option, -Wmissing-field-initializers)
59 warning-3 := -Wbad-function-cast
60 warning-3 += -Wcast-qual
61 warning-3 += -Wconversion
64 warning-3 += -Wpointer-arith
65 warning-3 += -Wredundant-decls
66 warning-3 += -Wswitch-default
67 warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
68 warning-3 += $(call cc-option, -Wvla)
70 warning := $(warning-$(findstring 1, $(BUILD_ENABLE_EXTRA_GCC_CHECKS)))
71 warning += $(warning-$(findstring 2, $(BUILD_ENABLE_EXTRA_GCC_CHECKS)))
72 warning += $(warning-$(findstring 3, $(BUILD_ENABLE_EXTRA_GCC_CHECKS)))
74 ifeq ("$(strip $(warning))","")
75 $(error W=$(BUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
78 EXTRAWARN_CFLAGS += $(warning)
81 ifeq ($(COMPILER),clang)
82 EXTRAWARN_CFLAGS += $(call cc-disable-warning, initializer-overrides)
83 EXTRAWARN_CFLAGS += $(call cc-disable-warning, unused-value)
84 EXTRAWARN_CFLAGS += $(call cc-disable-warning, format)
85 EXTRAWARN_CFLAGS += $(call cc-disable-warning, unknown-warning-option)
86 EXTRAWARN_CFLAGS += $(call cc-disable-warning, sign-compare)
87 EXTRAWARN_CFLAGS += $(call cc-disable-warning, format-zero-length)
88 EXTRAWARN_CFLAGS += $(call cc-disable-warning, uninitialized)