diff options
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/kbuild/makefiles.txt | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 3d2f88ea14a5..b7d6abb501a6 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 | ||
70 | Each subdirectory has a kbuild Makefile which carries out the commands | 70 | Each subdirectory has a kbuild Makefile which carries out the commands |
71 | passed down from above. The kbuild Makefile uses information from the | 71 | passed 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 |
73 | any built-in or modular targets. | 73 | any built-in or modular targets. |
74 | 74 | ||
75 | scripts/Makefile.* contains all the definitions/rules etc. that | 75 | scripts/Makefile.* contains all the definitions/rules etc. that |
@@ -203,9 +203,9 @@ 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 | ||
@@ -244,7 +244,7 @@ more details, with real examples. | |||
244 | For kbuild to actually recognize that there is a lib.a being built, | 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 | Use 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 |
@@ -408,7 +408,7 @@ more details, with real examples. | |||
408 | if first argument is not supported. | 408 | if first argument is not supported. |
409 | 409 | ||
410 | ld-option | 410 | ld-option |
411 | ld-option is used to check if $(CC) when used to link object files | 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 | 412 | supports the given option. An optional second option may be |
413 | specified if first option are not supported. | 413 | specified if first option are not supported. |
414 | 414 | ||
@@ -435,7 +435,7 @@ more details, with real examples. | |||
435 | cflags-y will be assigned no value if first option is not supported. | 435 | cflags-y will be assigned no value if first option is not supported. |
436 | 436 | ||
437 | cc-option-yn | 437 | cc-option-yn |
438 | cc-option-yn is used to check if gcc supports a given option | 438 | cc-option-yn is used to check if gcc supports a given option |
439 | and return 'y' if supported, otherwise 'n'. | 439 | and return 'y' if supported, otherwise 'n'. |
440 | 440 | ||
441 | Example: | 441 | Example: |
@@ -443,7 +443,7 @@ more details, with real examples. | |||
443 | biarch := $(call cc-option-yn, -m32) | 443 | biarch := $(call cc-option-yn, -m32) |
444 | aflags-$(biarch) += -a32 | 444 | aflags-$(biarch) += -a32 |
445 | cflags-$(biarch) += -m32 | 445 | cflags-$(biarch) += -m32 |
446 | 446 | ||
447 | In the above example, $(biarch) is set to y if $(CC) supports the -m32 | 447 | In the above example, $(biarch) is set to y if $(CC) supports the -m32 |
448 | option. When $(biarch) equals 'y', the expanded variables $(aflags-y) | 448 | option. When $(biarch) equals 'y', the expanded variables $(aflags-y) |
449 | and $(cflags-y) will be assigned the values -a32 and -m32, | 449 | and $(cflags-y) will be assigned the values -a32 and -m32, |
@@ -457,13 +457,13 @@ more details, with real examples. | |||
457 | cc-option-align = -malign | 457 | cc-option-align = -malign |
458 | gcc >= 3.00 | 458 | gcc >= 3.00 |
459 | cc-option-align = -falign | 459 | cc-option-align = -falign |
460 | 460 | ||
461 | Example: | 461 | Example: |
462 | CFLAGS += $(cc-option-align)-functions=4 | 462 | CFLAGS += $(cc-option-align)-functions=4 |
463 | 463 | ||
464 | In the above example, the option -falign-functions=4 is used for | 464 | In the above example, the option -falign-functions=4 is used for |
465 | gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used. | 465 | gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used. |
466 | 466 | ||
467 | cc-version | 467 | cc-version |
468 | cc-version returns a numerical version of the $(CC) compiler version. | 468 | cc-version returns a numerical version of the $(CC) compiler version. |
469 | The format is <major><minor> where both are two digits. So for example | 469 | The format is <major><minor> where both are two digits. So for example |
@@ -491,7 +491,7 @@ more details, with real examples. | |||
491 | 491 | ||
492 | In this example, EXTRA_CFLAGS will be assigned the value -O1 if the | 492 | In this example, EXTRA_CFLAGS will be assigned the value -O1 if the |
493 | $(CC) version is less than 4.2. | 493 | $(CC) version is less than 4.2. |
494 | cc-ifversion takes all the shell operators: | 494 | cc-ifversion takes all the shell operators: |
495 | -eq, -ne, -lt, -le, -gt, and -ge | 495 | -eq, -ne, -lt, -le, -gt, and -ge |
496 | The third parameter may be a text as in this example, but it may also | 496 | The third parameter may be a text as in this example, but it may also |
497 | be an expanded variable or a macro. | 497 | be an expanded variable or a macro. |
@@ -507,7 +507,7 @@ The first step is to tell kbuild that a host program exists. This is | |||
507 | done utilising the variable hostprogs-y. | 507 | done utilising the variable hostprogs-y. |
508 | 508 | ||
509 | The second step is to add an explicit dependency to the executable. | 509 | The second step is to add an explicit dependency to the executable. |
510 | This can be done in two ways. Either add the dependency in a rule, | 510 | This can be done in two ways. Either add the dependency in a rule, |
511 | or utilise the variable $(always). | 511 | or utilise the variable $(always). |
512 | Both possibilities are described in the following. | 512 | Both possibilities are described in the following. |
513 | 513 | ||
@@ -524,7 +524,7 @@ Both possibilities are described in the following. | |||
524 | Kbuild assumes in the above example that bin2hex is made from a single | 524 | Kbuild assumes in the above example that bin2hex is made from a single |
525 | c-source file named bin2hex.c located in the same directory as | 525 | c-source file named bin2hex.c located in the same directory as |
526 | the Makefile. | 526 | the Makefile. |
527 | 527 | ||
528 | --- 4.2 Composite Host Programs | 528 | --- 4.2 Composite Host Programs |
529 | 529 | ||
530 | Host programs can be made up based on composite objects. | 530 | Host programs can be made up based on composite objects. |
@@ -535,7 +535,7 @@ Both possibilities are described in the following. | |||
535 | 535 | ||
536 | Example: | 536 | Example: |
537 | #scripts/lxdialog/Makefile | 537 | #scripts/lxdialog/Makefile |
538 | hostprogs-y := lxdialog | 538 | hostprogs-y := lxdialog |
539 | lxdialog-objs := checklist.o lxdialog.o | 539 | lxdialog-objs := checklist.o lxdialog.o |
540 | 540 | ||
541 | Objects with extension .o are compiled from the corresponding .c | 541 | Objects with extension .o are compiled from the corresponding .c |
@@ -544,8 +544,8 @@ Both possibilities are described in the following. | |||
544 | Finally, the two .o files are linked to the executable, lxdialog. | 544 | Finally, the two .o files are linked to the executable, lxdialog. |
545 | Note: The syntax <executable>-y is not permitted for host-programs. | 545 | Note: The syntax <executable>-y is not permitted for host-programs. |
546 | 546 | ||
547 | --- 4.3 Defining shared libraries | 547 | --- 4.3 Defining shared libraries |
548 | 548 | ||
549 | Objects with extension .so are considered shared libraries, and | 549 | Objects with extension .so are considered shared libraries, and |
550 | will be compiled as position independent objects. | 550 | will be compiled as position independent objects. |
551 | Kbuild provides support for shared libraries, but the usage | 551 | Kbuild provides support for shared libraries, but the usage |
@@ -558,7 +558,7 @@ Both possibilities are described in the following. | |||
558 | hostprogs-y := conf | 558 | hostprogs-y := conf |
559 | conf-objs := conf.o libkconfig.so | 559 | conf-objs := conf.o libkconfig.so |
560 | libkconfig-objs := expr.o type.o | 560 | libkconfig-objs := expr.o type.o |
561 | 561 | ||
562 | Shared libraries always require a corresponding -objs line, and | 562 | Shared libraries always require a corresponding -objs line, and |
563 | in the example above the shared library libkconfig is composed by | 563 | in the example above the shared library libkconfig is composed by |
564 | the two objects expr.o and type.o. | 564 | the two objects expr.o and type.o. |
@@ -579,7 +579,7 @@ Both possibilities are described in the following. | |||
579 | 579 | ||
580 | In the example above the executable is composed of the C++ file | 580 | In the example above the executable is composed of the C++ file |
581 | qconf.cc - identified by $(qconf-cxxobjs). | 581 | qconf.cc - identified by $(qconf-cxxobjs). |
582 | 582 | ||
583 | If qconf is composed by a mixture of .c and .cc files, then an | 583 | If qconf is composed by a mixture of .c and .cc files, then an |
584 | additional line can be used to identify this. | 584 | additional line can be used to identify this. |
585 | 585 | ||
@@ -588,7 +588,7 @@ Both possibilities are described in the following. | |||
588 | hostprogs-y := qconf | 588 | hostprogs-y := qconf |
589 | qconf-cxxobjs := qconf.o | 589 | qconf-cxxobjs := qconf.o |
590 | qconf-objs := check.o | 590 | qconf-objs := check.o |
591 | 591 | ||
592 | --- 4.5 Controlling compiler options for host programs | 592 | --- 4.5 Controlling compiler options for host programs |
593 | 593 | ||
594 | When compiling host programs, it is possible to set specific flags. | 594 | When compiling host programs, it is possible to set specific flags. |
@@ -600,23 +600,23 @@ Both possibilities are described in the following. | |||
600 | Example: | 600 | Example: |
601 | #scripts/lxdialog/Makefile | 601 | #scripts/lxdialog/Makefile |
602 | HOST_EXTRACFLAGS += -I/usr/include/ncurses | 602 | HOST_EXTRACFLAGS += -I/usr/include/ncurses |
603 | 603 | ||
604 | To set specific flags for a single file the following construction | 604 | To set specific flags for a single file the following construction |
605 | is used: | 605 | is used: |
606 | 606 | ||
607 | Example: | 607 | Example: |
608 | #arch/ppc64/boot/Makefile | 608 | #arch/ppc64/boot/Makefile |
609 | HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) | 609 | HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) |
610 | 610 | ||
611 | It is also possible to specify additional options to the linker. | 611 | It is also possible to specify additional options to the linker. |
612 | 612 | ||
613 | Example: | 613 | Example: |
614 | #scripts/kconfig/Makefile | 614 | #scripts/kconfig/Makefile |
615 | HOSTLOADLIBES_qconf := -L$(QTDIR)/lib | 615 | HOSTLOADLIBES_qconf := -L$(QTDIR)/lib |
616 | 616 | ||
617 | When linking qconf, it will be passed the extra option | 617 | When linking qconf, it will be passed the extra option |
618 | "-L$(QTDIR)/lib". | 618 | "-L$(QTDIR)/lib". |
619 | 619 | ||
620 | --- 4.6 When host programs are actually built | 620 | --- 4.6 When host programs are actually built |
621 | 621 | ||
622 | Kbuild will only build host-programs when they are referenced | 622 | Kbuild will only build host-programs when they are referenced |
@@ -631,7 +631,7 @@ Both possibilities are described in the following. | |||
631 | $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist | 631 | $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist |
632 | ( cd $(obj); ./gen-devlist ) < $< | 632 | ( cd $(obj); ./gen-devlist ) < $< |
633 | 633 | ||
634 | The target $(obj)/devlist.h will not be built before | 634 | The target $(obj)/devlist.h will not be built before |
635 | $(obj)/gen-devlist is updated. Note that references to | 635 | $(obj)/gen-devlist is updated. Note that references to |
636 | the host programs in special rules must be prefixed with $(obj). | 636 | the host programs in special rules must be prefixed with $(obj). |
637 | 637 | ||
@@ -650,7 +650,7 @@ Both possibilities are described in the following. | |||
650 | 650 | ||
651 | --- 4.7 Using hostprogs-$(CONFIG_FOO) | 651 | --- 4.7 Using hostprogs-$(CONFIG_FOO) |
652 | 652 | ||
653 | A typcal pattern in a Kbuild file looks like this: | 653 | A typical pattern in a Kbuild file looks like this: |
654 | 654 | ||
655 | Example: | 655 | Example: |
656 | #scripts/Makefile | 656 | #scripts/Makefile |
@@ -682,7 +682,8 @@ When executing "make clean", the two files "devlist.h classlist.h" will | |||
682 | be deleted. Kbuild will assume files to be in same relative directory as the | 682 | be deleted. Kbuild will assume files to be in same relative directory as the |
683 | Makefile except if an absolute path is specified (path starting with '/'). | 683 | Makefile except if an absolute path is specified (path starting with '/'). |
684 | 684 | ||
685 | To delete a directory hirachy use: | 685 | To delete a directory hierarchy use: |
686 | |||
686 | Example: | 687 | Example: |
687 | #scripts/package/Makefile | 688 | #scripts/package/Makefile |
688 | clean-dirs := $(objtree)/debian/ | 689 | clean-dirs := $(objtree)/debian/ |
@@ -740,7 +741,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
740 | 5) Recursively descend down in all directories listed in | 741 | 5) Recursively descend down in all directories listed in |
741 | init-* core* drivers-* net-* libs-* and build all targets. | 742 | init-* core* drivers-* net-* libs-* and build all targets. |
742 | - The values of the above variables are expanded in arch/$(ARCH)/Makefile. | 743 | - The values of the above variables are expanded in arch/$(ARCH)/Makefile. |
743 | 6) All object files are then linked and the resulting file vmlinux is | 744 | 6) All object files are then linked and the resulting file vmlinux is |
744 | located at the root of the obj tree. | 745 | located at the root of the obj tree. |
745 | The very first objects linked are listed in head-y, assigned by | 746 | The very first objects linked are listed in head-y, assigned by |
746 | arch/$(ARCH)/Makefile. | 747 | arch/$(ARCH)/Makefile. |
@@ -762,7 +763,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
762 | LDFLAGS := -m elf_s390 | 763 | LDFLAGS := -m elf_s390 |
763 | Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise | 764 | Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise |
764 | the flags used. See chapter 7. | 765 | the flags used. See chapter 7. |
765 | 766 | ||
766 | LDFLAGS_MODULE Options for $(LD) when linking modules | 767 | LDFLAGS_MODULE Options for $(LD) when linking modules |
767 | 768 | ||
768 | LDFLAGS_MODULE is used to set specific flags for $(LD) when | 769 | LDFLAGS_MODULE is used to set specific flags for $(LD) when |
@@ -845,7 +846,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
845 | $(CFLAGS_MODULE) contains extra C compiler flags used to compile code | 846 | $(CFLAGS_MODULE) contains extra C compiler flags used to compile code |
846 | for loadable kernel modules. | 847 | for loadable kernel modules. |
847 | 848 | ||
848 | 849 | ||
849 | --- 6.2 Add prerequisites to archprepare: | 850 | --- 6.2 Add prerequisites to archprepare: |
850 | 851 | ||
851 | The archprepare: rule is used to list prerequisites that need to be | 852 | The archprepare: rule is used to list prerequisites that need to be |
@@ -869,7 +870,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
869 | corresponding arch-specific section for modules; the module-building | 870 | corresponding arch-specific section for modules; the module-building |
870 | machinery is all architecture-independent. | 871 | machinery is all architecture-independent. |
871 | 872 | ||
872 | 873 | ||
873 | head-y, init-y, core-y, libs-y, drivers-y, net-y | 874 | head-y, init-y, core-y, libs-y, drivers-y, net-y |
874 | 875 | ||
875 | $(head-y) lists objects to be linked first in vmlinux. | 876 | $(head-y) lists objects to be linked first in vmlinux. |
@@ -926,7 +927,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
926 | #arch/i386/Makefile | 927 | #arch/i386/Makefile |
927 | define archhelp | 928 | define archhelp |
928 | echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)' | 929 | echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)' |
929 | endef | 930 | endif |
930 | 931 | ||
931 | When make is executed without arguments, the first goal encountered | 932 | When make is executed without arguments, the first goal encountered |
932 | will be built. In the top level Makefile the first goal present | 933 | will be built. In the top level Makefile the first goal present |
@@ -938,7 +939,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
938 | 939 | ||
939 | Example: | 940 | Example: |
940 | #arch/i386/Makefile | 941 | #arch/i386/Makefile |
941 | all: bzImage | 942 | all: bzImage |
942 | 943 | ||
943 | When "make" is executed without arguments, bzImage will be built. | 944 | When "make" is executed without arguments, bzImage will be built. |
944 | 945 | ||
@@ -961,7 +962,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
961 | In this example, extra-y is used to list object files that | 962 | In this example, extra-y is used to list object files that |
962 | shall be built, but shall not be linked as part of built-in.o. | 963 | shall be built, but shall not be linked as part of built-in.o. |
963 | 964 | ||
964 | 965 | ||
965 | --- 6.6 Commands useful for building a boot image | 966 | --- 6.6 Commands useful for building a boot image |
966 | 967 | ||
967 | Kbuild provides a few macros that are useful when building a | 968 | Kbuild provides a few macros that are useful when building a |
@@ -995,7 +996,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
995 | 996 | ||
996 | ld | 997 | ld |
997 | Link target. Often, LDFLAGS_$@ is used to set specific options to ld. | 998 | Link target. Often, LDFLAGS_$@ is used to set specific options to ld. |
998 | 999 | ||
999 | objcopy | 1000 | objcopy |
1000 | Copy binary. Uses OBJCOPYFLAGS usually specified in | 1001 | Copy binary. Uses OBJCOPYFLAGS usually specified in |
1001 | arch/$(ARCH)/Makefile. | 1002 | arch/$(ARCH)/Makefile. |
@@ -1053,7 +1054,7 @@ When kbuild executes, the following steps are followed (roughly): | |||
1053 | BUILD arch/i386/boot/bzImage | 1054 | BUILD arch/i386/boot/bzImage |
1054 | 1055 | ||
1055 | will be displayed with "make KBUILD_VERBOSE=0". | 1056 | will be displayed with "make KBUILD_VERBOSE=0". |
1056 | 1057 | ||
1057 | 1058 | ||
1058 | --- 6.8 Preprocessing linker scripts | 1059 | --- 6.8 Preprocessing linker scripts |
1059 | 1060 | ||
@@ -1062,19 +1063,19 @@ When kbuild executes, the following steps are followed (roughly): | |||
1062 | The script is a preprocessed variant of the file vmlinux.lds.S | 1063 | The script is a preprocessed variant of the file vmlinux.lds.S |
1063 | located in the same directory. | 1064 | located in the same directory. |
1064 | kbuild knows .lds files and includes a rule *lds.S -> *lds. | 1065 | kbuild knows .lds files and includes a rule *lds.S -> *lds. |
1065 | 1066 | ||
1066 | Example: | 1067 | Example: |
1067 | #arch/i386/kernel/Makefile | 1068 | #arch/i386/kernel/Makefile |
1068 | always := vmlinux.lds | 1069 | always := vmlinux.lds |
1069 | 1070 | ||
1070 | #Makefile | 1071 | #Makefile |
1071 | export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) | 1072 | export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) |
1072 | 1073 | ||
1073 | The assigment to $(always) is used to tell kbuild to build the | 1074 | The assignment to $(always) is used to tell kbuild to build the |
1074 | target vmlinux.lds. | 1075 | target vmlinux.lds. |
1075 | The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the | 1076 | The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the |
1076 | specified options when building the target vmlinux.lds. | 1077 | specified options when building the target vmlinux.lds. |
1077 | 1078 | ||
1078 | When building the *.lds target, kbuild uses the variables: | 1079 | When building the *.lds target, kbuild uses the variables: |
1079 | CPPFLAGS : Set in top-level Makefile | 1080 | CPPFLAGS : Set in top-level Makefile |
1080 | EXTRA_CPPFLAGS : May be set in the kbuild makefile | 1081 | EXTRA_CPPFLAGS : May be set in the kbuild makefile |
@@ -1180,3 +1181,5 @@ Language QA by Jan Engelhardt <jengelh@gmx.de> | |||
1180 | - Generating offset header files. | 1181 | - Generating offset header files. |
1181 | - Add more variables to section 7? | 1182 | - Add more variables to section 7? |
1182 | 1183 | ||
1184 | |||
1185 | |||