mqueue: apply mathematics distributivity on mq_bytes calculation
[safe/jmp/linux-2.6] / Documentation / kbuild / makefiles.txt
index b7d6abb..71c602d 100644 (file)
@@ -18,6 +18,7 @@ This document describes the Linux kernel Makefiles.
           --- 3.9 Dependency tracking
           --- 3.10 Special Rules
           --- 3.11 $(CC) support functions
+          --- 3.12 $(LD) support functions
 
        === 4 Host Program support
           --- 4.1 Simple Host Program
@@ -34,16 +35,22 @@ This document describes the Linux kernel Makefiles.
           --- 6.1 Set variables to tweak the build to the architecture
           --- 6.2 Add prerequisites to archprepare:
           --- 6.3 List directories to visit when descending
-          --- 6.4 Architecture specific boot images
+          --- 6.4 Architecture-specific boot images
           --- 6.5 Building non-kbuild targets
           --- 6.6 Commands useful for building a boot image
           --- 6.7 Custom kbuild commands
           --- 6.8 Preprocessing linker scripts
 
-       === 7 Kbuild Variables
-       === 8 Makefile language
-       === 9 Credits
-       === 10 TODO
+       === 7 Kbuild syntax for exported headers
+               --- 7.1 header-y
+               --- 7.2 objhdr-y
+               --- 7.3 destination-y
+               --- 7.4 unifdef-y (deprecated)
+
+       === 8 Kbuild Variables
+       === 9 Makefile language
+       === 10 Credits
+       === 11 TODO
 
 === 1 Overview
 
@@ -124,7 +131,7 @@ more details, with real examples.
        Example:
                obj-y += foo.o
 
-       This tell kbuild that there is one object in that directory, named
+       This tells kbuild that there is one object in that directory, named
        foo.o. foo.o will be built from foo.c or foo.S.
 
        If foo.o shall be built as a module, the variable obj-m is used.
@@ -227,9 +234,9 @@ more details, with real examples.
        be included in a library, lib.a.
        All objects listed with lib-y are combined in a single
        library for that directory.
-       Objects that are listed in obj-y and additionaly listed in
-       lib-y will not be included in the library, since they will anyway
-       be accessible.
+       Objects that are listed in obj-y and additionally listed in
+       lib-y will not be included in the library, since they will
+       be accessible anyway.
        For consistency, objects listed in lib-m will be included in lib.a.
 
        Note that the same kbuild makefile may list files to be built-in
@@ -276,41 +283,49 @@ more details, with real examples.
 
 --- 3.7 Compilation flags
 
-    EXTRA_CFLAGS, EXTRA_AFLAGS, EXTRA_LDFLAGS, EXTRA_ARFLAGS
-
-       All the EXTRA_ variables apply only to the kbuild makefile
-       where they are assigned. The EXTRA_ variables apply to all
-       commands executed in the kbuild makefile.
+    ccflags-y, asflags-y and ldflags-y
+       The three flags listed above applies only to the kbuild makefile
+       where they are assigned. They are used for all the normal
+       cc, as and ld invocation happenign during a recursive build.
+       Note: Flags with the same behaviour were previously named:
+       EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS.
+       They are yet supported but their use are deprecated.
 
-       $(EXTRA_CFLAGS) specifies options for compiling C files with
-       $(CC).
+       ccflags-y specifies options for compiling C files with $(CC).
 
        Example:
                # drivers/sound/emu10k1/Makefile
-               EXTRA_CFLAGS += -I$(obj)
-               ifdef DEBUG
-                   EXTRA_CFLAGS += -DEMU10K1_DEBUG
-               endif
+               ccflags-y += -I$(obj)
+               ccflags-$(DEBUG) += -DEMU10K1_DEBUG
 
 
        This variable is necessary because the top Makefile owns the
-       variable $(CFLAGS) and uses it for compilation flags for the
+       variable $(KBUILD_CFLAGS) and uses it for compilation flags for the
        entire tree.
 
-       $(EXTRA_AFLAGS) is a similar string for per-directory options
+       asflags-y is a similar string for per-directory options
        when compiling assembly language source.
 
        Example:
                #arch/x86_64/kernel/Makefile
-               EXTRA_AFLAGS := -traditional
+               asflags-y := -traditional
 
 
-       $(EXTRA_LDFLAGS) and $(EXTRA_ARFLAGS) are similar strings for
-       per-directory options to $(LD) and $(AR).
+       ldflags-y is a string for per-directory options to $(LD).
 
        Example:
                #arch/m68k/fpsp040/Makefile
-               EXTRA_LDFLAGS := -x
+               ldflags-y := -x
+
+    subdir-ccflags-y, subdir-asflags-y
+       The two flags listed above are similar to ccflags-y and as-falgs-y.
+       The difference is that the subdir- variants has effect for the kbuild
+       file where tey are present and all subdirectories.
+       Options specified using subdir-* are added to the commandline before
+       the options specified using the non-subdir variants.
+
+       Example:
+               subdir-ccflags-y := -Werror
 
     CFLAGS_$@, AFLAGS_$@
 
@@ -353,7 +368,7 @@ more details, with real examples.
        Special 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
+       Another example are the architecture-specific Makefiles which
        need special rules to prepare boot images etc.
 
        Special rules are written as normal Make rules.
@@ -385,12 +400,26 @@ more details, with real examples.
        to prerequisites are referenced with $(src) (because they are not
        generated files).
 
+    $(kecho)
+       echoing information to user in a rule is often a good practice
+       but when execution "make -s" one does not expect to see any output
+       except for warnings/errors.
+       To support this kbuild define $(kecho) which will echo out the
+       text following $(kecho) to stdout except if "make -s" is used.
+
+       Example:
+               #arch/blackfin/boot/Makefile
+               $(obj)/vmImage: $(obj)/vmlinux.gz
+                       $(call if_changed,uimage)
+                       @$(kecho) 'Kernel: $@ is ready'
+
+
 --- 3.11 $(CC) support functions
 
        The kernel may be built with several different versions of
        $(CC), each supporting a unique set of features and options.
        kbuild provide basic support to check for valid options for $(CC).
-       $(CC) is useally the gcc compiler, but other alternatives are
+       $(CC) is usually the gcc compiler, but other alternatives are
        available.
 
     as-option
@@ -407,20 +436,26 @@ more details, with real examples.
        The second argument is optional, and if supplied will be used
        if first argument is not supported.
 
-    ld-option
-       ld-option is used to check if $(CC) when used to link object files
+    cc-ldoption
+       cc-ldoption is used to check if $(CC) when used to link object files
        supports the given option.  An optional second option may be
        specified if first option are not supported.
 
        Example:
                #arch/i386/kernel/Makefile
-               vsyscall-flags += $(call ld-option, -Wl$(comma)--hash-style=sysv)
+               vsyscall-flags += $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
 
-       In the above example vsyscall-flags will be assigned the option
+       In the above example, vsyscall-flags will be assigned the option
        -Wl$(comma)--hash-style=sysv if it is supported by $(CC).
        The second argument is optional, and if supplied will be used
        if first argument is not supported.
 
+    as-instr
+       as-instr checks if the assembler reports a specific instruction
+       and then outputs either option1 or option2
+       C escapes are supported in the test instruction
+       Note: as-instr-option uses KBUILD_AFLAGS for $(AS) options
+
     cc-option
        cc-option is used to check if $(CC) supports a given option, and not
        supported to use an optional second option.
@@ -429,10 +464,11 @@ more details, with real examples.
                #arch/i386/Makefile
                cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
 
-       In the above example cflags-y will be assigned the option
+       In the above example, cflags-y will be assigned the option
        -march=pentium-mmx if supported by $(CC), otherwise -march=i586.
        The second argument to cc-option is optional, and if omitted,
        cflags-y will be assigned no value if first option is not supported.
+       Note: cc-option uses KBUILD_CFLAGS for $(CC) options
 
    cc-option-yn
        cc-option-yn is used to check if gcc supports a given option
