xref: /linux/scripts/Makefile.extrawarn (revision 076f421da5d4594d0a3e60c032ccf02ba55e868a)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2a86fe353SMasahiro Yamada# ==========================================================================
3a86fe353SMasahiro Yamada#
4a86fe353SMasahiro Yamada# make W=... settings
5a86fe353SMasahiro Yamada#
6a86fe353SMasahiro Yamada# W=1 - warnings that may be relevant and does not occur too often
7a86fe353SMasahiro Yamada# W=2 - warnings that occur quite often but may still be relevant
8a86fe353SMasahiro Yamada# W=3 - the more obscure warnings, can most likely be ignored
9a86fe353SMasahiro Yamada#
10a86fe353SMasahiro Yamada# $(call cc-option, -W...) handles gcc -W.. options which
11a86fe353SMasahiro Yamada# are not supported by all versions of the compiler
12a86fe353SMasahiro Yamada# ==========================================================================
13a86fe353SMasahiro Yamada
14321cb030SXiongfeng WangKBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
15321cb030SXiongfeng Wang
16a86fe353SMasahiro Yamadaifeq ("$(origin W)", "command line")
17a86fe353SMasahiro Yamada  export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
18a86fe353SMasahiro Yamadaendif
19a86fe353SMasahiro Yamada
20a86fe353SMasahiro Yamadaifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
21a86fe353SMasahiro Yamadawarning-  := $(empty)
22a86fe353SMasahiro Yamada
23a86fe353SMasahiro Yamadawarning-1 := -Wextra -Wunused -Wno-unused-parameter
24a86fe353SMasahiro Yamadawarning-1 += -Wmissing-declarations
25a86fe353SMasahiro Yamadawarning-1 += -Wmissing-format-attribute
26a86fe353SMasahiro Yamadawarning-1 += $(call cc-option, -Wmissing-prototypes)
27a86fe353SMasahiro Yamadawarning-1 += -Wold-style-definition
28a86fe353SMasahiro Yamadawarning-1 += $(call cc-option, -Wmissing-include-dirs)
29a86fe353SMasahiro Yamadawarning-1 += $(call cc-option, -Wunused-but-set-variable)
30c9c6837dSArnd Bergmannwarning-1 += $(call cc-option, -Wunused-const-variable)
31321cb030SXiongfeng Wangwarning-1 += $(call cc-option, -Wpacked-not-aligned)
32a86fe353SMasahiro Yamadawarning-1 += $(call cc-disable-warning, missing-field-initializers)
337599ea8bSLee Joneswarning-1 += $(call cc-disable-warning, sign-compare)
34a86fe353SMasahiro Yamada
35a86fe353SMasahiro Yamadawarning-2 := -Waggregate-return
36a86fe353SMasahiro Yamadawarning-2 += -Wcast-align
37a86fe353SMasahiro Yamadawarning-2 += -Wdisabled-optimization
38a86fe353SMasahiro Yamadawarning-2 += -Wnested-externs
39a86fe353SMasahiro Yamadawarning-2 += -Wshadow
40a86fe353SMasahiro Yamadawarning-2 += $(call cc-option, -Wlogical-op)
41a86fe353SMasahiro Yamadawarning-2 += $(call cc-option, -Wmissing-field-initializers)
427599ea8bSLee Joneswarning-2 += $(call cc-option, -Wsign-compare)
43a76bcf55SArnd Bergmannwarning-2 += $(call cc-option, -Wmaybe-uninitialized)
44de8cf950SJohannes Thumshirnwarning-2 += $(call cc-option, -Wunused-macros)
45a86fe353SMasahiro Yamada
46a86fe353SMasahiro Yamadawarning-3 := -Wbad-function-cast
47a86fe353SMasahiro Yamadawarning-3 += -Wcast-qual
48a86fe353SMasahiro Yamadawarning-3 += -Wconversion
49a86fe353SMasahiro Yamadawarning-3 += -Wpacked
50a86fe353SMasahiro Yamadawarning-3 += -Wpadded
51a86fe353SMasahiro Yamadawarning-3 += -Wpointer-arith
52a86fe353SMasahiro Yamadawarning-3 += -Wredundant-decls
53a86fe353SMasahiro Yamadawarning-3 += -Wswitch-default
54a86fe353SMasahiro Yamadawarning-3 += $(call cc-option, -Wpacked-bitfield-compat)
55a86fe353SMasahiro Yamada
56a86fe353SMasahiro Yamadawarning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
57a86fe353SMasahiro Yamadawarning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
58a86fe353SMasahiro Yamadawarning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
59a86fe353SMasahiro Yamada
60a86fe353SMasahiro Yamadaifeq ("$(strip $(warning))","")
61a86fe353SMasahiro Yamada        $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
62a86fe353SMasahiro Yamadaendif
63a86fe353SMasahiro Yamada
64a86fe353SMasahiro YamadaKBUILD_CFLAGS += $(warning)
6526ea6bb1SBehan Websterelse
6626ea6bb1SBehan Webster
67*076f421dSMasahiro Yamadaifdef CONFIG_CC_IS_CLANG
6826ea6bb1SBehan WebsterKBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
6926ea6bb1SBehan WebsterKBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
7026ea6bb1SBehan WebsterKBUILD_CFLAGS += $(call cc-disable-warning, format)
7126ea6bb1SBehan WebsterKBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
7226ea6bb1SBehan WebsterKBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
7326ea6bb1SBehan WebsterKBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
7426ea6bb1SBehan Websterendif
75a86fe353SMasahiro Yamadaendif
76