kbuild: doc: merge 'Special Rules' and 'Custom kbuild commands' sections
[linux-2.6-microblaze.git] / Documentation / kbuild / makefiles.rst
index 0d5dd54..87ff7c6 100644 (file)
@@ -18,7 +18,7 @@ This document describes the Linux kernel Makefiles.
           --- 3.7 Compilation flags
           --- 3.8 <deleted>
           --- 3.9 Dependency tracking
-          --- 3.10 Special Rules
+          --- 3.10 Custom Rules
           --- 3.11 $(CC) support functions
           --- 3.12 $(LD) support functions
           --- 3.13 Script Invocation
@@ -46,7 +46,7 @@ This document describes the Linux kernel Makefiles.
           --- 7.5 Architecture-specific boot images
           --- 7.6 Building non-kbuild targets
           --- 7.7 Commands useful for building a boot image
-          --- 7.8 Custom kbuild commands
+          --- 7.8 <deleted>
           --- 7.9 Preprocessing linker scripts
           --- 7.10 Generic header files
           --- 7.11 Post-link pass
@@ -67,11 +67,11 @@ This document describes the Linux kernel Makefiles.
 
 The Makefiles have five parts::
 
-       Makefile                the top Makefile.
-       .config                 the kernel configuration file.
-       arch/$(ARCH)/Makefile   the arch Makefile.
-       scripts/Makefile.*      common rules etc. for all kbuild Makefiles.
-       kbuild Makefiles        there are about 500 of these.
+       Makefile                    the top Makefile.
+       .config                     the kernel configuration file.
+       arch/$(SRCARCH)/Makefile    the arch Makefile.
+       scripts/Makefile.*          common rules etc. for all kbuild Makefiles.
+       kbuild Makefiles            exist in every subdirectory
 
 The top Makefile reads the .config file, which comes from the kernel
 configuration process.
@@ -82,7 +82,7 @@ It builds these goals by recursively descending into the subdirectories of
 the kernel source tree.
 The list of subdirectories which are visited depends upon the kernel
 configuration. The top Makefile textually includes an arch Makefile
-with the name arch/$(ARCH)/Makefile. The arch Makefile supplies
+with the name arch/$(SRCARCH)/Makefile. The arch Makefile supplies
 architecture-specific information to the top Makefile.
 
 Each subdirectory has a kbuild Makefile which carries out the commands
@@ -278,7 +278,7 @@ more details, with real examples.
        actually recognize that there is a lib.a being built, the directory
        shall be listed in libs-y.
 
-       See also "6.4 List directories to visit when descending".
+       See also "7.4 List directories to visit when descending".
 
        Use of lib-y is normally restricted to `lib/` and `arch/*/lib`.
 
@@ -422,21 +422,21 @@ more details, with real examples.
        Thus, if you change an option to $(CC) all affected files will
        be re-compiled.
 
-3.10 Special Rules
+3.10 Custom Rules
 ------------------
 
-       Special rules are used when the kbuild infrastructure does
+       Custom rules are used when the kbuild infrastructure does
        not provide the required support. A typical example is
        header files generated during the build process.
        Another example are the architecture-specific Makefiles which
-       need special rules to prepare boot images etc.
+       need custom rules to prepare boot images etc.
 
-       Special rules are written as normal Make rules.
+       Custom rules are written as normal Make rules.
        Kbuild is not executing in the directory where the Makefile is
-       located, so all special rules shall provide a relative
+       located, so all custom rules shall use a relative
        path to prerequisite files and target files.
 
-       Two variables are used when defining special rules:
+       Two variables are used when defining custom rules:
 
        $(src)
            $(src) is a relative path which points to the directory
@@ -454,7 +454,7 @@ more details, with real examples.
                $(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl
                        $(CPP) -DCHIP=810 - < $< | ... $(src)/script_asm.pl
 
-           This is a special rule, following the normal syntax
+           This is a custom rule, following the normal syntax
            required by make.
 
            The target file depends on two prerequisite files. References
@@ -471,11 +471,33 @@ more details, with real examples.
 
        Example::
 
-               #arch/blackfin/boot/Makefile
-               $(obj)/vmImage: $(obj)/vmlinux.gz
-                       $(call if_changed,uimage)
-                       @$(kecho) 'Kernel: $@ is ready'
+               # arch/arm/Makefile
+               $(BOOT_TARGETS): vmlinux
+                       $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@
+                       @$(kecho) '  Kernel: $(boot)/$@ is ready'
 
+       When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
+       of a command is normally displayed.
+       To enable this behaviour for custom commands kbuild requires
+       two variables to be set::
+
+               quiet_cmd_<command>     - what shall be echoed
+                     cmd_<command>     - the command to execute
+
+       Example::
+
+               # lib/Makefile
+               quiet_cmd_crc32 = GEN     $@
+                     cmd_crc32 = $< > $@
+
+               $(obj)/crc32table.h: $(obj)/gen_crc32table
+                       $(call cmd,crc32)
+
+       When updating the $(obj)/crc32table.h target, the line:
+
+                 GEN     lib/crc32table.h
+
+       will be displayed with "make KBUILD_VERBOSE=0".
 
 3.11 $(CC) support functions
 ----------------------------
@@ -744,7 +766,7 @@ Both possibilities are described in the following.
        as a prerequisite.
        This is possible in two ways:
 
-       (1) List the prerequisite explicitly in a special rule.
+       (1) List the prerequisite explicitly in a custom rule.
 
        Example::
 
@@ -755,11 +777,11 @@ Both possibilities are described in the following.
 
        The target $(obj)/devlist.h will not be built before
        $(obj)/gen-devlist is updated. Note that references to
-       the host programs in special rules must be prefixed with $(obj).
+       the host programs in custom rules must be prefixed with $(obj).
 
        (2) Use always-y
 
-       When there is no suitable special rule, and the host program
+       When there is no suitable custom rule, and the host program
        shall be built when a makefile is entered, the always-y
        variable shall be used.
 
@@ -933,7 +955,7 @@ When "make clean" is executed, make will descend down in arch/x86/boot,
 and clean as usual. The Makefile located in arch/x86/boot/ may use
 the subdir- trick to descend further down.
 
-Note 1: arch/$(ARCH)/Makefile cannot use "subdir-", because that file is
+Note 1: arch/$(SRCARCH)/Makefile cannot use "subdir-", because that file is
 included in the top level makefile, and the kbuild infrastructure
 is not operational at that point.
 
@@ -946,9 +968,9 @@ be visited during "make clean".
 The top level Makefile sets up the environment and does the preparation,
 before starting to descend down in the individual directories.
 The top level makefile contains the generic part, whereas
-arch/$(ARCH)/Makefile contains what is required to set up kbuild
+arch/$(SRCARCH)/Makefile contains what is required to set up kbuild
 for said architecture.
-To do so, arch/$(ARCH)/Makefile sets up a number of variables and defines
+To do so, arch/$(SRCARCH)/Makefile sets up a number of variables and defines
 a few targets.
 
 When kbuild executes, the following steps are followed (roughly):
@@ -956,14 +978,14 @@ When kbuild executes, the following steps are followed (roughly):
 1) Configuration of the kernel => produce .config
 2) Store kernel version in include/linux/version.h
 3) Updating all other prerequisites to the target prepare:
-   - Additional prerequisites are specified in arch/$(ARCH)/Makefile
+   - Additional prerequisites are specified in arch/$(SRCARCH)/Makefile
 4) Recursively descend down in all directories listed in
    init-* core* drivers-* net-* libs-* and build all targets.
-   - The values of the above variables are expanded in arch/$(ARCH)/Makefile.
+   - The values of the above variables are expanded in arch/$(SRCARCH)/Makefile.
 5) All object files are then linked and the resulting file vmlinux is
    located at the root of the obj tree.
    The very first objects linked are listed in head-y, assigned by
