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