Makefile.extrawarn 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. ifeq ("$(origin W)", "command line")
  13. export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
  14. endif
  15. ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
  16. warning- := $(empty)
  17. warning-1 := -Wextra -Wunused -Wno-unused-parameter
  18. warning-1 += -Wmissing-declarations
  19. warning-1 += -Wmissing-format-attribute
  20. warning-1 += $(call cc-option, -Wmissing-prototypes)
  21. warning-1 += -Wold-style-definition
  22. warning-1 += $(call cc-option, -Wmissing-include-dirs)
  23. warning-1 += $(call cc-option, -Wunused-but-set-variable)
  24. warning-1 += $(call cc-disable-warning, missing-field-initializers)
  25. warning-2 := -Waggregate-return
  26. warning-2 += -Wcast-align
  27. warning-2 += -Wdisabled-optimization
  28. warning-2 += -Wnested-externs
  29. warning-2 += -Wshadow
  30. warning-2 += $(call cc-option, -Wlogical-op)
  31. warning-2 += $(call cc-option, -Wmissing-field-initializers)
  32. warning-3 := -Wbad-function-cast
  33. warning-3 += -Wcast-qual
  34. warning-3 += -Wconversion
  35. warning-3 += -Wpacked
  36. warning-3 += -Wpadded
  37. warning-3 += -Wpointer-arith
  38. warning-3 += -Wredundant-decls
  39. warning-3 += -Wswitch-default
  40. warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
  41. warning-3 += $(call cc-option, -Wvla)
  42. warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
  43. warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
  44. warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
  45. ifeq ("$(strip $(warning))","")
  46. $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
  47. endif
  48. KBUILD_CFLAGS += $(warning)
  49. else
  50. ifeq ($(COMPILER),clang)
  51. KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
  52. KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
  53. KBUILD_CFLAGS += $(call cc-disable-warning, format)
  54. KBUILD_CFLAGS += $(call cc-disable-warning, unknown-warning-option)
  55. KBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
  56. KBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
  57. KBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
  58. endif
  59. endif