2.5.59 kernel makefile documentation
[posted february 4, 2003 by corbet]
linux kernel makefiles
this document describes the linux kernel makefiles.
=== table of contents
=== 1 overview
=== 2 who does what
=== 3 the kbuild makefiles
--- 3.1 goal definitions
--- 3.2 built-in object goals - obj-y
--- 3.3 loadable module goals - obj-m
--- 3.4 objects which export symbols - export-objs
--- 3.5 library file goals - l_target
--- 3.6 descending down in directories
--- 3.7 compilation flags
--- 3.8 command line dependency
--- 3.9 dependency tracking
--- 3.10 special rules
=== 4 host program support
--- 4.1 simple host program
--- 4.2 composite host programs
--- 4.3 defining shared libraries
--- 4.4 using c for host programs
--- 4.5 controlling compiler options for host programs
--- 4.6 when host programs are actually built
=== 5 kbuild clean infrastructure
=== 6 architecture makefiles
--- 6.1 set variables to tweak the build to the architecture
--- 6.2 add prerequisites to prepare:
--- 6.3 list directories to visit when descending
--- 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
=== 7 kbuild variables
=== 8 makefile language
=== 9 credits
=== 10 todo
=== 1 overview
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.
the top makefile reads the .config file, which comes from the kernel
configuration process.
the top makefile is responsible for building two major products: vmlinux
(the resident kernel image) and modules (any module files).
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
architecture-specific information to the top makefile.
each subdirectory has a kbuild makefile which carries out the commands
passed down from above. the kbuild makefile uses information from the
.config file to construct various file lists used by kbuild to build
any built-in or modular targets.
scripts/makefile.* contains all the definitions/rules etc. that
are used to build the kernel based on the kbuild makefiles.
=== 2 who does what
people have four different relationships with the kernel makefiles.
*users* are people who build kernels. these people type commands such as
"make menuconfig" or "make". they usually do not read or edit
any kernel makefiles (or any other source files).
*normal developers* are people who work on features such as device
drivers, file systems, and network protocols. these people need to
maintain the kbuild makefiles for the subsystem that they are
working on. in order to do this effectively, they need some overall
knowledge about the kernel makefiles, plus detailed knowledge about the
public interface for kbuild.
*arch developers* are people who work on an entire architecture, such
as sparc or ia64. arch developers need to know about the arch makefile
as well as kbuild makefiles.
*kbuild developers* are people who work on the kernel build system itself.
these people need to know about all aspects of the kernel makefiles.
this document is aimed towards normal developers and arch developers.
=== 3 the kbuild makefiles
most makefiles within the kernel are kbuild makefiles that use the
kbuild infrastructure. this chapter introduce the syntax used in the
kbuild makefiles.
section 3.1 "goal definitions" is a quick intro, further chapters provide
more details, with real examples.
--- 3.1 goal definitions
goal definitions are the main part (heart) of the kbuild makefile.
these lines define the files to be built, any special compilation
options, and any subdirectories to be entered recursively.
the most simple kbuild makefile contains one line:
example:
obj-y = foo.o
this tell kbuild that there is one object in that directory named
foo.o. foo.o will be build from foo.c or foo.s.
if foo.o shall be built as a module, the variable obj-m is used.
therefore the following pattern is often used:
example:
obj-$(config_foo) = foo.o
$(config_foo) evaluates to either y (for built-in) or m (for module).
if config_foo is neither y nor m, then the file will not be compiled
nor linked.
--- 3.2 built-in object goals - obj-y
the kbuild makefile specifies object files for vmlinux
in the lists $(obj-y). these lists depend on the kernel
configuration.
kbuild compiles all the $(obj-y) files. it then calls
"$(ld) -r" to merge these files into one built-in.o file.
built-in.o is later linked into vmlinux by the parent makefile.
the order of files in $(obj-y) is significant. duplicates in
the lists are allowed: the first instance will be linked into
built-in.o and succeeding instances will be ignored.
link order is significant, because certain functions
(module_init() / __initcall) will be called during boot in the
order they appear. so keep in mind that changing the link
order may e.g. change the order in which your scsi
controllers are detected, and thus you disks are renumbered.
example:
#drivers/isdn/i4l/makefile
# makefile for the kernel isdn subsystem and device drivers.
# each configuration option enables a list of files.
obj-$(config_isdn) = isdn.o
obj-$(config_isdn_ppp_bsdcomp) = isdn_bsdcomp.o
--- 3.3 loadable module goals - obj-m
$(obj-m) specify object files which are built as loadable
kernel modules.
a module may be built from one source file or several source
files. in the case of one source file, the kbuild makefile
simply adds the file to $(obj-m).
example:
#drivers/isdn/i4l/makefile
obj-$(config_isdn_ppp_bsdcomp) = isdn_bsdcomp.o
note: in this example $(config_isdn_ppp_bsdcomp) evaluates to 'm'
if a kernel module is built from several source files, you specify
that you want to build a module in the same way as above.
kbuild needs to know which the parts that you want to build your
module from, so you have to tell it by setting an
$(-objs) variable.
example:
#drivers/isdn/i4l/makefile
obj-$(config_isdn) = isdn.o
isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o
in this example, the module name will be isdn.o. kbuild will
compile the objects listed in $(isdn-objs) and then run
"$(ld) -r" on the list of these files to generate isdn.o.
kbuild recognises objects used for composite objects by the suffix
-objs, and the suffix -y. this allows the makefiles to use
the value of a config_ symbol to determine if an object is part
of a composite object.
example:
#fs/ext2/makefile
obj-$(config_ext2_fs) = ext2.o
ext2-y := balloc.o bitmap.o
ext2-$(config_ext2_fs_xattr) = xattr.o
in this example xattr.o is only part of the composite object
ext2.o, if $(config_ext2_fs_xattr) evaluates to 'y'.
note: of course, when you are building objects into the kernel,
the syntax above will also work. so, if you have config_ext2_fs=y,
kbuild will build an ext2.o file for you out of the individual
parts and then link this into built-in.o, as you would expect.
--- 3.4 objects which export symbols - export-objs
when using loadable modules, not every global symbol in the
kernel / other modules is automatically available, only those
explicitly exported are available for your module.
to make a symbol available for use in modules, to "export" it,
use the export_symbol() directive in your source. in
addition, you need to list all object files which export symbols
(i.e. their source contains an export_symbol() directive) in the
makefile variable $(export-objs).
example:
#drivers/isdn/i4l/makefile
# objects that export symbols.
export-objs := isdn_common.o
since isdn_common.c contains
export_symbol(register_isdn);
which makes the function register_isdn available to
low-level isdn drivers.
there exist a export_symbol_gpl() variant with similar functionality,
but more restrictive with what may use that symbol. the requirement
to list the .o file in export-objs is the same.
--- 3.5 library file goals - l_target
instead of building a built-in.o file, you may also
build an archive which again contains objects listed in $(obj-y).
this is normally not necessary and only used in lib/ and
arch/$(arch)/lib directories.
only the name lib.a is allowed.
example:
#arch/i386/lib/makefile
l_target := lib.a
obj-y := checksum.o delay.o
this will create a library lib.a based on checksum.o and delay.o.
--- 3.6 descending down in directories
a makefile is only responsible for building objects in its own
directory. files in subdirectories should be taken care of by
makefiles in these subdirs. the build system will automatically
invoke make recursively in subdirectories, provided you let it know of
them.
to do so obj-y and obj-m are used.
ext2 lives in a separate directory, and the makefile present in fs/
tells kbuild to descend down using the following assignment.
example:
#fs/makefile
obj-$(config_ext2_fs) = ext2/
if config_ext2_fs is set to either 'y' (built-in) or 'm' (modular)
the corresponding obj- variable will be set, and kbuild will descend
down in the ext2 directory.
kbuild only uses this information to decide that it needs to visit
the directory, it is the makefile in the subdirectory that
specifies what is modules and what is built-in.
it is good practice to use a config_ variable when assigning directory
names. this allows kbuild to totally skip the directory if the
corresponding config_ option is neither 'y' nor 'm'.
--- 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.
$(extra_cflags) specifies options for compiling c files with
$(cc).
example:
# drivers/sound/emu10k1/makefile
extra_cflags = -i$(obj)
ifdef debug
extra_cflags = -demu10k1_debug
endif
this variable is necessary because the top makefile owns the
variable $(cflags) and uses it for compilation flags for the
entire tree.
$(extra_aflags) is a similar string for per-directory options
when compiling assembly language source.
example:
#arch/x86_64/kernel/makefile
extra_aflags := -traditional
$(extra_ldflags) and $(extra_arflags) are similar strings for
per-directory options to $(ld) and $(ar).
example:
#arch/m68k/fpsp040/makefile
extra_ldflags := -x
cflags_$@, aflags_$@
cflags_$@ and aflags_$@ only apply to commands in current
kbuild makefile.
$(cflags_$@) specifies per-file options for $(cc). the $@
part has a literal value which specifies the file that it is for.
example:
# drivers/scsi/makefile
cflags_aha152x.o = -daha152x_stat -dautoconf
cflags_gdth.o = # -ddebug_gdth=2 -d__serial__ -d__com2__ \
-dgdth_statistics
cflags_seagate.o = -darbitrate -dparity -dseagate_use_asm
these three lines specify compilation flags for aha152x.o,
gdth.o, and seagate.o
$(aflags_$@) is a similar feature for source files in assembly
languages.
example:
# arch/arm/kernel/makefile
aflags_head-armv.o := -dtextaddr=$(textaddr) -traditional
aflags_head-armo.o := -dtextaddr=$(textaddr) -traditional
--- 3.9 dependency tracking
kbuild track dependencies on the following:
1) all prerequisite files (both *.c and *.h)
2) config_ options used in all prerequisite files
3) command-line used to compile target
thus, if you change an option to $(cc) all affected files will
be re-compiled.
--- 3.10 special rules
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 is the architecture specific makefiles which
needs special rules to prepare boot images etc.
special 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
path to prerequisite files and target files.
two variables are used when defining special rules:
$(src)
$(src) is a relative path which points to the directory
where the makefile is located. always use $(src) when
referring to files located in the src tree.
$(obj)
$(obj) is a relative path which points to the directory
where the target is saved. always use $(obj) when
referring to generated files.
example:
#drivers/scsi/makefile
$(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
required by make.
the target file depends on two prerequisite files. references
to the target file are prefixed with $(obj), references
to prerequisites are referenced with $(src) (because they are not
generated files).
=== 4 host program support
kbuild supports building executables on the host for use during the
compilation stage.
two steps are required in order to use a host executable.
the first step is to tell kbuild that a host program exists. this is
done utilising the variable host-prog.
the second step is to add an explicit dependency to the executable.
this can be done in two ways. either add the dependency in a rule,
or utilise the variable build-targets.
both possibilities are described in the following.
--- 4.1 simple host program
in some cases there is a need to compile and run a program on the
computer where the build is running.
the following line tells kbuild that the program bin2hex shall be
built on the build host.
example:
host-progs := bin2hex
kbuild assumes in the above example that bin2hex is made from a single
c-source file named bin2hex.c located in the same directory as
the makefile.
--- 4.2 composite host programs
host programs can be made up based on composite objects.
the syntax used to define composite objetcs for host programs is
similar to the syntax used for kernel objects.
$(-objs) list all objects used to link the final
executable.
example:
#scripts/lxdialog/makefile
host-progs := lxdialog
lxdialog-objs := checklist.o lxdialog.o
objects with extension .o are compiled from the corresponding .c
files. in the above example checklist.c is compiled to checklist.o
and lxdialog.c is compiled to lxdialog.o.
finally the two .o files are linked to the executable, lxdialog.
note: the syntax -y is not permitted for host-programs.
--- 4.3 defining shared libraries
objects with extension .so are considered shared libraries, and
will be compiled as position independent objects.
kbuild provides support for shared libraries, but the usage
shall be restricted.
in the following example the libkconfig.so shared library is used
to link the executable conf.
example:
#scripts/kconfig/makefile
host-progs := conf
conf-objs := conf.o libkconfig.so
libkconfig-objs := expr.o type.o
shared libraries always require a corresponding -objs line, and
in the example above the shared library libkconfig is composed by
the two objects expr.o and type.o.
expr.o and type.o will be built as position independent code and
linked as a shared library libkconfig.so. c is not supported for
shared libraries.
--- 4.4 using c for host programs
kbuild offers support for host programs written in c . this was
introduced solely to support kconfig, and is not recommended
for general use.
example:
#scripts/kconfig/makefile
host-progs := qconf
qconf-cxxobjs := qconf.o
in the example above the executable is composed of the c file
qconf.cc - identified by $(qconf-cxxobjs).
if qconf is composed by a mixture of .c and .cc files, then an
additional line can be used to identify this.
example:
#scripts/kconfig/makefile
host-progs := qconf
qconf-cxxobjs := qconf.o
qconf-objs := check.o
--- 4.5 controlling compiler options for host programs
when compiling host programs, it is possible to set specific flags.
the programs will always be compiled utilising $(hostcc) passed
the options specified in $(hostcflags).
to set flags that will take effect for all host programs created
in that makefile use the variable host_extracflags.
example:
#scripts/lxdialog/makefile
host_extracflags = -i/usr/include/ncurses
to set specific flags for a single file the following construction
is used:
example:
#arch/ppc64/boot/makefile
hostcflags_piggyback.o := -dkernelbase=$(kernelbase)
it is also possible to specify additional options to the linker.
example:
#scripts/kconfig/makefile
hostloadlibes_qconf := -l$(qtdir)/lib
when linking qconf it will be passed the extra option "-l$(qtdir)/lib".
--- 4.6 when host programs are actually built
kbuild will only build host-programs when they are referenced
as a prerequisite.
this is possible in two ways:
(1) list the prerequisite explicitly in a special rule.
example:
#drivers/pci/makefile
host-progs := gen-devlist
$(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
( cd $(obj); ./gen-devlist ) < $<
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).
(2) use $(build-targets)
when there is no suitable special rule, and the host program
shall be built when a makefile is entered, the $(build-targets)
variable shall be used.
example:
#scripts/lxdialog/makefile
host-progs := lxdialog
build-targets := $(host-progs)
this will tell kbuild to build lxdialog even if not referenced in
any rule.
=== 5 kbuild clean infrastructure
"make clean" deletes most generated files in the src tree where the kernel
is compiled. this includes generated files such as host programs.
kbuild knows targets listed in $(host-progs) and $(extra_targets) and
they are all deleted during "make clean".
files matching the patterns "*.[oas]", "*.ko", plus some additional files
generated by kbuild are deleted all over the kernel src tree when
"make clean" is executed.
additional files can be specified by means of $(clean-files).
example:
#drivers/pci/makefile
clean-files := devlist.h classlist.h
when executing "make clean", the two files "devlist.h classlist.h" will
be deleted. kbuild knows that files specified by $(clean-files) are
located in the same directory as the makefile.
usually kbuild descends down in subdirectories due to "obj-* := dir/",
but in the architecture makefiles where the kbuild infrastructure
is not sufficent this sometimes needs to be explicit.
example:
#arch/i386/boot/makefile
subdir- := compressed/
the above assignment instructs kbuild to descend down in the
directory compressed/ when "make clean" is executed.
to support the clean infrastructure in the makefiles that builds the
final bootimage there is an optional target named archclean:
example:
#arch/i386/makefile
archclean:
$(q)$(make) $(clean)=arch/i386/boot
when "make clean" is executed, make will descend down in arch/i386/boot,
and clean as usual. the makefile located in arch/i386/boot/ may use
the subdir- trick to descend further down.
note 1: arch/$(arch)/makefile cannot use "subdir-", because that file is
included in the top level makefile, and the kbuild infrastructure
is not operational at that point.
note 2: all directories listed in core-y, libs-y, drivers-y and net-y will
be visited during "make clean".
=== 6 architecture makefiles
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 the
arch/$(arch)/makefile contains what is required to set-up kbuild
to the said architecture.
to do so arch/$(arch)/makefile sets a number of variables, and defines
a few targets.
when kbuild executes the following steps are followed (roughly):
1) configuration of the kernel => produced .config
2) store kernel version in include/linux/version.h
3) symlink include/asm to include/asm-$(arch)
4) updating all other prerequisites to the target prepare:
- additional prerequisites are specified in arch/$(arch)/makefile
5) recursively descend down in all directories listed in
init-* core* drivers-* net-* libs-* and build all targets.
- the value of the above variables are extended in arch/$(arch)/makefile.
6) all object files are then linked and the resulting file vmlinux is
located at the root of the src 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
and builds the final bootimage.
- this includes building boot records
- preparing initrd images and the like
--- 6.1 set variables to tweak the build to the architecture
ldflags generic $(ld) options
flags used for all invocations of the linker.
often specifying the emulation is sufficient.
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.
ldflags_module options for $(ld) when linking modules
ldflags_module is used to set specific flags for $(ld) when
linking the .ko files used for modules.
default is "-r", for relocatable output.
ldflags_vmlinux options for $(ld) when linking vmlinux
ldflags_vmlinux is used to specify additional flags to pass to
the linker when linking the final vmlinux.
ldflags_vmlinux uses the ldflags_$@ support.
example:
#arch/i386/makefile
ldflags_vmlinux := -e stext
ldflags_blob options for $(ld) when linking the initramfs blob
the image used for initramfs is made during the build process.
ldflags_blob is used to specify additional flags to be used when
creating the initramfs_data.o file.
example:
#arch/i386/makefile
ldflags_blob := --format binary --oformat elf32-i386
objcopyflags objcopy flags
when $(call if_changed,objcopy) is used to translate a .o file,
then the flags specified in objcopyflags will be used.
$(call if_changed,objcopy) is often used to generate raw binaries on
vmlinux.
example:
#arch/s390/makefile
objcopyflags := -o binary
#arch/s390/boot/makefile
$(obj)/image: vmlinux force
$(call if_changed,objcopy)
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
default value - see top level makefile
append or modify as required per architecture.
example:
#arch/sparc64/makefile
aflags = -m64 -mcpu=ultrasparc
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.
example:
#arch/i386/makefile
cflags-$(config_m386) = -march=i386
cflags = $(cflags-y)
many arch makefiles dynamically run the target c compiler to
probe supported options:
#arch/i386/makefile
check_gcc = $(shell if $(cc) $(1) -s -o /dev/null -xc \
/dev/null\ > /dev/null 2>&1; then echo "$(1)"; \
else echo "$(2)"; fi)
cflags-$(config_mcyrixiii) = $(call check_gcc,\
-march=c3,-march=i486)
cflags = $(cflags-y)
the above examples both utilise the trick that a config option expands
to 'y' when selected.
cflags_kernel $(cc) options specific for built-in
$(cflags_kernel) contains extra c compiler flags used to compile
resident kernel code.
cflags_module $(cc) options specific for modules
$(cflags_module) contains extra c compiler flags used to compile code
for loadable kernel modules.
--- 6.2 add prerequisites to prepare:
the prepare: rule is used to list prerequisites that needs to be
built before starting to descend down in the subdirectories.
this is usual header files containing assembler constants.
example:
#arch/s390/makefile
prepare: include/asm-$(arch)/offsets.h
in this example the file include/asm-$(arch)/offsets.h will
be built before descending down in the subdirectories.
see also chapter xxx-todo that describe how kbuild supports
generating offset header files.
--- 6.3 list directories to visit when descending
an arch makefile cooperates with the top makefile to define variables
which specify how to build the vmlinux file. note that there is no
corresponding arch-specific section for modules; the module-building
machinery is all architecture-independent.
head-y, init-y, core-y, libs-y, drivers-y, net-y
$(head-y) list objects to be linked first in vmlinux.
$(libs-y) list directories where a libs.a archive can be located.
the rest list directories where a built-in.o 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).
the top level makefile define values for all generic directories,
and arch/$(arch)/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/
--- 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
somewhere. this includes various kinds of installation commands.
the actual goals are not standardized across architectures.
it is common to locate any additional processing in a boot/
directory below arch/$(arch)/.
kbuild does not provide any smart way to support building a
target specified in boot/. therefore arch/$(arch)/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.
example:
#arch/i386/makefile
boot := arch/i386/boot
bzimage: vmlinux
$(q)$(make) $(build)=$(boot) $(boot)/$@
"$(q)$(make) $(build)=" is the recommended way to invoke
make in a subdirectory.
there are no rules for naming of the architecture specific targets,
but executing "make help" will list all relevant targets.
to support this $(archhelp) must be defined.
example:
#arch/i386/makefile
define archhelp
echo '* bzimage - image (arch/$(arch)/boot/bzimage)'
endef
when make is executed without arguments, the first goal encountered
will be built. in the top level makefile the first goal present
is all:.
an architecture shall always per default build a bootable image.
in "make help" the default goal is highlighted with a '*'.
add a new prerequisite to all: to select a default goal different
from vmlinux.
example:
#arch/i386/makefile
all: bzimage
when "make" is executed without arguments, bzimage will be built.
--- 6.5 building non-kbuild targets
extra_targets
extra_targets specify additional targets created in current
directory, in addition to any targets specified by obj-*.
listing all targets in extra_targets is required for three purposes:
1) avoid that the target is linked in as part of built-in.o
2) enable kbuild to check changes in command lines
- when $(call if_changed,xxx) is used
3) kbuild knows what file to delete during "make clean"
example:
#arch/i386/kernel/makefile
extra_targets := head.o init_task.o
in this example extra_targets is used to list object files that
shall be built, but shall not be linked as part of built-in.o.
example:
#arch/i386/boot/makefile
extra_targets := vmlinux.bin bootsect bootsect.o
in this example extra_targets is used to list all intermediate
targets, and all final targets.
the targets are added to extra_targets to enable 2) and 3) above.
--- 6.6 commands useful for building a boot image
kbuild provide a few macros that are useful when building a
boot image.
if_changed
if_changed is the infrastructure used for the following commands.
usage:
target: source(s) force
$(call if_changed,ld/objcopy/gzip)
when the rule is evaluated it is checked to see if any files
needs an update, or the commandline has changed since 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 extra_targets,
otherwise the command line check will fail, and the target will
always be built.
if_changed may be used in conjunction with custom commands as
defined in 6.7 "custom kbuild commands".
note: it is a typical mistake to forget the force prerequisite.
ld
link target. often ldflags_$@ is used to set specific options to ld.
objcopy
copy binary. uses objcopyflags usually specified in
arch/$(arch)/makefile.
gzip
compress target. use maximum compression to compress target.
--- 6.7 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_ - what shall be echoed
cmd_ - the command to execute
example:
#
quiet_cmd_image = build $@
cmd_image = $(obj)/tools/build $(buildflags) \
$(obj)/vmlinux.bin > $@
$(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/i386/boot/bzimage
will be displayed with "make kbuild_verbose=0".
=== 7 kbuild variables
the top makefile exports the following variables:
version, patchlevel, sublevel, extraversion
these variables define the current kernel version. a few arch
makefiles actually use these values directly; they should use
$(kernelrelease) instead.
$(version), $(patchlevel), and $(sublevel) define the basic
three-part version number, such as "2", "4", and "0". these three
values are always numeric.
$(extraversion) defines an even tinier sublevel for pre-patches
or additional patches. it is usually some non-numeric string
such as "-pre4", and is often blank.
kernelrelease
$(kernelrelease) is a single string such as "2.4.0-pre4", suitable
for constructing installation directory names or showing in
version strings. some arch makefiles use it for this purpose.
arch
this variable defines the target architecture, such as "i386",
"arm", or "sparc". some kbuild makefiles test $(arch) to
determine which files to compile.
by default, the top makefile sets $(arch) to be the same as the
host system architecture. for a cross build, a user may
override the value of $(arch) on the command line:
make arch=m68k ...
install_path
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.
install_mod_path, modlib
$(install_mod_path) specifies a prefix to $(modlib) for module
installation. this variable is not defined in the makefile but
may be passed in by the user if desired.
$(modlib) specifies the directory for module installation.
the top makefile defines $(modlib) to
$(install_mod_path)/lib/modules/$(kernelrelease). the user may
override this value on the command line if desired.
=== 8 makefile language
the kernel makefiles are designed to run with gnu make. the makefiles
use only the documented features of gnu make, but they do use many
gnu extensions.
gnu make supports elementary list-processing functions. the kernel
makefiles use a novel style of list building and manipulation with few
"if" statements.
gnu make has two assignment operators, ":=" and "=". ":=" performs
immediate evaluation of the right-hand side and stores an actual string
into the left-hand side. "=" is like a formula definition; it stores the
right-hand side in an unevaluated form and then evaluates this form each
time the left-hand side is used.
there are some cases where "=" is appropriate. usually, though, ":="
is the right choice.
=== 9 credits
original version made by michael elizabeth chastain,
updates by kai germaschewski
updates by sam ravnborg
=== 10 todo
- describe how kbuild support shipped files with _shipped.
- generating offset header files.
- add more variables to section 7?
from :
阅读(5545) | 评论(0) | 转发(0) |