@@ -448,6 +484,7 @@ more details, with real examples.
        option. When $(biarch) equals 'y', the expanded variables $(aflags-y)
        and $(cflags-y) will be assigned the values -a32 and -m32,
        respectively.
+       Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options
 
     cc-option-align
        gcc versions >= 3.0 changed the type of options used to specify
@@ -459,10 +496,11 @@ more details, with real examples.
                cc-option-align = -falign
 
        Example:
-               CFLAGS += $(cc-option-align)-functions=4
+               KBUILD_CFLAGS += $(cc-option-align)-functions=4
 
        In the above example, the option -falign-functions=4 is used for
        gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used.
+       Note: cc-option-align uses KBUILD_CFLAGS for $(CC) options
 
     cc-version
        cc-version returns a numerical version of the $(CC) compiler version.
@@ -487,15 +525,64 @@ more details, with real examples.
 
        Example:
                #fs/reiserfs/Makefile
-               EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1)
+               ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
 
-       In this example, EXTRA_CFLAGS will be assigned the value -O1 if the
+       In this example, ccflags-y will be assigned the value -O1 if the
        $(CC) version is less than 4.2.
        cc-ifversion takes all the shell operators:
        -eq, -ne, -lt, -le, -gt, and -ge
        The third parameter may be a text as in this example, but it may also
        be an expanded variable or a macro.
 
+    cc-fullversion
+       cc-fullversion is useful when the exact version of gcc is needed.
+       One typical use-case is when a specific GCC version is broken.
+       cc-fullversion points out a more specific version than cc-version does.
+
+       Example:
+               #arch/powerpc/Makefile
+               $(Q)if test "$(call cc-fullversion)" = "040200" ; then \
+                       echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \
+                       false ; \
+               fi
+
+       In this example for a specific GCC version the build will error out explaining
+       to the user why it stops.
+
+    cc-cross-prefix
+       cc-cross-prefix is used to check if there exists a $(CC) in path with
+       one of the listed prefixes. The first prefix where there exist a
+       prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found
+       then nothing is returned.
+       Additional prefixes are separated by a single space in the
+       call of cc-cross-prefix.
+       This functionality is useful for architecture Makefiles that try
+       to set CROSS_COMPILE to well-known values but may have several
+       values to select between.
+       It is recommended only to try to set CROSS_COMPILE if it is a cross
+       build (host arch is different from target arch). And if CROSS_COMPILE
+       is already set then leave it with the old value.
+
+       Example:
+               #arch/m68k/Makefile
+               ifneq ($(SUBARCH),$(ARCH))
+                       ifeq ($(CROSS_COMPILE),)
+                              CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-)
+                       endif
+               endif
+
+--- 3.12 $(LD) support functions
+
+    ld-option
+       ld-option is used to check if $(LD) supports the supplied option.
+       ld-option takes two options as arguments.
+       The second argument is an optional option that can be used if the
+       first option is not supported by $(LD).
+
+       Example:
+               #Makefile
+               LDFLAGS_vmlinux += $(call really-ld-option, -X)
+
 
 === 4 Host Program support
 
@@ -530,7 +617,7 @@ Both possibilities are described in the following.
        Host programs can be made up based on composite objects.
        The syntax used to define composite objects for host programs is
        similar to the syntax used for kernel objects.
-       $(<executeable>-objs) lists all objects used to link the final
+       $(<executable>-objs) lists all objects used to link the final
        executable.
 
        Example:
@@ -745,10 +832,10 @@ When kbuild executes, the following steps are followed (roughly):
    located at the root of the obj tree.
    The very first objects linked are listed in head-y, assigned by
    arch/$(ARCH)/Makefile.
-7) Finally, the architecture specific part does any required post processing
+7) Finally, the architecture-specific part does any required post processing
    and builds the final bootimage.
    - This includes building boot records
-   - Preparing initrd images and thelike
+   - Preparing initrd images and the like
 
 
 --- 6.1 Set variables to tweak the build to the architecture
@@ -761,8 +848,8 @@ When kbuild executes, the following steps are followed (roughly):
        Example:
                #arch/s390/Makefile
                LDFLAGS         := -m elf_s390
