aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/kbuild/makefiles.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/kbuild/makefiles.txt')
-rw-r--r--Documentation/kbuild/makefiles.txt290
1 files changed, 162 insertions, 128 deletions
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index a9c00facdf40..e2cbd59cf2d0 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -22,7 +22,7 @@ This document describes the Linux kernel Makefiles.
22 === 4 Host Program support 22 === 4 Host Program support
23 --- 4.1 Simple Host Program 23 --- 4.1 Simple Host Program
24 --- 4.2 Composite Host Programs 24 --- 4.2 Composite Host Programs
25 --- 4.3 Defining shared libraries 25 --- 4.3 Defining shared libraries
26 --- 4.4 Using C++ for host programs 26 --- 4.4 Using C++ for host programs
27 --- 4.5 Controlling compiler options for host programs 27 --- 4.5 Controlling compiler options for host programs
28 --- 4.6 When host programs are actually built 28 --- 4.6 When host programs are actually built
@@ -69,7 +69,7 @@ architecture-specific information to the top Makefile.
69 69
70Each subdirectory has a kbuild Makefile which carries out the commands 70Each subdirectory has a kbuild Makefile which carries out the commands
71passed down from above. The kbuild Makefile uses information from the 71passed down from above. The kbuild Makefile uses information from the
72.config file to construct various file lists used by kbuild to build 72.config file to construct various file lists used by kbuild to build
73any built-in or modular targets. 73any built-in or modular targets.
74 74
75scripts/Makefile.* contains all the definitions/rules etc. that 75scripts/Makefile.* contains all the definitions/rules etc. that
@@ -86,7 +86,7 @@ any kernel Makefiles (or any other source files).
86 86
87*Normal developers* are people who work on features such as device 87*Normal developers* are people who work on features such as device
88drivers, file systems, and network protocols. These people need to 88drivers, file systems, and network protocols. These people need to
89maintain the kbuild Makefiles for the subsystem that they are 89maintain the kbuild Makefiles for the subsystem they are
90working on. In order to do this effectively, they need some overall 90working on. In order to do this effectively, they need some overall
91knowledge about the kernel Makefiles, plus detailed knowledge about the 91knowledge about the kernel Makefiles, plus detailed knowledge about the
92public interface for kbuild. 92public interface for kbuild.
@@ -104,10 +104,10 @@ This document is aimed towards normal developers and arch developers.
104=== 3 The kbuild files 104=== 3 The kbuild files
105 105
106Most Makefiles within the kernel are kbuild Makefiles that use the 106Most Makefiles within the kernel are kbuild Makefiles that use the
107kbuild infrastructure. This chapter introduce the syntax used in the 107kbuild infrastructure. This chapter introduces the syntax used in the
108kbuild makefiles. 108kbuild makefiles.
109The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can 109The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can
110be used and if both a 'Makefile' and a 'Kbuild' file exists then the 'Kbuild' 110be used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild'
111file will be used. 111file will be used.
112 112
113Section 3.1 "Goal definitions" is a quick intro, further chapters provide 113Section 3.1 "Goal definitions" is a quick intro, further chapters provide
@@ -124,7 +124,7 @@ more details, with real examples.
124 Example: 124 Example:
125 obj-y += foo.o 125 obj-y += foo.o
126 126
127 This tell kbuild that there is one object in that directory named 127 This tell kbuild that there is one object in that directory, named
128 foo.o. foo.o will be built from foo.c or foo.S. 128 foo.o. foo.o will be built from foo.c or foo.S.
129 129
130 If foo.o shall be built as a module, the variable obj-m is used. 130 If foo.o shall be built as a module, the variable obj-m is used.
@@ -140,7 +140,7 @@ more details, with real examples.
140--- 3.2 Built-in object goals - obj-y 140--- 3.2 Built-in object goals - obj-y
141 141
142 The kbuild Makefile specifies object files for vmlinux 142 The kbuild Makefile specifies object files for vmlinux
143 in the lists $(obj-y). These lists depend on the kernel 143 in the $(obj-y) lists. These lists depend on the kernel
144 configuration. 144 configuration.
145 145
146 Kbuild compiles all the $(obj-y) files. It then calls 146 Kbuild compiles all the $(obj-y) files. It then calls
@@ -154,8 +154,8 @@ more details, with real examples.
154 Link order is significant, because certain functions 154 Link order is significant, because certain functions
155 (module_init() / __initcall) will be called during boot in the 155 (module_init() / __initcall) will be called during boot in the
156 order they appear. So keep in mind that changing the link 156 order they appear. So keep in mind that changing the link
157 order may e.g. change the order in which your SCSI 157 order may e.g. change the order in which your SCSI
158 controllers are detected, and thus you disks are renumbered. 158 controllers are detected, and thus your disks are renumbered.
159 159
160 Example: 160 Example:
161 #drivers/isdn/i4l/Makefile 161 #drivers/isdn/i4l/Makefile
@@ -203,11 +203,11 @@ more details, with real examples.
203 Example: 203 Example:
204 #fs/ext2/Makefile 204 #fs/ext2/Makefile
205 obj-$(CONFIG_EXT2_FS) += ext2.o 205 obj-$(CONFIG_EXT2_FS) += ext2.o
206 ext2-y := balloc.o bitmap.o 206 ext2-y := balloc.o bitmap.o
207 ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o 207 ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o
208 208
209 In this example xattr.o is only part of the composite object 209 In this example, xattr.o is only part of the composite object
210 ext2.o, if $(CONFIG_EXT2_FS_XATTR) evaluates to 'y'. 210 ext2.o if $(CONFIG_EXT2_FS_XATTR) evaluates to 'y'.
211 211
212 Note: Of course, when you are building objects into the kernel, 212 Note: Of course, when you are building objects into the kernel,
213 the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, 213 the syntax above will also work. So, if you have CONFIG_EXT2_FS=y,
@@ -221,16 +221,16 @@ more details, with real examples.
221 221
222--- 3.5 Library file goals - lib-y 222--- 3.5 Library file goals - lib-y
223 223
224 Objects listed with obj-* are used for modules or 224 Objects listed with obj-* are used for modules, or
225 combined in a built-in.o for that specific directory. 225 combined in a built-in.o for that specific directory.
226 There is also the possibility to list objects that will 226 There is also the possibility to list objects that will
227 be included in a library, lib.a. 227 be included in a library, lib.a.
228 All objects listed with lib-y are combined in a single 228 All objects listed with lib-y are combined in a single
229 library for that directory. 229 library for that directory.
230 Objects that are listed in obj-y and additional listed in 230 Objects that are listed in obj-y and additionaly listed in
231 lib-y will not be included in the library, since they will anyway 231 lib-y will not be included in the library, since they will anyway
232 be accessible. 232 be accessible.
233 For consistency objects listed in lib-m will be included in lib.a. 233 For consistency, objects listed in lib-m will be included in lib.a.
234 234
235 Note that the same kbuild makefile may list files to be built-in 235 Note that the same kbuild makefile may list files to be built-in
236 and to be part of a library. Therefore the same directory 236 and to be part of a library. Therefore the same directory
@@ -241,11 +241,11 @@ more details, with real examples.
241 lib-y := checksum.o delay.o 241 lib-y := checksum.o delay.o
242 242
243 This will create a library lib.a based on checksum.o and delay.o. 243 This will create a library lib.a based on checksum.o and delay.o.
244 For kbuild to actually recognize that there is a lib.a being build 244 For kbuild to actually recognize that there is a lib.a being built,
245 the directory shall be listed in libs-y. 245 the directory shall be listed in libs-y.
246 See also "6.3 List directories to visit when descending". 246 See also "6.3 List directories to visit when descending".
247 247
248 Usage of lib-y is normally restricted to lib/ and arch/*/lib. 248 Use of lib-y is normally restricted to lib/ and arch/*/lib.
249 249
250--- 3.6 Descending down in directories 250--- 3.6 Descending down in directories
251 251
@@ -255,7 +255,7 @@ more details, with real examples.
255 invoke make recursively in subdirectories, provided you let it know of 255 invoke make recursively in subdirectories, provided you let it know of
256 them. 256 them.
257 257
258 To do so obj-y and obj-m are used. 258 To do so, obj-y and obj-m are used.
259 ext2 lives in a separate directory, and the Makefile present in fs/ 259 ext2 lives in a separate directory, and the Makefile present in fs/
260 tells kbuild to descend down using the following assignment. 260 tells kbuild to descend down using the following assignment.
261 261
@@ -353,8 +353,8 @@ more details, with real examples.
353 Special rules are used when the kbuild infrastructure does 353 Special rules are used when the kbuild infrastructure does
354 not provide the required support. A typical example is 354 not provide the required support. A typical example is
355 header files generated during the build process. 355 header files generated during the build process.
356 Another example is the architecture specific Makefiles which 356 Another example are the architecture specific Makefiles which
357 needs special rules to prepare boot images etc. 357 need special rules to prepare boot images etc.
358 358
359 Special rules are written as normal Make rules. 359 Special rules are written as normal Make rules.
360 Kbuild is not executing in the directory where the Makefile is 360 Kbuild is not executing in the directory where the Makefile is
@@ -387,28 +387,47 @@ more details, with real examples.
387 387
388--- 3.11 $(CC) support functions 388--- 3.11 $(CC) support functions
389 389
390 The kernel may be build with several different versions of 390 The kernel may be built with several different versions of
391 $(CC), each supporting a unique set of features and options. 391 $(CC), each supporting a unique set of features and options.
392 kbuild provide basic support to check for valid options for $(CC). 392 kbuild provide basic support to check for valid options for $(CC).
393 $(CC) is useally the gcc compiler, but other alternatives are 393 $(CC) is useally the gcc compiler, but other alternatives are
394 available. 394 available.
395 395
396 as-option 396 as-option
397 as-option is used to check if $(CC) when used to compile 397 as-option is used to check if $(CC) -- when used to compile
398 assembler (*.S) files supports the given option. An optional 398 assembler (*.S) files -- supports the given option. An optional
399 second option may be specified if first option are not supported. 399 second option may be specified if the first option is not supported.
400 400
401 Example: 401 Example:
402 #arch/sh/Makefile 402 #arch/sh/Makefile
403 cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),) 403 cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),)
404 404
405 In the above example cflags-y will be assinged the the option 405 In the above example, cflags-y will be assigned the option
406 -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC). 406 -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC).
407 The second argument is optional, and if supplied will be used 407 The second argument is optional, and if supplied will be used
408 if first argument is not supported. 408 if first argument is not supported.
409 409
410 ld-option
411 ld-option is used to check if $(CC) when used to link object files
412 supports the given option. An optional second option may be
413 specified if first option are not supported.
414
415 Example:
416 #arch/i386/kernel/Makefile
417 vsyscall-flags += $(call ld-option, -Wl$(comma)--hash-style=sysv)
418
419 In the above example vsyscall-flags will be assigned the option
420 -Wl$(comma)--hash-style=sysv if it is supported by $(CC).
421 The second argument is optional, and if supplied will be used
422 if first argument is not supported.
423
424 as-instr
425 as-instr checks if the assembler reports a specific instruction
426 and then outputs either option1 or option2
427 C escapes are supported in the test instruction
428
410 cc-option 429 cc-option
411 cc-option is used to check if $(CC) support a given option, and not 430 cc-option is used to check if $(CC) supports a given option, and not
412 supported to use an optional second option. 431 supported to use an optional second option.
413 432
414 Example: 433 Example:
@@ -416,12 +435,12 @@ more details, with real examples.
416 cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586) 435 cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
417 436
418 In the above example cflags-y will be assigned the option 437 In the above example cflags-y will be assigned the option
419 -march=pentium-mmx if supported by $(CC), otherwise -march-i586. 438 -march=pentium-mmx if supported by $(CC), otherwise -march=i586.
420 The second argument to cc-option is optional, and if omitted 439 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. 440 cflags-y will be assigned no value if first option is not supported.
422 441
423 cc-option-yn 442 cc-option-yn
424 cc-option-yn is used to check if gcc supports a given option 443 cc-option-yn is used to check if gcc supports a given option
425 and return 'y' if supported, otherwise 'n'. 444 and return 'y' if supported, otherwise 'n'.
426 445
427 Example: 446 Example:
@@ -429,32 +448,33 @@ more details, with real examples.
429 biarch := $(call cc-option-yn, -m32) 448 biarch := $(call cc-option-yn, -m32)
430 aflags-$(biarch) += -a32 449 aflags-$(biarch) += -a32
431 cflags-$(biarch) += -m32 450 cflags-$(biarch) += -m32
432 451
433 In the above example $(biarch) is set to y if $(CC) supports the -m32 452 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) 453 option. When $(biarch) equals 'y', the expanded variables $(aflags-y)
435 and $(cflags-y) will be assigned the values -a32 and -m32. 454 and $(cflags-y) will be assigned the values -a32 and -m32,
455 respectively.
436 456
437 cc-option-align 457 cc-option-align
438 gcc version >= 3.0 shifted type of options used to speify 458 gcc versions >= 3.0 changed the type of options used to specify
439 alignment of functions, loops etc. $(cc-option-align) whrn used 459 alignment of functions, loops etc. $(cc-option-align), when used
440 as prefix to the align options will select the right prefix: 460 as prefix to the align options, will select the right prefix:
441 gcc < 3.00 461 gcc < 3.00
442 cc-option-align = -malign 462 cc-option-align = -malign
443 gcc >= 3.00 463 gcc >= 3.00
444 cc-option-align = -falign 464 cc-option-align = -falign
445 465
446 Example: 466 Example:
447 CFLAGS += $(cc-option-align)-functions=4 467 CFLAGS += $(cc-option-align)-functions=4
448 468
449 In the above example the option -falign-functions=4 is used for 469 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. 470 gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used.
451 471
452 cc-version 472 cc-version
453 cc-version return a numerical version of the $(CC) compiler version. 473 cc-version returns a numerical version of the $(CC) compiler version.
454 The format is <major><minor> where both are two digits. So for example 474 The format is <major><minor> where both are two digits. So for example
455 gcc 3.41 would return 0341. 475 gcc 3.41 would return 0341.
456 cc-version is useful when a specific $(CC) version is faulty in one 476 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 477 area, for example -mregparm=3 was broken in some gcc versions
458 even though the option was accepted by gcc. 478 even though the option was accepted by gcc.
459 479
460 Example: 480 Example:
@@ -463,20 +483,20 @@ more details, with real examples.
463 if [ $(call cc-version) -ge 0300 ] ; then \ 483 if [ $(call cc-version) -ge 0300 ] ; then \
464 echo "-mregparm=3"; fi ;) 484 echo "-mregparm=3"; fi ;)
465 485
466 In the above example -mregparm=3 is only used for gcc version greater 486 In the above example, -mregparm=3 is only used for gcc version greater
467 than or equal to gcc 3.0. 487 than or equal to gcc 3.0.
468 488
469 cc-ifversion 489 cc-ifversion
470 cc-ifversion test the version of $(CC) and equals last argument if 490 cc-ifversion tests the version of $(CC) and equals last argument if
471 version expression is true. 491 version expression is true.
472 492
473 Example: 493 Example:
474 #fs/reiserfs/Makefile 494 #fs/reiserfs/Makefile
475 EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1) 495 EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1)
476 496
477 In this example EXTRA_CFLAGS will be assigned the value -O1 if the 497 In this example, EXTRA_CFLAGS will be assigned the value -O1 if the
478 $(CC) version is less than 4.2. 498 $(CC) version is less than 4.2.
479 cc-ifversion takes all the shell operators: 499 cc-ifversion takes all the shell operators:
480 -eq, -ne, -lt, -le, -gt, and -ge 500 -eq, -ne, -lt, -le, -gt, and -ge
481 The third parameter may be a text as in this example, but it may also 501 The third parameter may be a text as in this example, but it may also
482 be an expanded variable or a macro. 502 be an expanded variable or a macro.
@@ -492,7 +512,7 @@ The first step is to tell kbuild that a host program exists. This is
492done utilising the variable hostprogs-y. 512done utilising the variable hostprogs-y.
493 513
494The second step is to add an explicit dependency to the executable. 514The second step is to add an explicit dependency to the executable.
495This can be done in two ways. Either add the dependency in a rule, 515This can be done in two ways. Either add the dependency in a rule,
496or utilise the variable $(always). 516or utilise the variable $(always).
497Both possibilities are described in the following. 517Both possibilities are described in the following.
498 518
@@ -509,28 +529,28 @@ Both possibilities are described in the following.
509 Kbuild assumes in the above example that bin2hex is made from a single 529 Kbuild assumes in the above example that bin2hex is made from a single
510 c-source file named bin2hex.c located in the same directory as 530 c-source file named bin2hex.c located in the same directory as
511 the Makefile. 531 the Makefile.
512 532
513--- 4.2 Composite Host Programs 533--- 4.2 Composite Host Programs
514 534
515 Host programs can be made up based on composite objects. 535 Host programs can be made up based on composite objects.
516 The syntax used to define composite objects for host programs is 536 The syntax used to define composite objects for host programs is
517 similar to the syntax used for kernel objects. 537 similar to the syntax used for kernel objects.
518 $(<executeable>-objs) list all objects used to link the final 538 $(<executeable>-objs) lists all objects used to link the final
519 executable. 539 executable.
520 540
521 Example: 541 Example:
522 #scripts/lxdialog/Makefile 542 #scripts/lxdialog/Makefile
523 hostprogs-y := lxdialog 543 hostprogs-y := lxdialog
524 lxdialog-objs := checklist.o lxdialog.o 544 lxdialog-objs := checklist.o lxdialog.o
525 545
526 Objects with extension .o are compiled from the corresponding .c 546 Objects with extension .o are compiled from the corresponding .c
527 files. In the above example checklist.c is compiled to checklist.o 547 files. In the above example, checklist.c is compiled to checklist.o
528 and lxdialog.c is compiled to lxdialog.o. 548 and lxdialog.c is compiled to lxdialog.o.
529 Finally the two .o files are linked to the executable, lxdialog. 549 Finally, the two .o files are linked to the executable, lxdialog.
530 Note: The syntax <executable>-y is not permitted for host-programs. 550 Note: The syntax <executable>-y is not permitted for host-programs.
531 551
532--- 4.3 Defining shared libraries 552--- 4.3 Defining shared libraries
533 553
534 Objects with extension .so are considered shared libraries, and 554 Objects with extension .so are considered shared libraries, and
535 will be compiled as position independent objects. 555 will be compiled as position independent objects.
536 Kbuild provides support for shared libraries, but the usage 556 Kbuild provides support for shared libraries, but the usage
@@ -543,7 +563,7 @@ Both possibilities are described in the following.
543 hostprogs-y := conf 563 hostprogs-y := conf
544 conf-objs := conf.o libkconfig.so 564 conf-objs := conf.o libkconfig.so
545 libkconfig-objs := expr.o type.o 565 libkconfig-objs := expr.o type.o
546 566
547 Shared libraries always require a corresponding -objs line, and 567 Shared libraries always require a corresponding -objs line, and
548 in the example above the shared library libkconfig is composed by 568 in the example above the shared library libkconfig is composed by
549 the two objects expr.o and type.o. 569 the two objects expr.o and type.o.
@@ -564,7 +584,7 @@ Both possibilities are described in the following.
564 584
565 In the example above the executable is composed of the C++ file 585 In the example above the executable is composed of the C++ file
566 qconf.cc - identified by $(qconf-cxxobjs). 586 qconf.cc - identified by $(qconf-cxxobjs).
567 587
568 If qconf is composed by a mixture of .c and .cc files, then an 588 If qconf is composed by a mixture of .c and .cc files, then an
569 additional line can be used to identify this. 589 additional line can be used to identify this.
570 590
@@ -573,34 +593,35 @@ Both possibilities are described in the following.
573 hostprogs-y := qconf 593 hostprogs-y := qconf
574 qconf-cxxobjs := qconf.o 594 qconf-cxxobjs := qconf.o
575 qconf-objs := check.o 595 qconf-objs := check.o
576 596
577--- 4.5 Controlling compiler options for host programs 597--- 4.5 Controlling compiler options for host programs
578 598
579 When compiling host programs, it is possible to set specific flags. 599 When compiling host programs, it is possible to set specific flags.
580 The programs will always be compiled utilising $(HOSTCC) passed 600 The programs will always be compiled utilising $(HOSTCC) passed
581 the options specified in $(HOSTCFLAGS). 601 the options specified in $(HOSTCFLAGS).
582 To set flags that will take effect for all host programs created 602 To set flags that will take effect for all host programs created
583 in that Makefile use the variable HOST_EXTRACFLAGS. 603 in that Makefile, use the variable HOST_EXTRACFLAGS.
584 604
585 Example: 605 Example:
586 #scripts/lxdialog/Makefile 606 #scripts/lxdialog/Makefile
587 HOST_EXTRACFLAGS += -I/usr/include/ncurses 607 HOST_EXTRACFLAGS += -I/usr/include/ncurses
588 608
589 To set specific flags for a single file the following construction 609 To set specific flags for a single file the following construction
590 is used: 610 is used:
591 611
592 Example: 612 Example:
593 #arch/ppc64/boot/Makefile 613 #arch/ppc64/boot/Makefile
594 HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) 614 HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE)
595 615
596 It is also possible to specify additional options to the linker. 616 It is also possible to specify additional options to the linker.
597 617
598 Example: 618 Example:
599 #scripts/kconfig/Makefile 619 #scripts/kconfig/Makefile
600 HOSTLOADLIBES_qconf := -L$(QTDIR)/lib 620 HOSTLOADLIBES_qconf := -L$(QTDIR)/lib
601 621
602 When linking qconf it will be passed the extra option "-L$(QTDIR)/lib". 622 When linking qconf, it will be passed the extra option
603 623 "-L$(QTDIR)/lib".
624
604--- 4.6 When host programs are actually built 625--- 4.6 When host programs are actually built
605 626
606 Kbuild will only build host-programs when they are referenced 627 Kbuild will only build host-programs when they are referenced
@@ -615,7 +636,7 @@ Both possibilities are described in the following.
615 $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist 636 $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
616 ( cd $(obj); ./gen-devlist ) < $< 637 ( cd $(obj); ./gen-devlist ) < $<
617 638
618 The target $(obj)/devlist.h will not be built before 639 The target $(obj)/devlist.h will not be built before
619 $(obj)/gen-devlist is updated. Note that references to 640 $(obj)/gen-devlist is updated. Note that references to
620 the host programs in special rules must be prefixed with $(obj). 641 the host programs in special rules must be prefixed with $(obj).
621 642
@@ -634,7 +655,7 @@ Both possibilities are described in the following.
634 655
635--- 4.7 Using hostprogs-$(CONFIG_FOO) 656--- 4.7 Using hostprogs-$(CONFIG_FOO)
636 657
637 A typcal pattern in a Kbuild file lok like this: 658 A typical pattern in a Kbuild file looks like this:
638 659
639 Example: 660 Example:
640 #scripts/Makefile 661 #scripts/Makefile
@@ -642,13 +663,13 @@ Both possibilities are described in the following.
642 663
643 Kbuild knows about both 'y' for built-in and 'm' for module. 664 Kbuild knows about both 'y' for built-in and 'm' for module.
644 So if a config symbol evaluate to 'm', kbuild will still build 665 So if a config symbol evaluate to 'm', kbuild will still build
645 the binary. In other words Kbuild handle hostprogs-m exactly 666 the binary. In other words, Kbuild handles hostprogs-m exactly
646 like hostprogs-y. But only hostprogs-y is recommend used 667 like hostprogs-y. But only hostprogs-y is recommended to be used
647 when no CONFIG symbol are involved. 668 when no CONFIG symbols are involved.
648 669
649=== 5 Kbuild clean infrastructure 670=== 5 Kbuild clean infrastructure
650 671
651"make clean" deletes most generated files in the src tree where the kernel 672"make clean" deletes most generated files in the obj tree where the kernel
652is compiled. This includes generated files such as host programs. 673is compiled. This includes generated files such as host programs.
653Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always), 674Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always),
654$(extra-y) and $(targets). They are all deleted during "make clean". 675$(extra-y) and $(targets). They are all deleted during "make clean".
@@ -666,7 +687,8 @@ When executing "make clean", the two files "devlist.h classlist.h" will
666be deleted. Kbuild will assume files to be in same relative directory as the 687be deleted. Kbuild will assume files to be in same relative directory as the
667Makefile except if an absolute path is specified (path starting with '/'). 688Makefile except if an absolute path is specified (path starting with '/').
668 689
669To delete a directory hirachy use: 690To delete a directory hierarchy use:
691
670 Example: 692 Example:
671 #scripts/package/Makefile 693 #scripts/package/Makefile
672 clean-dirs := $(objtree)/debian/ 694 clean-dirs := $(objtree)/debian/
@@ -709,29 +731,29 @@ be visited during "make clean".
709 731
710The top level Makefile sets up the environment and does the preparation, 732The top level Makefile sets up the environment and does the preparation,
711before starting to descend down in the individual directories. 733before starting to descend down in the individual directories.
712The top level makefile contains the generic part, whereas the 734The top level makefile contains the generic part, whereas
713arch/$(ARCH)/Makefile contains what is required to set-up kbuild 735arch/$(ARCH)/Makefile contains what is required to set up kbuild
714to the said architecture. 736for said architecture.
715To do so arch/$(ARCH)/Makefile sets a number of variables, and defines 737To do so, arch/$(ARCH)/Makefile sets up a number of variables and defines
716a few targets. 738a few targets.
717 739
718When kbuild executes the following steps are followed (roughly): 740When kbuild executes, the following steps are followed (roughly):
7191) Configuration of the kernel => produced .config 7411) Configuration of the kernel => produce .config
7202) Store kernel version in include/linux/version.h 7422) Store kernel version in include/linux/version.h
7213) Symlink include/asm to include/asm-$(ARCH) 7433) Symlink include/asm to include/asm-$(ARCH)
7224) Updating all other prerequisites to the target prepare: 7444) Updating all other prerequisites to the target prepare:
723 - Additional prerequisites are specified in arch/$(ARCH)/Makefile 745 - Additional prerequisites are specified in arch/$(ARCH)/Makefile
7245) Recursively descend down in all directories listed in 7465) Recursively descend down in all directories listed in
725 init-* core* drivers-* net-* libs-* and build all targets. 747 init-* core* drivers-* net-* libs-* and build all targets.
726 - The value of the above variables are extended in arch/$(ARCH)/Makefile. 748 - The values of the above variables are expanded in arch/$(ARCH)/Makefile.
7276) All object files are then linked and the resulting file vmlinux is 7496) All object files are then linked and the resulting file vmlinux is
728 located at the root of the src tree. 750 located at the root of the obj tree.
729 The very first objects linked are listed in head-y, assigned by 751 The very first objects linked are listed in head-y, assigned by
730 arch/$(ARCH)/Makefile. 752 arch/$(ARCH)/Makefile.
7317) Finally the architecture specific part does any required post processing 7537) Finally, the architecture specific part does any required post processing
732 and builds the final bootimage. 754 and builds the final bootimage.
733 - This includes building boot records 755 - This includes building boot records
734 - Preparing initrd images and the like 756 - Preparing initrd images and thelike
735 757
736 758
737--- 6.1 Set variables to tweak the build to the architecture 759--- 6.1 Set variables to tweak the build to the architecture
@@ -746,7 +768,7 @@ When kbuild executes the following steps are followed (roughly):
746 LDFLAGS := -m elf_s390 768 LDFLAGS := -m elf_s390
747 Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise 769 Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise
748 the flags used. See chapter 7. 770 the flags used. See chapter 7.
749 771
750 LDFLAGS_MODULE Options for $(LD) when linking modules 772 LDFLAGS_MODULE Options for $(LD) when linking modules
751 773
752 LDFLAGS_MODULE is used to set specific flags for $(LD) when 774 LDFLAGS_MODULE is used to set specific flags for $(LD) when
@@ -756,7 +778,7 @@ When kbuild executes the following steps are followed (roughly):
756 LDFLAGS_vmlinux Options for $(LD) when linking vmlinux 778 LDFLAGS_vmlinux Options for $(LD) when linking vmlinux
757 779
758 LDFLAGS_vmlinux is used to specify additional flags to pass to 780 LDFLAGS_vmlinux is used to specify additional flags to pass to
759 the linker when linking the final vmlinux. 781 the linker when linking the final vmlinux image.
760 LDFLAGS_vmlinux uses the LDFLAGS_$@ support. 782 LDFLAGS_vmlinux uses the LDFLAGS_$@ support.
761 783
762 Example: 784 Example:
@@ -766,7 +788,7 @@ When kbuild executes the following steps are followed (roughly):
766 OBJCOPYFLAGS objcopy flags 788 OBJCOPYFLAGS objcopy flags
767 789
768 When $(call if_changed,objcopy) is used to translate a .o file, 790 When $(call if_changed,objcopy) is used to translate a .o file,
769 then the flags specified in OBJCOPYFLAGS will be used. 791 the flags specified in OBJCOPYFLAGS will be used.
770 $(call if_changed,objcopy) is often used to generate raw binaries on 792 $(call if_changed,objcopy) is often used to generate raw binaries on
771 vmlinux. 793 vmlinux.
772 794
@@ -778,7 +800,7 @@ When kbuild executes the following steps are followed (roughly):
778 $(obj)/image: vmlinux FORCE 800 $(obj)/image: vmlinux FORCE
779 $(call if_changed,objcopy) 801 $(call if_changed,objcopy)
780 802
781 In this example the binary $(obj)/image is a binary version of 803 In this example, the binary $(obj)/image is a binary version of
782 vmlinux. The usage of $(call if_changed,xxx) will be described later. 804 vmlinux. The usage of $(call if_changed,xxx) will be described later.
783 805
784 AFLAGS $(AS) assembler flags 806 AFLAGS $(AS) assembler flags
@@ -795,7 +817,7 @@ When kbuild executes the following steps are followed (roughly):
795 Default value - see top level Makefile 817 Default value - see top level Makefile
796 Append or modify as required per architecture. 818 Append or modify as required per architecture.
797 819
798 Often the CFLAGS variable depends on the configuration. 820 Often, the CFLAGS variable depends on the configuration.
799 821
800 Example: 822 Example:
801 #arch/i386/Makefile 823 #arch/i386/Makefile
@@ -816,7 +838,7 @@ When kbuild executes the following steps are followed (roughly):
816 ... 838 ...
817 839
818 840
819 The first examples utilises the trick that a config option expands 841 The first example utilises the trick that a config option expands
820 to 'y' when selected. 842 to 'y' when selected.
821 843
822 CFLAGS_KERNEL $(CC) options specific for built-in 844 CFLAGS_KERNEL $(CC) options specific for built-in
@@ -829,18 +851,18 @@ When kbuild executes the following steps are followed (roughly):
829 $(CFLAGS_MODULE) contains extra C compiler flags used to compile code 851 $(CFLAGS_MODULE) contains extra C compiler flags used to compile code
830 for loadable kernel modules. 852 for loadable kernel modules.
831 853
832 854
833--- 6.2 Add prerequisites to archprepare: 855--- 6.2 Add prerequisites to archprepare:
834 856
835 The archprepare: rule is used to list prerequisites that needs to be 857 The archprepare: rule is used to list prerequisites that need to be
836 built before starting to descend down in the subdirectories. 858 built before starting to descend down in the subdirectories.
837 This is usual header files containing assembler constants. 859 This is usually used for header files containing assembler constants.
838 860
839 Example: 861 Example:
840 #arch/arm/Makefile 862 #arch/arm/Makefile
841 archprepare: maketools 863 archprepare: maketools
842 864
843 In this example the file target maketools will be processed 865 In this example, the file target maketools will be processed
844 before descending down in the subdirectories. 866 before descending down in the subdirectories.
845 See also chapter XXX-TODO that describe how kbuild supports 867 See also chapter XXX-TODO that describe how kbuild supports
846 generating offset header files. 868 generating offset header files.
@@ -853,18 +875,19 @@ When kbuild executes the following steps are followed (roughly):
853 corresponding arch-specific section for modules; the module-building 875 corresponding arch-specific section for modules; the module-building
854 machinery is all architecture-independent. 876 machinery is all architecture-independent.
855 877
856 878
857 head-y, init-y, core-y, libs-y, drivers-y, net-y 879 head-y, init-y, core-y, libs-y, drivers-y, net-y
858 880
859 $(head-y) list objects to be linked first in vmlinux. 881 $(head-y) lists objects to be linked first in vmlinux.
860 $(libs-y) list directories where a lib.a archive can be located. 882 $(libs-y) lists directories where a lib.a archive can be located.
861 The rest list directories where a built-in.o object file can be located. 883 The rest lists directories where a built-in.o object file can be
884 located.
862 885
863 $(init-y) objects will be located after $(head-y). 886 $(init-y) objects will be located after $(head-y).
864 Then the rest follows in this order: 887 Then the rest follows in this order:
865 $(core-y), $(libs-y), $(drivers-y) and $(net-y). 888 $(core-y), $(libs-y), $(drivers-y) and $(net-y).
866 889
867 The top level Makefile define values for all generic directories, 890 The top level Makefile defines values for all generic directories,
868 and arch/$(ARCH)/Makefile only adds architecture specific directories. 891 and arch/$(ARCH)/Makefile only adds architecture specific directories.
869 892
870 Example: 893 Example:
@@ -901,27 +924,27 @@ When kbuild executes the following steps are followed (roughly):
901 "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke 924 "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke
902 make in a subdirectory. 925 make in a subdirectory.
903 926
904 There are no rules for naming of the architecture specific targets, 927 There are no rules for naming architecture specific targets,
905 but executing "make help" will list all relevant targets. 928 but executing "make help" will list all relevant targets.
906 To support this $(archhelp) must be defined. 929 To support this, $(archhelp) must be defined.
907 930
908 Example: 931 Example:
909 #arch/i386/Makefile 932 #arch/i386/Makefile
910 define archhelp 933 define archhelp
911 echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)' 934 echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)'
912 endef 935 endif
913 936
914 When make is executed without arguments, the first goal encountered 937 When make is executed without arguments, the first goal encountered
915 will be built. In the top level Makefile the first goal present 938 will be built. In the top level Makefile the first goal present
916 is all:. 939 is all:.
917 An architecture shall always per default build a bootable image. 940 An architecture shall always, per default, build a bootable image.
918 In "make help" the default goal is highlighted with a '*'. 941 In "make help", the default goal is highlighted with a '*'.
919 Add a new prerequisite to all: to select a default goal different 942 Add a new prerequisite to all: to select a default goal different
920 from vmlinux. 943 from vmlinux.
921 944
922 Example: 945 Example:
923 #arch/i386/Makefile 946 #arch/i386/Makefile
924 all: bzImage 947 all: bzImage
925 948
926 When "make" is executed without arguments, bzImage will be built. 949 When "make" is executed without arguments, bzImage will be built.
927 950
@@ -941,10 +964,10 @@ When kbuild executes the following steps are followed (roughly):
941 #arch/i386/kernel/Makefile 964 #arch/i386/kernel/Makefile
942 extra-y := head.o init_task.o 965 extra-y := head.o init_task.o
943 966
944 In this example extra-y is used to list object files that 967 In this example, extra-y is used to list object files that
945 shall be built, but shall not be linked as part of built-in.o. 968 shall be built, but shall not be linked as part of built-in.o.
946 969
947 970
948--- 6.6 Commands useful for building a boot image 971--- 6.6 Commands useful for building a boot image
949 972
950 Kbuild provides a few macros that are useful when building a 973 Kbuild provides a few macros that are useful when building a
@@ -958,8 +981,8 @@ When kbuild executes the following steps are followed (roughly):
958 target: source(s) FORCE 981 target: source(s) FORCE
959 $(call if_changed,ld/objcopy/gzip) 982 $(call if_changed,ld/objcopy/gzip)
960 983
961 When the rule is evaluated it is checked to see if any files 984 When the rule is evaluated, it is checked to see if any files
962 needs an update, or the commandline has changed since last 985 needs an update, or the command line has changed since the last
963 invocation. The latter will force a rebuild if any options 986 invocation. The latter will force a rebuild if any options
964 to the executable have changed. 987 to the executable have changed.
965 Any target that utilises if_changed must be listed in $(targets), 988 Any target that utilises if_changed must be listed in $(targets),
@@ -977,8 +1000,8 @@ When kbuild executes the following steps are followed (roughly):
977 #WRONG!# $(call if_changed, ld/objcopy/gzip) 1000 #WRONG!# $(call if_changed, ld/objcopy/gzip)
978 1001
979 ld 1002 ld
980 Link target. Often LDFLAGS_$@ is used to set specific options to ld. 1003 Link target. Often, LDFLAGS_$@ is used to set specific options to ld.
981 1004
982 objcopy 1005 objcopy
983 Copy binary. Uses OBJCOPYFLAGS usually specified in 1006 Copy binary. Uses OBJCOPYFLAGS usually specified in
984 arch/$(ARCH)/Makefile. 1007 arch/$(ARCH)/Makefile.
@@ -996,10 +1019,10 @@ When kbuild executes the following steps are followed (roughly):
996 $(obj)/setup $(obj)/bootsect: %: %.o FORCE 1019 $(obj)/setup $(obj)/bootsect: %: %.o FORCE
997 $(call if_changed,ld) 1020 $(call if_changed,ld)
998 1021
999 In this example there are two possible targets, requiring different 1022 In this example, there are two possible targets, requiring different
1000 options to the linker. the linker options are specified using the 1023 options to the linker. The linker options are specified using the
1001 LDFLAGS_$@ syntax - one for each potential target. 1024 LDFLAGS_$@ syntax - one for each potential target.
1002 $(targets) are assinged all potential targets, herby kbuild knows 1025 $(targets) are assinged all potential targets, by which kbuild knows
1003 the targets and will: 1026 the targets and will:
1004 1) check for commandline changes 1027 1) check for commandline changes
1005 2) delete target during make clean 1028 2) delete target during make clean
@@ -1013,7 +1036,7 @@ When kbuild executes the following steps are followed (roughly):
1013 1036
1014--- 6.7 Custom kbuild commands 1037--- 6.7 Custom kbuild commands
1015 1038
1016 When kbuild is executing with KBUILD_VERBOSE=0 then only a shorthand 1039 When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
1017 of a command is normally displayed. 1040 of a command is normally displayed.
1018 To enable this behaviour for custom commands kbuild requires 1041 To enable this behaviour for custom commands kbuild requires
1019 two variables to be set: 1042 two variables to be set:
@@ -1031,34 +1054,34 @@ When kbuild executes the following steps are followed (roughly):
1031 $(call if_changed,image) 1054 $(call if_changed,image)
1032 @echo 'Kernel: $@ is ready' 1055 @echo 'Kernel: $@ is ready'
1033 1056
1034 When updating the $(obj)/bzImage target the line: 1057 When updating the $(obj)/bzImage target, the line
1035 1058
1036 BUILD arch/i386/boot/bzImage 1059 BUILD arch/i386/boot/bzImage
1037 1060
1038 will be displayed with "make KBUILD_VERBOSE=0". 1061 will be displayed with "make KBUILD_VERBOSE=0".
1039 1062
1040 1063
1041--- 6.8 Preprocessing linker scripts 1064--- 6.8 Preprocessing linker scripts
1042 1065
1043 When the vmlinux image is build the linker script: 1066 When the vmlinux image is built, the linker script
1044 arch/$(ARCH)/kernel/vmlinux.lds is used. 1067 arch/$(ARCH)/kernel/vmlinux.lds is used.
1045 The script is a preprocessed variant of the file vmlinux.lds.S 1068 The script is a preprocessed variant of the file vmlinux.lds.S
1046 located in the same directory. 1069 located in the same directory.
1047 kbuild knows .lds file and includes a rule *lds.S -> *lds. 1070 kbuild knows .lds files and includes a rule *lds.S -> *lds.
1048 1071
1049 Example: 1072 Example:
1050 #arch/i386/kernel/Makefile 1073 #arch/i386/kernel/Makefile
1051 always := vmlinux.lds 1074 always := vmlinux.lds
1052 1075
1053 #Makefile 1076 #Makefile
1054 export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) 1077 export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
1055 1078
1056 The assigment to $(always) is used to tell kbuild to build the 1079 The assignment to $(always) is used to tell kbuild to build the
1057 target: vmlinux.lds. 1080 target vmlinux.lds.
1058 The assignment to $(CPPFLAGS_vmlinux.lds) tell kbuild to use the 1081 The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the
1059 specified options when building the target vmlinux.lds. 1082 specified options when building the target vmlinux.lds.
1060 1083
1061 When building the *.lds target kbuild used the variakles: 1084 When building the *.lds target, kbuild uses the variables:
1062 CPPFLAGS : Set in top-level Makefile 1085 CPPFLAGS : Set in top-level Makefile
1063 EXTRA_CPPFLAGS : May be set in the kbuild makefile 1086 EXTRA_CPPFLAGS : May be set in the kbuild makefile
1064 CPPFLAGS_$(@F) : Target specific flags. 1087 CPPFLAGS_$(@F) : Target specific flags.
@@ -1123,9 +1146,17 @@ The top Makefile exports the following variables:
1123 $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may 1146 $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may
1124 override this value on the command line if desired. 1147 override this value on the command line if desired.
1125 1148
1149 INSTALL_MOD_STRIP
1150
1151 If this variable is specified, will cause modules to be stripped
1152 after they are installed. If INSTALL_MOD_STRIP is '1', then the
1153 default option --strip-debug will be used. Otherwise,
1154 INSTALL_MOD_STRIP will used as the option(s) to the strip command.
1155
1156
1126=== 8 Makefile language 1157=== 8 Makefile language
1127 1158
1128The kernel Makefiles are designed to run with GNU Make. The Makefiles 1159The kernel Makefiles are designed to be run with GNU Make. The Makefiles
1129use only the documented features of GNU Make, but they do use many 1160use only the documented features of GNU Make, but they do use many
1130GNU extensions. 1161GNU extensions.
1131 1162
@@ -1147,10 +1178,13 @@ is the right choice.
1147Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net> 1178Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
1148Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de> 1179Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
1149Updates by Sam Ravnborg <sam@ravnborg.org> 1180Updates by Sam Ravnborg <sam@ravnborg.org>
1181Language QA by Jan Engelhardt <jengelh@gmx.de>
1150 1182
1151=== 10 TODO 1183=== 10 TODO
1152 1184
1153- Describe how kbuild support shipped files with _shipped. 1185- Describe how kbuild supports shipped files with _shipped.
1154- Generating offset header files. 1186- Generating offset header files.
1155- Add more variables to section 7? 1187- Add more variables to section 7?
1156 1188
1189
1190