Commit 720097d895956c0bf15b8440f7845159a04b74da

Authored by Sam Ravnborg
1 parent f14875a3e0

kbuild: introduce subdir-ccflags-y

Following patch introduce support for setting options
to gcc that has effect for current directory and all
subdirectories.

The typical use case are an architecture or a subsystem that
decide to cover all files with -Werror.
Today alpha, mips and sparc uses -Werror in almost all their
Makefile- with subdir-ccflag-y it is now simpler to do so
as only the top-level directories needs to be covered.

Likewise if we decide to cover a full subsystem such
as net/ with -Werror this is done by adding a single
line to net/Makefile.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>

Showing 3 changed files with 20 additions and 2 deletions Side-by-side Diff

Documentation/kbuild/makefiles.txt
... ... @@ -316,6 +316,16 @@
316 316 #arch/m68k/fpsp040/Makefile
317 317 ldflags-y := -x
318 318  
  319 + subdir-ccflags-y, subdir-asflags-y
  320 + The two flags listed above are similar to ccflags-y and as-falgs-y.
  321 + The difference is that the subdir- variants has effect for the kbuild
  322 + file where tey are present and all subdirectories.
  323 + Options specified using subdir-* are added to the commandline before
  324 + the options specified using the non-subdir variants.
  325 +
  326 + Example:
  327 + subdir-ccflags-y := -Werror
  328 +
319 329 CFLAGS_$@, AFLAGS_$@
320 330  
321 331 CFLAGS_$@ and AFLAGS_$@ only apply to commands in current
scripts/Makefile.build
... ... @@ -27,6 +27,9 @@
27 27 cppflags-y :=
28 28 ldflags-y :=
29 29  
  30 +subdir-asflags-y :=
  31 +subdir-ccflags-y :=
  32 +
30 33 # Read auto.conf if it exists, otherwise ignore
31 34 -include include/config/auto.conf
32 35  
scripts/Makefile.lib
... ... @@ -4,6 +4,11 @@
4 4 cppflags-y += $(EXTRA_CPPFLAGS)
5 5 ldflags-y += $(EXTRA_LDFLAGS)
6 6  
  7 +#
  8 +# flags that take effect in sub directories
  9 +export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y)
  10 +export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
  11 +
7 12 # Figure out what we need to build from the various variables
8 13 # ===========================================================================
9 14  
10 15  
... ... @@ -104,10 +109,10 @@
104 109 debug_flags =
105 110 endif
106 111  
107   -orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
  112 +orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
108 113 $(ccflags-y) $(CFLAGS_$(basetarget).o)
109 114 _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
110   -_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
  115 +_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
111 116 $(asflags-y) $(AFLAGS_$(basetarget).o)
112 117 _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
113 118