-       Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise
-       the flags used. See chapter 7.
+       Note: ldflags-y can be used to further customise
+       the flags used. See chapter 3.7.
 
     LDFLAGS_MODULE     Options for $(LD) when linking modules
 
@@ -798,26 +885,26 @@ When kbuild executes, the following steps are followed (roughly):
        In this example, the binary $(obj)/image is a binary version of
        vmlinux. The usage of $(call if_changed,xxx) will be described later.
 
-    AFLAGS             $(AS) assembler flags
+    KBUILD_AFLAGS              $(AS) assembler flags
 
        Default value - see top level Makefile
        Append or modify as required per architecture.
 
        Example:
                #arch/sparc64/Makefile
-               AFLAGS += -m64 -mcpu=ultrasparc
+               KBUILD_AFLAGS += -m64 -mcpu=ultrasparc
 
-    CFLAGS             $(CC) compiler flags
+    KBUILD_CFLAGS              $(CC) compiler flags
 
        Default value - see top level Makefile
        Append or modify as required per architecture.
 
-       Often, the CFLAGS variable depends on the configuration.
+       Often, the KBUILD_CFLAGS variable depends on the configuration.
 
        Example:
                #arch/i386/Makefile
                cflags-$(CONFIG_M386) += -march=i386
-               CFLAGS += $(cflags-y)
+               KBUILD_CFLAGS += $(cflags-y)
 
        Many arch Makefiles dynamically run the target C compiler to
        probe supported options:
@@ -829,7 +916,7 @@ When kbuild executes, the following steps are followed (roughly):
                                                -march=pentium2,-march=i686)
                ...
                # Disable unit-at-a-time mode ...
-               CFLAGS += $(call cc-option,-fno-unit-at-a-time)
+               KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time)
                ...
 
 
@@ -875,7 +962,7 @@ When kbuild executes, the following steps are followed (roughly):
 
        $(head-y) lists objects to be linked first in vmlinux.
        $(libs-y) lists directories where a lib.a archive can be located.
-       The rest lists directories where a built-in.o object file can be
+       The rest list directories where a built-in.o object file can be
        located.
 
        $(init-y) objects will be located after $(head-y).
@@ -883,7 +970,7 @@ When kbuild executes, the following steps are followed (roughly):
        $(core-y), $(libs-y), $(drivers-y) and $(net-y).
 
        The top level Makefile defines values for all generic directories,
-       and arch/$(ARCH)/Makefile only adds architecture specific directories.
+       and arch/$(ARCH)/Makefile only adds architecture-specific directories.
 
        Example:
                #arch/sparc64/Makefile
@@ -892,7 +979,7 @@ When kbuild executes, the following steps are followed (roughly):
                drivers-$(CONFIG_OPROFILE)  += arch/sparc64/oprofile/
 
 
---- 6.4 Architecture specific boot images
+--- 6.4 Architecture-specific boot images
 
        An arch Makefile specifies goals that take the vmlinux file, compress
        it, wrap it in bootstrapping code, and copy the resulting files
@@ -919,7 +1006,7 @@ When kbuild executes, the following steps are followed (roughly):
        "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke
        make in a subdirectory.
 
-       There are no rules for naming architecture specific targets,
+       There are no rules for naming architecture-specific targets,
        but executing "make help" will list all relevant targets.
        To support this, $(archhelp) must be defined.
 
@@ -977,7 +1064,7 @@ When kbuild executes, the following steps are followed (roughly):
                        $(call if_changed,ld/objcopy/gzip)
 
        When the rule is evaluated, it is checked to see if any files
-       needs an update, or the command line has changed since the last
+       need an update, or the command line has changed since the last
        invocation. The latter will force a rebuild if any options
        to the executable have changed.
        Any target that utilises if_changed must be listed in $(targets),
@@ -1017,7 +1104,7 @@ When kbuild executes, the following steps are followed (roughly):
        In this example, there are two possible targets, requiring different
        options to the linker. The linker options are specified using the
        LDFLAGS_$@ syntax - one for each potential target.
