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