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