aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/kbuild/makefiles.txt166
-rw-r--r--Makefile32
-rw-r--r--scripts/Kbuild.include37
-rw-r--r--scripts/Makefile.build3
4 files changed, 136 insertions, 102 deletions
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 443230b43e09..99d51a5bb0d9 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -17,6 +17,7 @@ This document describes the Linux kernel Makefiles.
17 --- 3.8 Command line dependency 17 --- 3.8 Command line dependency
18 --- 3.9 Dependency tracking 18 --- 3.9 Dependency tracking
19 --- 3.10 Special Rules 19 --- 3.10 Special Rules
20 --- 3.11 $(CC) support functions
20 21
21 === 4 Host Program support 22 === 4 Host Program support
22 --- 4.1 Simple Host Program 23 --- 4.1 Simple Host Program
@@ -38,7 +39,6 @@ This document describes the Linux kernel Makefiles.
38 --- 6.6 Commands useful for building a boot image 39 --- 6.6 Commands useful for building a boot image
39 --- 6.7 Custom kbuild commands 40 --- 6.7 Custom kbuild commands
40 --- 6.8 Preprocessing linker scripts 41 --- 6.8 Preprocessing linker scripts
41 --- 6.9 $(CC) support functions
42 42
43 === 7 Kbuild Variables 43 === 7 Kbuild Variables
44 === 8 Makefile language 44 === 8 Makefile language
@@ -385,6 +385,102 @@ more details, with real examples.
385 to prerequisites are referenced with $(src) (because they are not 385 to prerequisites are referenced with $(src) (because they are not
386 generated files). 386 generated files).
387 387
388--- 3.11 $(CC) support functions
389
390 The kernel may be build with several different versions of
391 $(CC), each supporting a unique set of features and options.
392 kbuild provide basic support to check for valid options for $(CC).
393 $(CC) is useally the gcc compiler, but other alternatives are
394 available.
395
396 as-option
397 as-option is used to check if $(CC) when used to compile
398 assembler (*.S) files supports the given option. An optional
399 second option may be specified if first option are not supported.
400
401 Example:
402 #arch/sh/Makefile
403 cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),)
404
405 In the above example cflags-y will be assinged the the option
406 -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC).
407 The second argument is optional, and if supplied will be used
408 if first argument is not supported.
409
410 cc-option
411 cc-option is used to check if $(CC) support a given option, and not
412 supported to use an optional second option.
413
414 Example:
415 #arch/i386/Makefile
416 cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
417
418 In the above example cflags-y will be assigned the option
419 -march=pentium-mmx if supported by $(CC), otherwise -march-i586.
420 The second argument to cc-option is optional, and if omitted
421 cflags-y will be assigned no value if first option is not supported.
422
423 cc-option-yn
424 cc-option-yn is used to check if gcc supports a given option
425 and return 'y' if supported, otherwise 'n'.
426
427 Example:
428 #arch/ppc/Makefile
429 biarch := $(call cc-option-yn, -m32)
430 aflags-$(biarch) += -a32
431 cflags-$(biarch) += -m32
432
433 In the above example $(biarch) is set to y if $(CC) supports the -m32
434 option. When $(biarch) equals to y the expanded variables $(aflags-y)
435 and $(cflags-y) will be assigned the values -a32 and -m32.
436
437 cc-option-align
438 gcc version >= 3.0 shifted type of options used to speify
439 alignment of functions, loops etc. $(cc-option-align) whrn used
440 as prefix to the align options will select the right prefix:
441 gcc < 3.00
442 cc-option-align = -malign
443 gcc >= 3.00
444 cc-option-align = -falign
445
446 Example:
447 CFLAGS += $(cc-option-align)-functions=4
448
449 In the above example the option -falign-functions=4 is used for
450 gcc >= 3.00. For gcc < 3.00 -malign-functions=4 is used.
451
452 cc-version
453 cc-version return a numerical version of the $(CC) compiler version.
454 The format is <major><minor> where both are two digits. So for example
455 gcc 3.41 would return 0341.
456 cc-version is useful when a specific $(CC) version is faulty in one
457 area, for example the -mregparm=3 were broken in some gcc version
458 even though the option was accepted by gcc.
459
460 Example:
461 #arch/i386/Makefile
462 cflags-y += $(shell \
463 if [ $(call cc-version) -ge 0300 ] ; then \
464 echo "-mregparm=3"; fi ;)
465
466 In the above example -mregparm=3 is only used for gcc version greater
467 than or equal to gcc 3.0.
468
469 cc-ifversion
470 cc-ifversion test the version of $(CC) and equals last argument if
471 version expression is true.
472
473 Example:
474 #fs/reiserfs/Makefile
475 EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1)
476
477 In this example EXTRA_CFLAGS will be assigned the value -O1 if the
478 $(CC) version is less than 4.2.
479 cc-ifversion takes all the shell operators:
480 -eq, -ne, -lt, -le, -gt, and -ge
481 The third parameter may be a text as in this example, but it may also
482 be an expanded variable or a macro.
483
388 484
389=== 4 Host Program support 485=== 4 Host Program support
390 486
@@ -973,74 +1069,6 @@ When kbuild executes the following steps are followed (roughly):
973 architecture specific files. 1069 architecture specific files.
974 1070
975 1071
976--- 6.9 $(CC) support functions
977
978 The kernel may be build with several different versions of
979 $(CC), each supporting a unique set of features and options.
980 kbuild provide basic support to check for valid options for $(CC).
981 $(CC) is useally the gcc compiler, but other alternatives are
982 available.
983
984 cc-option
985 cc-option is used to check if $(CC) support a given option, and not
986 supported to use an optional second option.
987
988 Example:
989 #arch/i386/Makefile
990 cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
991
992 In the above example cflags-y will be assigned the option
993 -march=pentium-mmx if supported by $(CC), otherwise -march-i586.
994 The second argument to cc-option is optional, and if omitted
995 cflags-y will be assigned no value if first option is not supported.
996
997 cc-option-yn
998 cc-option-yn is used to check if gcc supports a given option
999 and return 'y' if supported, otherwise 'n'.
1000
1001 Example:
1002 #arch/ppc/Makefile
1003 biarch := $(call cc-option-yn, -m32)
1004 aflags-$(biarch) += -a32
1005 cflags-$(biarch) += -m32
1006
1007 In the above example $(biarch) is set to y if $(CC) supports the -m32
1008 option. When $(biarch) equals to y the expanded variables $(aflags-y)
1009 and $(cflags-y) will be assigned the values -a32 and -m32.
1010
1011 cc-option-align
1012 gcc version >= 3.0 shifted type of options used to speify
1013 alignment of functions, loops etc. $(cc-option-align) whrn used
1014 as prefix to the align options will select the right prefix:
1015 gcc < 3.00
1016 cc-option-align = -malign
1017 gcc >= 3.00
1018 cc-option-align = -falign
1019
1020 Example:
1021 CFLAGS += $(cc-option-align)-functions=4
1022
1023 In the above example the option -falign-functions=4 is used for
1024 gcc >= 3.00. For gcc < 3.00 -malign-functions=4 is used.
1025
1026 cc-version
1027 cc-version return a numerical version of the $(CC) compiler version.
1028 The format is <major><minor> where both are two digits. So for example
1029 gcc 3.41 would return 0341.
1030 cc-version is useful when a specific $(CC) version is faulty in one
1031 area, for example the -mregparm=3 were broken in some gcc version
1032 even though the option was accepted by gcc.
1033
1034 Example:
1035 #arch/i386/Makefile
1036 cflags-y += $(shell \
1037 if [ $(call cc-version) -ge 0300 ] ; then \
1038 echo "-mregparm=3"; fi ;)
1039
1040 In the above example -mregparm=3 is only used for gcc version greater
1041 than or equal to gcc 3.0.
1042
1043
1044=== 7 Kbuild Variables 1072=== 7 Kbuild Variables
1045 1073
1046The top Makefile exports the following variables: 1074The top Makefile exports the following variables:
diff --git a/Makefile b/Makefile
index c55d0f1b85ec..05b451a1b760 100644
--- a/Makefile
+++ b/Makefile
@@ -258,38 +258,6 @@ endif
258 258
259export quiet Q KBUILD_VERBOSE 259export quiet Q KBUILD_VERBOSE
260 260
261######
262# cc support functions to be used (only) in arch/$(ARCH)/Makefile
263# See documentation in Documentation/kbuild/makefiles.txt
264
265# as-option
266# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
267
268as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
269 -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \
270 else echo "$(2)"; fi ;)
271
272# cc-option
273# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
274
275cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
276 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
277
278# cc-option-yn
279# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
280cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
281 > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
282
283# cc-option-align
284# Prefix align with either -falign or -malign
285cc-option-align = $(subst -functions=0,,\
286 $(call cc-option,-falign-functions=0,-malign-functions=0))
287
288# cc-version
289# Usage gcc-ver := $(call cc-version $(CC))
290cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
291 $(if $(1), $(1), $(CC)))
292
293 261
294# Look for make include files relative to root of kernel src 262# Look for make include files relative to root of kernel src
295MAKEFLAGS += --include-dir=$(srctree) 263MAKEFLAGS += --include-dir=$(srctree)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 0168d6c37075..92ce94b58bd6 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -44,6 +44,43 @@ define filechk
44 fi 44 fi
45endef 45endef
46 46
47######
48# cc support functions to be used (only) in arch/$(ARCH)/Makefile
49# See documentation in Documentation/kbuild/makefiles.txt
50
51# as-option
52# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
53
54as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
55 -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \
56 else echo "$(2)"; fi ;)
57
58# cc-option
59# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
60
61cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
62 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
63
64# cc-option-yn
65# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
66cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
67 > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
68
69# cc-option-align
70# Prefix align with either -falign or -malign
71cc-option-align = $(subst -functions=0,,\
72 $(call cc-option,-falign-functions=0,-malign-functions=0))
73
74# cc-version
75# Usage gcc-ver := $(call cc-version, $(CC))
76cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
77 $(if $(1), $(1), $(CC)))
78
79# cc-ifversion
80# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
81cc-ifversion = $(shell if [ $(call cc-version, $(CC)) $(1) $(2) ]; then \
82 echo $(3); fi;)
83
47### 84###
48# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 85# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
49# Usage: 86# Usage:
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index c33e62bde6b0..2737765f2fb4 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -10,11 +10,12 @@ __build:
10# Read .config if it exist, otherwise ignore 10# Read .config if it exist, otherwise ignore
11-include .config 11-include .config
12 12
13include scripts/Kbuild.include
14
13# The filename Kbuild has precedence over Makefile 15# The filename Kbuild has precedence over Makefile
14kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) 16kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
15include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile) 17include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
16 18
17include scripts/Kbuild.include
18include scripts/Makefile.lib 19include scripts/Makefile.lib
19 20
20ifdef host-progs 21ifdef host-progs