diff mbox series

[1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS

Message ID 20221206040731.442499-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS | expand

Commit Message

Masahiro Yamada Dec. 6, 2022, 4:07 a.m. UTC
CONFIG_WERROR turns warnings into errors, which happens only for *.c
files because -Werror is added to KBUILD_CFLAGS.

Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors
understand the -Werror option.

For example, you can put a #warning directive in any preprocessed code.

    warning: #warning "this is a warning message" [-Wcpp]

If -Werror is added, it is promoted to an error.

    error: #warning "this is a warning message" [-Werror=cpp]

This commit moves -Werror to KBUILD_CPPFLAGS so it works in the same way
for *.c, *.S, *.lds.S or whatever needs preprocessing.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
---

 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Nathan Chancellor Dec. 9, 2022, 5:47 p.m. UTC | #1
On Tue, Dec 06, 2022 at 01:07:30PM +0900, Masahiro Yamada wrote:
> CONFIG_WERROR turns warnings into errors, which happens only for *.c
> files because -Werror is added to KBUILD_CFLAGS.
> 
> Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors
> understand the -Werror option.
> 
> For example, you can put a #warning directive in any preprocessed code.
> 
>     warning: #warning "this is a warning message" [-Wcpp]
> 
> If -Werror is added, it is promoted to an error.
> 
>     error: #warning "this is a warning message" [-Werror=cpp]
> 
> This commit moves -Werror to KBUILD_CPPFLAGS so it works in the same way
> for *.c, *.S, *.lds.S or whatever needs preprocessing.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

This seems reasonable, as people should not really be polluting the
build with messages through pragmas anyways, since the build should
always be clean.

> ---
> 
>  Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 53fa1a9fba8a..f84b57910667 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -869,7 +869,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
>  
>  KBUILD_CFLAGS += $(stackp-flags-y)
>  
> -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
> +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
> +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
>  KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
>  
>  KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
> -- 
> 2.34.1
> 
>
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 53fa1a9fba8a..f84b57910667 100644
--- a/Makefile
+++ b/Makefile
@@ -869,7 +869,8 @@  stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
 
 KBUILD_CFLAGS += $(stackp-flags-y)
 
-KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
 
 KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings