Makefile.extrawarn 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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-option, -Wunused-const-variable)
  25. warning-1 += $(call cc-disable-warning, missing-field-initializers)
  26. warning-1 += $(call cc-disable-warning, sign-compare)
  27. warning-2 := -Waggregate-return
  28. warning-2 += -Wcast-align
  29. warning-2 += -Wdisabled-optimization
  30. warning-2 += -Wnested-externs
  31. warning-2 += -Wshadow
  32. warning-2 += $(call cc-option, -Wlogical-op)
  33. warning-2 += $(call cc-option, -Wmissing-field-initializers)
  34. warning-2 += $(call cc-option, -Wsign-compare)
  35. warning-2 += $(call cc-option, -Wmaybe-uninitialized)
  36. warning-3 := -Wbad-function-cast
  37. warning-3 += -Wcast-qual
  38. warning-3 += -Wconversion
  39. warning-3 += -Wpacked
  40. warning-3 += -Wpadded
  41. warning-3 += -Wpointer-arith
  42. warning-3 += -Wredundant-decls
  43. warning-3 += -Wswitch-default
  44. warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
  45. warning-3 += $(call cc-option, -Wvla)
  46. warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
  47. warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
  48. warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
  49. ifeq ("$(strip $(warning))","")
  50. $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
  51. endif
  52. KBUILD_CFLAGS += $(warning)
  53. else
  54. ifeq ($(cc-name),clang)
  55. KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
  56. KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
  57. KBUILD_CFLAGS += $(call cc-disable-warning, format)
  58. KBUILD_CFLAGS += $(call cc-disable-warning, unknown-warning-option)
  59. KBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
  60. KBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
  61. KBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
  62. endif
  63. endif