Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp02.tex V2 - 09/04/2008 6:09pm Page 1158

Appendix B: Working with the Source Code


CFLAGS_MODULE = $(MODFLAGS)
AFLAGS_MODULE = $(MODFLAGS)
LDFLAGS_MODULE = -r
CFLAGS_KERNEL =
AFLAGS_KERNEL =
...

TheCROSS_COMPILEprefix that precedes a definition is normally left blank. It must be assigned an appro-
priate value (ia64-linux-, for example) if the kernel is to be compiled for a different architecture.^4 As a
result, two different toolsets are used for the host and the target.

All other Makefiles mayneveruse the names of the tools directly, but must always employ the variables
defined here.

The main Makefile declares theARCHvariable to indicate the architecture for which the kernel is compiled.
It contains a value that is automatically detected and that is compatible with the directory names inarch/.
For example,ARCHis set toi386for IA-32 because the architecture-specific files reside inarch/i386/.

If the kernel is to be cross-compiled,ARCHmust be modified accordingly. For example, the following
calls are required to configure and compile the kernel for ARM systems (assuming that the appropriate
toolchain is available):

make ARCH=arm menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-

In addition to these definitions, the Makefile includes the statements needed to descend recursively into
the individual subdirectories and to compile the files they contain with the help of the local Makefile.
This appendix doesn’t go into the implementation details of this mechanism because it involves a large
number ofmakesubtleties.

Driver and SubsystemMakefiles


The Makefiles in the driver and subsystem directories are used to compile the correct files — in accor-
dance with the configuration in.config— and to direct the compilation flow to the required subdirec-
tories. The Kbuild framework makes the creation of such Makefiles relatively easy. Only the following
line is needed to generate an object file for permanent compilation into the kernel (regardless of the
configuration):

obj-y = file.o

By reference to the filename, Kbuild automatically detects that the source file isfile.cand invokes the
C compiler with the appropriate options to generate the binary object file if it is not already present or if
the source file has been modified after generation of an old version of the object file. The generated file is
also automatically included when the kernel is linked by the linker.

This approach can also be adopted if there are several object files. The specified files must then be sepa-
rated by blanks.

(^4) This can be set explicitly in the Makefile, specified by means of a shell variable in the environment, or passed as a parameter for
make.

Free download pdf