diff mbox

Kbuild: move extra gcc check flags to the top Makefile

Message ID 1396840939-24512-1-git-send-email-yamada.m@jp.panasonic.com (mailing list archive)
State New, archived
Headers show

Commit Message

Masahiro Yamada April 7, 2014, 3:22 a.m. UTC
If W=... given to the command line, extra gcc check flags are added
to KBUILD_CFLAGS.

If we have such code in scripts/Makefile.build, the same flags are
added to KBUILD_CFLAGS multiple times becuase scripts/Makefile.build
is invoked every time Kbuild descends into the subdirectories.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---
 Makefile               | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/Makefile.build | 51 --------------------------------------------------
 2 files changed, 51 insertions(+), 51 deletions(-)

Comments

Michal Marek April 8, 2014, 3:06 p.m. UTC | #1
On 2014-04-07 05:22, Masahiro Yamada wrote:
> If W=... given to the command line, extra gcc check flags are added
> to KBUILD_CFLAGS.
> 
> If we have such code in scripts/Makefile.build, the same flags are
> added to KBUILD_CFLAGS multiple times becuase scripts/Makefile.build
> is invoked every time Kbuild descends into the subdirectories.

Indeed. For three years, nobody has noticed that the gcc commandline is
growing with every subdirectory.

> 
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> ---
>  Makefile               | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  scripts/Makefile.build | 51 --------------------------------------------------
>  2 files changed, 51 insertions(+), 51 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 00a933b..6588a03 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -579,6 +579,57 @@ endif # $(dot-config)
>  # Defaults to vmlinux, but the arch makefile usually adds further targets
>  all: vmlinux
>  
> +#
> +# make W=... settings

I don't think it's a good idea to add this to the main Makefile. First
of all, this option

> +warning-1 += $(call cc-option, -Wunused-but-set-variable)

gets overridden by

KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)

couple of lines later. This is easily fixed by moving the whole block
down. However, the main Makefile is quite complex already, so please
move this to a new Makefile fragment in scripts/ and include this from
the main Makefile instead.

Thanks,
Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sam Ravnborg April 8, 2014, 3:18 p.m. UTC | #2
On Tue, Apr 08, 2014 at 05:06:57PM +0200, Michal Marek wrote:
> On 2014-04-07 05:22, Masahiro Yamada wrote:
> > If W=... given to the command line, extra gcc check flags are added
> > to KBUILD_CFLAGS.
> > 
> > If we have such code in scripts/Makefile.build, the same flags are
> > added to KBUILD_CFLAGS multiple times becuase scripts/Makefile.build
> > is invoked every time Kbuild descends into the subdirectories.
> 
> Indeed. For three years, nobody has noticed that the gcc commandline is
> growing with every subdirectory.
I once had a patchset that moved all this out - to avoid this.
It was lost for various reasons.

The top-level Makefile is already too cluttered - so adding all this
is not good.
Moving it all to a dedicated file would be better.

	Sam
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 00a933b..6588a03 100644
--- a/Makefile
+++ b/Makefile
@@ -579,6 +579,57 @@  endif # $(dot-config)
 # Defaults to vmlinux, but the arch makefile usually adds further targets
 all: vmlinux
 
+#
+# make W=... settings
+#
+# W=1 - warnings that may be relevant and does not occur too often
+# W=2 - warnings that occur quite often but may still be relevant
+# W=3 - the more obscure warnings, can most likely be ignored
+#
+# $(call cc-option, -W...) handles gcc -W.. options which
+# are not supported by all versions of the compiler
+ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
+warning-  := $(empty)
+
+warning-1 := -Wextra -Wunused -Wno-unused-parameter
+warning-1 += -Wmissing-declarations
+warning-1 += -Wmissing-format-attribute
+warning-1 += -Wmissing-prototypes
+warning-1 += -Wold-style-definition
+warning-1 += $(call cc-option, -Wmissing-include-dirs)
+warning-1 += $(call cc-option, -Wunused-but-set-variable)
+warning-1 += $(call cc-disable-warning, missing-field-initializers)
+
+warning-2 := -Waggregate-return
+warning-2 += -Wcast-align
+warning-2 += -Wdisabled-optimization
+warning-2 += -Wnested-externs
+warning-2 += -Wshadow
+warning-2 += $(call cc-option, -Wlogical-op)
+warning-2 += $(call cc-option, -Wmissing-field-initializers)
+
+warning-3 := -Wbad-function-cast
+warning-3 += -Wcast-qual
+warning-3 += -Wconversion
+warning-3 += -Wpacked
+warning-3 += -Wpadded
+warning-3 += -Wpointer-arith
+warning-3 += -Wredundant-decls
+warning-3 += -Wswitch-default
+warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
+warning-3 += $(call cc-option, -Wvla)
+
+warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
+warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
+warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
+
+ifeq ("$(strip $(warning))","")
+        $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
+endif
+
+KBUILD_CFLAGS += $(warning)
+endif
+
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 KBUILD_CFLAGS	+= -Os $(call cc-disable-warning,maybe-uninitialized,)
 else
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 9f0ee22..b5e02b6 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -50,57 +50,6 @@  ifeq ($(KBUILD_NOPEDANTIC),)
         endif
 endif
 
-#
-# make W=... settings
-#
-# W=1 - warnings that may be relevant and does not occur too often
-# W=2 - warnings that occur quite often but may still be relevant
-# W=3 - the more obscure warnings, can most likely be ignored
-#
-# $(call cc-option, -W...) handles gcc -W.. options which
-# are not supported by all versions of the compiler
-ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
-warning-  := $(empty)
-
-warning-1 := -Wextra -Wunused -Wno-unused-parameter
-warning-1 += -Wmissing-declarations
-warning-1 += -Wmissing-format-attribute
-warning-1 += -Wmissing-prototypes
-warning-1 += -Wold-style-definition
-warning-1 += $(call cc-option, -Wmissing-include-dirs)
-warning-1 += $(call cc-option, -Wunused-but-set-variable)
-warning-1 += $(call cc-disable-warning, missing-field-initializers)
-
-warning-2 := -Waggregate-return
-warning-2 += -Wcast-align
-warning-2 += -Wdisabled-optimization
-warning-2 += -Wnested-externs
-warning-2 += -Wshadow
-warning-2 += $(call cc-option, -Wlogical-op)
-warning-2 += $(call cc-option, -Wmissing-field-initializers)
-
-warning-3 := -Wbad-function-cast
-warning-3 += -Wcast-qual
-warning-3 += -Wconversion
-warning-3 += -Wpacked
-warning-3 += -Wpadded
-warning-3 += -Wpointer-arith
-warning-3 += -Wredundant-decls
-warning-3 += -Wswitch-default
-warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
-warning-3 += $(call cc-option, -Wvla)
-
-warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
-warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
-warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
-
-ifeq ("$(strip $(warning))","")
-        $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
-endif
-
-KBUILD_CFLAGS += $(warning)
-endif
-
 include scripts/Makefile.lib
 
 ifdef host-progs