-       $(targets) are assinged all potential targets, by which kbuild knows
+       $(targets) are assigned all potential targets, by which kbuild knows
        the targets and will:
                1) check for commandline changes
                2) delete target during make clean
@@ -1077,17 +1164,78 @@ When kbuild executes, the following steps are followed (roughly):
        specified options when building the target vmlinux.lds.
 
        When building the *.lds target, kbuild uses the variables:
-       CPPFLAGS        : Set in top-level Makefile
-       EXTRA_CPPFLAGS  : May be set in the kbuild makefile
+       KBUILD_CPPFLAGS : Set in top-level Makefile
+       cppflags-y      : May be set in the kbuild makefile
        CPPFLAGS_$(@F)  : Target specific flags.
                          Note that the full filename is used in this
                          assignment.
 
        The kbuild infrastructure for *lds file are used in several
-       architecture specific files.
+       architecture-specific files.
+
+=== 7 Kbuild syntax for exported headers
+
+The kernel include a set of headers that is exported to userspace.
+Many headers can be exported as-is but other headers requires  a
+minimal pre-processing before they are ready for user-space.
+The pre-processing does:
+- drop kernel specific annotations
+- drop include of compiler.h
+- drop all sections that is kernel internat (guarded by ifdef __KERNEL__)
+
+Each relevant directory contain a file name "Kbuild" which specify the
+headers to be exported.
+See subsequent chapter for the syntax of the Kbuild file.
+
+       --- 7.1 header-y
+
+       header-y specify header files to be exported.
+
+               Example:
+                       #include/linux/Kbuild
+                       header-y += usb/
+                       header-y += aio_abi.h
+
+       The convention is to list one file per line and
+       preferably in alphabetic order.
+
+       header-y also specify which subdirectories to visit.
+       A subdirectory is identified by a trailing '/' which
+       can be seen in the example above for the usb subdirectory.
+
+       Subdirectories are visited before their parent directories.
+
+       --- 7.2 objhdr-y
+
+       objhdr-y specifies generated files to be exported.
+       Generated files are special as they need to be looked
+       up in another directory when doing 'make O=...' builds.
+
+               Example:
+                       #include/linux/Kbuild
+                       objhdr-y += version.h
+
+       --- 7.3 destination-y
+
+       When an architecture have a set of exported headers that needs to be
+       exported to a different directory destination-y is used.
+       destination-y specify the destination directory for all exported
+       headers in the file where it is present.
+
+               Example:
+                       #arch/xtensa/platforms/s6105/include/platform/Kbuild
+                       destination-y := include/linux
+
+       In the example above all exported headers in the Kbuild file
+       will be located in the directory "include/linux" when exported.
+
+
+       --- 7.4 unifdef-y (deprecated)
+
+       unifdef-y is deprecated. A direct replacement is header-y.
 
 
-=== 7 Kbuild Variables
+=== 8 Kbuild Variables
 
 The top Makefile exports the following variables:
 
@@ -1128,7 +1276,7 @@ The top Makefile exports the following variables:
 
        This variable defines a place for the arch Makefiles to install
        the resident kernel image and System.map file.
-       Use this for architecture specific install targets.
+       Use this for architecture-specific install targets.
 
     INSTALL_MOD_PATH, MODLIB
 
@@ -1149,7 +1297,7 @@ The top Makefile exports the following variables:
        INSTALL_MOD_STRIP will used as the option(s) to the strip command.
 
 
-=== 8 Makefile language
+=== 9 Makefile language
 
 The kernel Makefiles are designed to be run with GNU Make.  The Makefiles
 use only the documented features of GNU Make, but they do use many
@@ -1168,14 +1316,14 @@ time the left-hand side is used.
 There are some cases where "=" is appropriate.  Usually, though, ":="
 is the right choice.
 
-=== 9 Credits
+=== 10 Credits
 
 Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
 Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
 Updates by Sam Ravnborg <sam@ravnborg.org>
 Language QA by Jan Engelhardt <jengelh@gmx.de>
 
-=== 10 TODO
+=== 11 TODO
 
 - Describe how kbuild supports shipped files with _shipped.
 - Generating offset header files.