Linux Kernel Architecture

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

Appendix B: Working with the Source Code


The Main Makefile


The main Makefile is key to kernel compilation. It defines the call paths for the C compiler, linker, and so
on. The following distinction must be made between two toolchain alternatives:

❑ A toolchain to generatelocalprograms that execute on the host that compiles the kernel.
Examples of such programs are themenuconfigbinaries or tools for analyzing module symbols.
❑ A toolchain to generate the kernel itself.

The toolchains are usually identical. Differences arise only when a kernel is cross-compiled; in other
words, when a specific architecture is used to compile a kernel for a different architecture. This method
is applied if the target computer is either an embedded system with few resources (e.g., an ARM or MIPS
handheld device) or a very old and slow computer (aclassic Sparc or m68 Mac). In this case, a cross-
compiler (and appropriate cross-binutils) must be available for the toolchain responsible for creating the
kernel so that the desired code can be generated.

The local tools are defined as follows:

wolfgang@meitner>cat Makefile
...
HOSTCC = gcc
HOSTCXX = g++
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2
...

The kernel tools are defined as follows:

wolfgang@meitner>cat Makefile
...
CROSS_COMPILE=

AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
AWK = awk
GENKSYMS = scripts/genksyms/genksyms
DEPMOD = /sbin/depmod
KALLSYMS = scripts/kallsyms
PERL = perl
CHECK = sparse

CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
MODFLAGS = -DMODULE
Free download pdf