Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 2 | # ========================================================================== |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 3 | # make W=... settings |
| 4 | # |
Masahiro Yamada | 64a9190 | 2019-09-01 01:25:54 +0900 | [diff] [blame^] | 5 | # There are three warning groups enabled by W=1, W=2, W=3. |
| 6 | # They are independent, and can be combined like W=12 or W=123. |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 7 | # ========================================================================== |
| 8 | |
Xiongfeng Wang | 321cb03 | 2018-01-11 17:22:29 +0800 | [diff] [blame] | 9 | KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) |
| 10 | |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 11 | ifeq ("$(origin W)", "command line") |
| 12 | export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) |
| 13 | endif |
| 14 | |
Masahiro Yamada | 64a9190 | 2019-09-01 01:25:54 +0900 | [diff] [blame^] | 15 | # |
| 16 | # W=1 - warnings which may be relevant and do not occur too often |
| 17 | # |
| 18 | ifneq ($(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 19 | |
Masahiro Yamada | 64a9190 | 2019-09-01 01:25:54 +0900 | [diff] [blame^] | 20 | KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter |
| 21 | KBUILD_CFLAGS += -Wmissing-declarations |
| 22 | KBUILD_CFLAGS += -Wmissing-format-attribute |
| 23 | KBUILD_CFLAGS += -Wmissing-prototypes |
| 24 | KBUILD_CFLAGS += -Wold-style-definition |
| 25 | KBUILD_CFLAGS += -Wmissing-include-dirs |
| 26 | KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) |
| 27 | KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) |
| 28 | KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) |
| 29 | KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) |
Masahiro Yamada | 4c8dd95 | 2019-05-09 15:46:35 +0900 | [diff] [blame] | 30 | # The following turn off the warnings enabled by -Wextra |
Masahiro Yamada | 64a9190 | 2019-09-01 01:25:54 +0900 | [diff] [blame^] | 31 | KBUILD_CFLAGS += -Wno-missing-field-initializers |
| 32 | KBUILD_CFLAGS += -Wno-sign-compare |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 33 | |
Behan Webster | 26ea6bb | 2014-07-31 21:08:25 -0700 | [diff] [blame] | 34 | else |
| 35 | |
Masahiro Yamada | 64a9190 | 2019-09-01 01:25:54 +0900 | [diff] [blame^] | 36 | # Some diagnostics enabled by default are noisy. |
| 37 | # Suppress them by using -Wno... except for W=1. |
| 38 | |
Masahiro Yamada | 076f421 | 2018-10-30 22:26:33 +0900 | [diff] [blame] | 39 | ifdef CONFIG_CC_IS_CLANG |
Masahiro Yamada | a149430 | 2019-05-10 23:10:09 +0900 | [diff] [blame] | 40 | KBUILD_CFLAGS += -Wno-initializer-overrides |
Masahiro Yamada | a149430 | 2019-05-10 23:10:09 +0900 | [diff] [blame] | 41 | KBUILD_CFLAGS += -Wno-format |
| 42 | KBUILD_CFLAGS += -Wno-sign-compare |
| 43 | KBUILD_CFLAGS += -Wno-format-zero-length |
Behan Webster | 26ea6bb | 2014-07-31 21:08:25 -0700 | [diff] [blame] | 44 | endif |
Masahiro Yamada | 64a9190 | 2019-09-01 01:25:54 +0900 | [diff] [blame^] | 45 | |
| 46 | endif |
| 47 | |
| 48 | # |
| 49 | # W=2 - warnings which occur quite often but may still be relevant |
| 50 | # |
| 51 | ifneq ($(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) |
| 52 | |
| 53 | KBUILD_CFLAGS += -Wcast-align |
| 54 | KBUILD_CFLAGS += -Wdisabled-optimization |
| 55 | KBUILD_CFLAGS += -Wnested-externs |
| 56 | KBUILD_CFLAGS += -Wshadow |
| 57 | KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) |
| 58 | KBUILD_CFLAGS += -Wmissing-field-initializers |
| 59 | KBUILD_CFLAGS += -Wsign-compare |
| 60 | KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) |
| 61 | KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) |
| 62 | |
| 63 | endif |
| 64 | |
| 65 | # |
| 66 | # W=3 - more obscure warnings, can most likely be ignored |
| 67 | # |
| 68 | ifneq ($(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) |
| 69 | |
| 70 | KBUILD_CFLAGS += -Wbad-function-cast |
| 71 | KBUILD_CFLAGS += -Wcast-qual |
| 72 | KBUILD_CFLAGS += -Wconversion |
| 73 | KBUILD_CFLAGS += -Wpacked |
| 74 | KBUILD_CFLAGS += -Wpadded |
| 75 | KBUILD_CFLAGS += -Wpointer-arith |
| 76 | KBUILD_CFLAGS += -Wredundant-decls |
| 77 | KBUILD_CFLAGS += -Wswitch-default |
| 78 | KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) |
| 79 | |
Masahiro Yamada | a86fe35 | 2014-04-14 18:27:10 +0900 | [diff] [blame] | 80 | endif |