-   arch/$(ARCH)/Makefile.
+   arch/$(SRCARCH)/Makefile.
 6) Finally, the architecture-specific part does any required post processing
    and builds the final bootimage.
    - This includes building boot records
@@ -1154,7 +1176,7 @@ When kbuild executes, the following steps are followed (roughly):
        machinery is all architecture-independent.
 
 
-       head-y, init-y, core-y, libs-y, drivers-y, net-y
+       head-y, core-y, libs-y, drivers-y
            $(head-y) lists objects to be linked first in vmlinux.
 
            $(libs-y) lists directories where a lib.a archive can be located.
@@ -1162,23 +1184,24 @@ When kbuild executes, the following steps are followed (roughly):
            The rest list directories where a built-in.a object file can be
            located.
 
-           $(init-y) objects will be located after $(head-y).
-
            Then the rest follows in this order:
 
-               $(core-y), $(libs-y), $(drivers-y) and $(net-y).
+               $(core-y), $(libs-y), $(drivers-y)
 
            The top level Makefile defines values for all generic directories,
-           and arch/$(ARCH)/Makefile only adds architecture-specific
+           and arch/$(SRCARCH)/Makefile only adds architecture-specific
            directories.
 
            Example::
 
-               #arch/sparc64/Makefile
-               core-y += arch/sparc64/kernel/
-               libs-y += arch/sparc64/prom/ arch/sparc64/lib/
-               drivers-$(CONFIG_OPROFILE)  += arch/sparc64/oprofile/
+               # arch/sparc/Makefile
+               core-y                 += arch/sparc/
+
+               libs-y                 += arch/sparc/prom/
+               libs-y                 += arch/sparc/lib/
 
+               drivers-$(CONFIG_PM) += arch/sparc/power/
+               drivers-$(CONFIG_OPROFILE)      += arch/sparc/oprofile/
 
 7.5 Architecture-specific boot images
 -------------------------------------
@@ -1189,15 +1212,15 @@ When kbuild executes, the following steps are followed (roughly):
        The actual goals are not standardized across architectures.
 
        It is common to locate any additional processing in a boot/
-       directory below arch/$(ARCH)/.
+       directory below arch/$(SRCARCH)/.
 
        Kbuild does not provide any smart way to support building a
-       target specified in boot/. Therefore arch/$(ARCH)/Makefile shall
+       target specified in boot/. Therefore arch/$(SRCARCH)/Makefile shall
        call make manually to build a target in boot/.
 
        The recommended approach is to include shortcuts in
-       arch/$(ARCH)/Makefile, and use the full path when calling down
-       into the arch/$(ARCH)/boot/Makefile.
+       arch/$(SRCARCH)/Makefile, and use the full path when calling down
+       into the arch/$(SRCARCH)/boot/Makefile.
 
        Example::
 
@@ -1217,7 +1240,7 @@ When kbuild executes, the following steps are followed (roughly):
 
                #arch/x86/Makefile
                define archhelp
-                 echo  '* bzImage      - Image (arch/$(ARCH)/boot/bzImage)'
+                 echo  '* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)'
                endif
 
        When make is executed without arguments, the first goal encountered
@@ -1280,8 +1303,8 @@ When kbuild executes, the following steps are followed (roughly):
        otherwise the command line check will fail, and the target will
        always be built.
        Assignments to $(targets) are without $(obj)/ prefix.
-       if_changed may be used in conjunction with custom commands as
-       defined in 7.8 "Custom kbuild commands".
+       if_changed may be used in conjunction with custom rules as
+       defined in "3.10 Custom Rules".
 
        Note: It is a typical mistake to forget the FORCE prerequisite.
        Another common pitfall is that whitespace is sometimes
@@ -1332,7 +1355,7 @@ When kbuild executes, the following steps are followed (roughly):
 
     objcopy
        Copy binary. Uses OBJCOPYFLAGS usually specified in
