Commit f77bf01425b11947eeb3b5b54685212c302741b8

Authored by Sam Ravnborg
1 parent 06c5040cdb

kbuild: introduce ccflags-y, asflags-y and ldflags-y

Introduce ccflags-y, asflags-y and ldflags-y so we soon can
deprecate use of EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS.
This patch does not touch any in-tree users - thats next round.
Lets get this committed first and then fix the users of the
soon to be deprecated variants next.

The rationale behind this change is to introduce support for
makefile fragments like:

ccflags-$(CONFIG_WHATEVER_DEBUG) := -DDEBUG

As a replacement for the uglier:
ifeq ($(CONFIG_WHATEVER_DEBUG),y)
        EXTRA_CFLAGS := -DDEBUG
endif

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

Showing 4 changed files with 35 additions and 26 deletions Side-by-side Diff

Documentation/kbuild/makefiles.txt
... ... @@ -276,40 +276,39 @@
276 276  
277 277 --- 3.7 Compilation flags
278 278  
279   - EXTRA_CFLAGS, EXTRA_AFLAGS, EXTRA_LDFLAGS
  279 + ccflags-y, asflags-y and ldflags-y
  280 + The three flags listed above applies only to the kbuild makefile
  281 + where they are assigned. They are used for all the normal
  282 + cc, as and ld invocation happenign during a recursive build.
  283 + Note: Flags with the same behaviour were previously named:
  284 + EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS.
  285 + They are yet supported but their use are deprecated.
280 286  
281   - All the EXTRA_ variables apply only to the kbuild makefile
282   - where they are assigned. The EXTRA_ variables apply to all
283   - commands executed in the kbuild makefile.
  287 + ccflags-y specifies options for compiling C files with $(CC).
284 288  
285   - $(EXTRA_CFLAGS) specifies options for compiling C files with
286   - $(CC).
287   -
288 289 Example:
289 290 # drivers/sound/emu10k1/Makefile
290   - EXTRA_CFLAGS += -I$(obj)
291   - ifdef DEBUG
292   - EXTRA_CFLAGS += -DEMU10K1_DEBUG
293   - endif
  291 + ccflags-y += -I$(obj)
  292 + ccflags-$(DEBUG) += -DEMU10K1_DEBUG
294 293  
295 294  
296 295 This variable is necessary because the top Makefile owns the
297 296 variable $(KBUILD_CFLAGS) and uses it for compilation flags for the
298 297 entire tree.
299 298  
300   - $(EXTRA_AFLAGS) is a similar string for per-directory options
  299 + asflags-y is a similar string for per-directory options
301 300 when compiling assembly language source.
302 301  
303 302 Example:
304 303 #arch/x86_64/kernel/Makefile
305   - EXTRA_AFLAGS := -traditional
  304 + asflags-y := -traditional
306 305  
307 306  
308   - $(EXTRA_LDFLAGS) is a string for per-directory options to $(LD).
  307 + ldflags-y is a string for per-directory options to $(LD).
309 308  
310 309 Example:
311 310 #arch/m68k/fpsp040/Makefile
312   - EXTRA_LDFLAGS := -x
  311 + ldflags-y := -x
313 312  
314 313 CFLAGS_$@, AFLAGS_$@
315 314  
316 315  
... ... @@ -495,9 +494,9 @@
495 494  
496 495 Example:
497 496 #fs/reiserfs/Makefile
498   - EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1)
  497 + ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
499 498  
500   - In this example, EXTRA_CFLAGS will be assigned the value -O1 if the
  499 + In this example, ccflags-y will be assigned the value -O1 if the
501 500 $(CC) version is less than 4.2.
502 501 cc-ifversion takes all the shell operators:
503 502 -eq, -ne, -lt, -le, -gt, and -ge
... ... @@ -783,7 +782,7 @@
783 782 Example:
784 783 #arch/s390/Makefile
785 784 LDFLAGS := -m elf_s390
786   - Note: EXTRA_LDFLAGS can be used to further customise
  785 + Note: ldflags-y can be used to further customise
787 786 the flags used. See chapter 3.7.
788 787  
789 788 LDFLAGS_MODULE Options for $(LD) when linking modules
... ... @@ -1100,7 +1099,7 @@
1100 1099  
1101 1100 When building the *.lds target, kbuild uses the variables:
1102 1101 KBUILD_CPPFLAGS : Set in top-level Makefile
1103   - EXTRA_CPPFLAGS : May be set in the kbuild makefile
  1102 + cppflags-y : May be set in the kbuild makefile
1104 1103 CPPFLAGS_$(@F) : Target specific flags.
1105 1104 Note that the full filename is used in this
1106 1105 assignment.
scripts/Makefile.build
... ... @@ -22,6 +22,10 @@
22 22 EXTRA_CFLAGS :=
23 23 EXTRA_CPPFLAGS :=
24 24 EXTRA_LDFLAGS :=
  25 +asflags-y :=
  26 +ccflags-y :=
  27 +cppflags-y :=
  28 +ldflags-y :=
25 29  
26 30 # Read .config if it exist, otherwise ignore
27 31 -include include/config/auto.conf
scripts/Makefile.lib
  1 +# Backward compatibility
  2 +asflags-y += $(EXTRA_AFLAGS)
  3 +ccflags-y += $(EXTRA_CFLAGS)
  4 +cppflags-y += $(EXTRA_CPPFLAGS)
  5 +ldflags-y += $(EXTRA_LDFLAGS)
  6 +
1 7 # Figure out what we need to build from the various variables
2 8 # ===========================================================================
3 9  
... ... @@ -84,9 +90,9 @@
84 90 modname_flags = $(if $(filter 1,$(words $(modname))),\
85 91 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
86 92  
87   -_c_flags = $(KBUILD_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(basetarget).o)
88   -_a_flags = $(KBUILD_AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
89   -_cpp_flags = $(KBUILD_CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F))
  93 +_c_flags = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o)
  94 +_a_flags = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o)
  95 +_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
90 96  
91 97 # If building the kernel in a separate objtree expand all occurrences
92 98 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
... ... @@ -115,7 +121,7 @@
115 121  
116 122 cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
117 123  
118   -ld_flags = $(LDFLAGS) $(EXTRA_LDFLAGS)
  124 +ld_flags = $(LDFLAGS) $(ldflags-y)
119 125  
120 126 # Finds the multi-part object the current object will be linked into
121 127 modname-multi = $(sort $(foreach m,$(multi-used),\
... ... @@ -145,7 +151,7 @@
145 151 # ---------------------------------------------------------------------------
146 152  
147 153 quiet_cmd_ld = LD $@
148   -cmd_ld = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$(@F)) \
  154 +cmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \
149 155 $(filter-out FORCE,$^) -o $@
150 156  
151 157 # Objcopy
... ... @@ -3,8 +3,8 @@
3 3 # with correct relocations from System.map
4 4 # Requires the following lines in makefile:
5 5 #%.lst: %.c
6   -# $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
7   -# $(srctree)/scripts/makelst $*.o $(objtree)/System.map $(OBJDUMP)
  6 +# $(CC) $(c_flags) -g -c -o $*.o $< &&
  7 +# $(srctree)/scripts/makelst $*.o System.map $(OBJDUMP) > $@
8 8 #
9 9 # Copyright (C) 2000 IBM Corporation
10 10 # Author(s): DJ Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)