Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 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 | |
Xiongfeng Wang | dfb64b8 | 2018-01-11 17:22:29 +0800 | [diff] [blame] | 13 | KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) |
| 14 | |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 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) |
Arnd Bergmann | c9c6837 | 2016-05-10 23:30:01 +0200 | [diff] [blame] | 29 | warning-1 += $(call cc-option, -Wunused-const-variable) |
Xiongfeng Wang | dfb64b8 | 2018-01-11 17:22:29 +0800 | [diff] [blame] | 30 | warning-1 += $(call cc-option, -Wpacked-not-aligned) |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 31 | warning-1 += $(call cc-disable-warning, missing-field-initializers) |
Lee Jones | 7599ea8 | 2016-01-12 14:24:18 +0000 | [diff] [blame] | 32 | warning-1 += $(call cc-disable-warning, sign-compare) |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 33 | |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 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) |
Lee Jones | 7599ea8 | 2016-01-12 14:24:18 +0000 | [diff] [blame] | 41 | warning-2 += $(call cc-option, -Wsign-compare) |
Arnd Bergmann | a76bcf5 | 2016-11-10 17:44:44 +0100 | [diff] [blame] | 42 | warning-2 += $(call cc-option, -Wmaybe-uninitialized) |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 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) |
Behan Webster | 26ea6bb | 2014-07-31 21:08:25 -0700 | [diff] [blame] | 64 | else |
| 65 | |
Michal Marek | 5631d9c | 2015-08-19 17:36:41 +0200 | [diff] [blame] | 66 | ifeq ($(cc-name),clang) |
Behan Webster | 26ea6bb | 2014-07-31 21:08:25 -0700 | [diff] [blame] | 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) |
Behan Webster | 26ea6bb | 2014-07-31 21:08:25 -0700 | [diff] [blame] | 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) |
Nathan Chancellor | 3251c97 | 2020-03-11 12:41:21 -0700 | [diff] [blame] | 73 | KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast) |
Nathan Chancellor | 4bc7e76 | 2022-02-02 16:05:16 -0700 | [diff] [blame] | 74 | KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access) |
Behan Webster | 26ea6bb | 2014-07-31 21:08:25 -0700 | [diff] [blame] | 75 | endif |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 76 | endif |