-       arch/$(ARCH)/Makefile.
+       arch/$(SRCARCH)/Makefile.
        OBJCOPYFLAGS_$@ may be used to set additional options.
 
     gzip
@@ -1361,41 +1384,11 @@ When kbuild executes, the following steps are followed (roughly):
                targets += $(dtb-y)
                DTC_FLAGS ?= -p 1024
 
-7.8 Custom kbuild commands
---------------------------
-
-       When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
-       of a command is normally displayed.
-       To enable this behaviour for custom commands kbuild requires
-       two variables to be set::
-
-               quiet_cmd_<command>     - what shall be echoed
-                     cmd_<command>     - the command to execute
-
-       Example::
-
-               #
-               quiet_cmd_image = BUILD   $@
-                     cmd_image = $(obj)/tools/build $(BUILDFLAGS) \
-                                                    $(obj)/vmlinux.bin > $@
-
-               targets += bzImage
-               $(obj)/bzImage: $(obj)/vmlinux.bin $(obj)/tools/build FORCE
-                       $(call if_changed,image)
-                       @echo 'Kernel: $@ is ready'
-
-       When updating the $(obj)/bzImage target, the line:
-
-               BUILD    arch/x86/boot/bzImage
-
-       will be displayed with "make KBUILD_VERBOSE=0".
-
-
 7.9 Preprocessing linker scripts
 --------------------------------
 
        When the vmlinux image is built, the linker script
-       arch/$(ARCH)/kernel/vmlinux.lds is used.
+       arch/$(SRCARCH)/kernel/vmlinux.lds is used.
        The script is a preprocessed variant of the file vmlinux.lds.S
        located in the same directory.
        kbuild knows .lds files and includes a rule `*lds.S` -> `*lds`.
@@ -1405,9 +1398,6 @@ When kbuild executes, the following steps are followed (roughly):
                #arch/x86/kernel/Makefile
                extra-y := vmlinux.lds
 
-               #Makefile
-               export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
-
        The assignment to extra-y is used to tell kbuild to build the
        target vmlinux.lds.
        The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the
@@ -1481,7 +1471,7 @@ See subsequent chapter for the syntax of the Kbuild file.
 
        If an architecture uses a verbatim copy of a header from
        include/asm-generic then this is listed in the file
-       arch/$(ARCH)/include/asm/Kbuild like this:
+       arch/$(SRCARCH)/include/asm/Kbuild like this:
 
                Example::
 
@@ -1492,7 +1482,7 @@ See subsequent chapter for the syntax of the Kbuild file.
        During the prepare phase of the build a wrapper include
        file is generated in the directory::
 
-               arch/$(ARCH)/include/generated/asm
+               arch/$(SRCARCH)/include/generated/asm
 
        When a header is exported where the architecture uses
        the generic header a similar wrapper is generated as part
@@ -1527,8 +1517,8 @@ See subsequent chapter for the syntax of the Kbuild file.
        to define the minimum set of ASM headers that all architectures must have.
 
        This works like optional generic-y. If a mandatory header is missing
-       in arch/$(ARCH)/include/(uapi/)/asm, Kbuild will automatically generate
-       a wrapper of the asm-generic one.
+       in arch/$(SRCARCH)/include/(uapi/)/asm, Kbuild will automatically
+       generate a wrapper of the asm-generic one.
 
 9 Kbuild Variables
 ==================
@@ -1564,6 +1554,16 @@ The top Makefile exports the following variables:
 
            make ARCH=m68k ...
 
+    SRCARCH
+       This variable specifies the directory in arch/ to build.
+
+       ARCH and SRCARCH may not necessarily match. A couple of arch
+       directories are biarch, that is, a single `arch/*/` directory supports
+       both 32-bit and 64-bit.
+
+       For example, you can pass in ARCH=i386, ARCH=x86_64, or ARCH=x86.
+       For all of them, SRCARCH=x86 because arch/x86/ supports both i386 and
+       x86_64.
 
     INSTALL_PATH
        This variable defines a place for the arch Makefiles to install