1*4882a593Smuzhiyun# ==========================================================================
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# make W=... settings
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# W=1 - warnings that may be relevant and does not occur too often
6*4882a593Smuzhiyun# W=2 - warnings that occur quite often but may still be relevant
7*4882a593Smuzhiyun# W=3 - the more obscure warnings, can most likely be ignored
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun# $(call cc-option, -W...) handles gcc -W.. options which
10*4882a593Smuzhiyun# are not supported by all versions of the compiler
11*4882a593Smuzhiyun# ==========================================================================
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
14*4882a593Smuzhiyun
15*4882a593Smuzhiyunifeq ("$(origin W)", "command line")
16*4882a593Smuzhiyun  export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
17*4882a593Smuzhiyunendif
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
20*4882a593Smuzhiyunwarning-  := $(empty)
21*4882a593Smuzhiyun
22*4882a593Smuzhiyunwarning-1 := -Wextra -Wunused -Wno-unused-parameter
23*4882a593Smuzhiyunwarning-1 += -Wmissing-declarations
24*4882a593Smuzhiyunwarning-1 += -Wmissing-format-attribute
25*4882a593Smuzhiyunwarning-1 += $(call cc-option, -Wmissing-prototypes)
26*4882a593Smuzhiyunwarning-1 += -Wold-style-definition
27*4882a593Smuzhiyunwarning-1 += $(call cc-option, -Wmissing-include-dirs)
28*4882a593Smuzhiyunwarning-1 += $(call cc-option, -Wunused-but-set-variable)
29*4882a593Smuzhiyunwarning-1 += $(call cc-option, -Wunused-const-variable)
30*4882a593Smuzhiyunwarning-1 += $(call cc-option, -Wpacked-not-aligned)
31*4882a593Smuzhiyunwarning-1 += $(call cc-disable-warning, missing-field-initializers)
32*4882a593Smuzhiyun
33*4882a593Smuzhiyunwarning-2 := -Waggregate-return
34*4882a593Smuzhiyunwarning-2 += -Wcast-align
35*4882a593Smuzhiyunwarning-2 += -Wdisabled-optimization
36*4882a593Smuzhiyunwarning-2 += -Wnested-externs
37*4882a593Smuzhiyunwarning-2 += -Wshadow
38*4882a593Smuzhiyunwarning-2 += $(call cc-option, -Wlogical-op)
39*4882a593Smuzhiyunwarning-2 += $(call cc-option, -Wmissing-field-initializers)
40*4882a593Smuzhiyun
41*4882a593Smuzhiyunwarning-3 := -Wbad-function-cast
42*4882a593Smuzhiyunwarning-3 += -Wcast-qual
43*4882a593Smuzhiyunwarning-3 += -Wconversion
44*4882a593Smuzhiyunwarning-3 += -Wpacked
45*4882a593Smuzhiyunwarning-3 += -Wpadded
46*4882a593Smuzhiyunwarning-3 += -Wpointer-arith
47*4882a593Smuzhiyunwarning-3 += -Wredundant-decls
48*4882a593Smuzhiyunwarning-3 += -Wswitch-default
49*4882a593Smuzhiyunwarning-3 += $(call cc-option, -Wpacked-bitfield-compat)
50*4882a593Smuzhiyunwarning-3 += $(call cc-option, -Wvla)
51*4882a593Smuzhiyun
52*4882a593Smuzhiyunwarning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
53*4882a593Smuzhiyunwarning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
54*4882a593Smuzhiyunwarning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
55*4882a593Smuzhiyun
56*4882a593Smuzhiyunifeq ("$(strip $(warning))","")
57*4882a593Smuzhiyun        $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
58*4882a593Smuzhiyunendif
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunKBUILD_CFLAGS += $(warning)
61*4882a593Smuzhiyunelse
62*4882a593Smuzhiyun
63*4882a593Smuzhiyunifeq ($(cc-name),clang)
64*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
65*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
66*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, format)
67*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
68*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
69*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
70*4882a593Smuzhiyunendif
71*4882a593Smuzhiyunendif
72