Kconfig: Introduce CONFIG_WERROR
authorPaul Barker <paul.barker.ct@bp.renesas.com>
Fri, 28 Feb 2025 10:04:33 +0000 (10:04 +0000)
committerTom Rini <trini@konsulko.com>
Thu, 13 Mar 2025 20:23:11 +0000 (14:23 -0600)
Add a new config option under "General setup" to enable the -Werror flag
when building U-Boot. This is useful during development to help catch
mistakes.

This is based on a similar config option added to the Linux kernel by
Linus in 2021 - see Linux commit 3fe617ccafd6 ("Enable '-Werror' by
default for all kernel builds"). The modification of KBUILD_CFLAGS is
done in Makefile.extrawarn, matching where it was moved in the kernel by
Linux commit e88ca24319e4 ("kbuild: consolidate warning flags in
scripts/Makefile.extrawarn").

Signed-off-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Kconfig
scripts/Makefile.extrawarn

diff --git a/Kconfig b/Kconfig
index 6379a45..70dc385 100644 (file)
--- a/Kconfig
+++ b/Kconfig
@@ -27,6 +27,17 @@ config DEPRECATED
          code that relies on deprecated features that will be removed and
          the conversion deadline has passed.
 
+config WERROR
+       bool "Compile U-Boot with warnings as errors"
+       help
+         A U-Boot build should not cause any compiler warnings, and this
+         enables the '-Werror' flag to enforce that rule.
+
+         However, if you have a new (or very old) compiler or linker with odd
+         and unusual warnings, or you have some architecture with problems,
+         you may need to disable this config option in order to
+         successfully build U-Boot.
+
 config LOCALVERSION
        string "Local version - append to U-Boot release"
        help
index 7d39b27..f687515 100644 (file)
@@ -13,6 +13,9 @@
 
 KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
 
+KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
+
 ifeq ("$(origin W)", "command line")
   export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
 endif