Linux Kernel Architecture

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

Appendix B: Working with the Source Code


If there is a choice of linking in kernel components or not (in other words, if configuration is controlled
by aboolquery), the Makefile must react accordingly to the user’s selection. The configuration symbol
in the Makefile can be used for this purpose, as the following example taken from the Makefile in the
kernel/directory illustrates:


obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
exit.o itimer.o time.o softirq.o resource.o \
sysctl.o capability.o ptrace.o timer.o user.o user_namespace.o \
signal.o sys.o kmod.o workqueue.o pid.o \
rcupdate.o extable.o params.o posix-timers.o \
kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \
utsname.o notifier.o

obj-$(CONFIG_SYSCTL) += sysctl_check.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o
obj-y += time/
...
obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
obj-$(CONFIG_SMP) += cpu.o spinlock.o
obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
...
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_KALLSYMS) += kallsyms.o
obj-$(CONFIG_PM) += power/
...
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
obj-$(CONFIG_MARKERS) += marker.o

The files that arealwayscompiled are at the top of the list. The files below them are not compiled by
Kbuild unless their configuration symbol is set toy. For example, if module support is configured, the
corresponding line expands to the following:


obj-y += module.o

Note the use of+=instead of a normal equal sign (=), which causes the object to be added to the target
obj-y.


If module support is not configured, the line expands as follows:


obj-n += module.o

All files of the targetobj-nare ignored by the Kbuild system and are therefore not compiled.


The following line for power management is particularly interesting:


obj-$(CONFIG_PM) += power/

Here the target is not a file but a directory. IfCONFIG_PMis set, Kbuild switches to thekernel/power/file
during compilation and processes the Makefile that it contains.

Free download pdf