xref: /openbmc/linux/Documentation/kbuild/makefiles.rst (revision eabc8bcb292fb9a5757b0c8ab7751f41b0a104f8)
1cd238effSMauro Carvalho Chehab======================
2cd238effSMauro Carvalho ChehabLinux Kernel Makefiles
3cd238effSMauro Carvalho Chehab======================
4cd238effSMauro Carvalho Chehab
5cd238effSMauro Carvalho ChehabThis document describes the Linux kernel Makefiles.
6cd238effSMauro Carvalho Chehab
7cd238effSMauro Carvalho Chehab.. Table of Contents
8cd238effSMauro Carvalho Chehab
9cd238effSMauro Carvalho Chehab	=== 1 Overview
10cd238effSMauro Carvalho Chehab	=== 2 Who does what
11cd238effSMauro Carvalho Chehab	=== 3 The kbuild files
12cd238effSMauro Carvalho Chehab	   --- 3.1 Goal definitions
13cd238effSMauro Carvalho Chehab	   --- 3.2 Built-in object goals - obj-y
14cd238effSMauro Carvalho Chehab	   --- 3.3 Loadable module goals - obj-m
15cd238effSMauro Carvalho Chehab	   --- 3.4 Objects which export symbols
16cd238effSMauro Carvalho Chehab	   --- 3.5 Library file goals - lib-y
17cd238effSMauro Carvalho Chehab	   --- 3.6 Descending down in directories
18cd238effSMauro Carvalho Chehab	   --- 3.7 Compilation flags
19cd238effSMauro Carvalho Chehab	   --- 3.8 Command line dependency
20cd238effSMauro Carvalho Chehab	   --- 3.9 Dependency tracking
21cd238effSMauro Carvalho Chehab	   --- 3.10 Special Rules
22cd238effSMauro Carvalho Chehab	   --- 3.11 $(CC) support functions
23cd238effSMauro Carvalho Chehab	   --- 3.12 $(LD) support functions
24cd238effSMauro Carvalho Chehab
25cd238effSMauro Carvalho Chehab	=== 4 Host Program support
26cd238effSMauro Carvalho Chehab	   --- 4.1 Simple Host Program
27cd238effSMauro Carvalho Chehab	   --- 4.2 Composite Host Programs
28cd238effSMauro Carvalho Chehab	   --- 4.3 Using C++ for host programs
29cd238effSMauro Carvalho Chehab	   --- 4.4 Controlling compiler options for host programs
30cd238effSMauro Carvalho Chehab	   --- 4.5 When host programs are actually built
31cd238effSMauro Carvalho Chehab
32cd238effSMauro Carvalho Chehab	=== 5 Kbuild clean infrastructure
33cd238effSMauro Carvalho Chehab
34cd238effSMauro Carvalho Chehab	=== 6 Architecture Makefiles
35cd238effSMauro Carvalho Chehab	   --- 6.1 Set variables to tweak the build to the architecture
36cd238effSMauro Carvalho Chehab	   --- 6.2 Add prerequisites to archheaders:
37cd238effSMauro Carvalho Chehab	   --- 6.3 Add prerequisites to archprepare:
38cd238effSMauro Carvalho Chehab	   --- 6.4 List directories to visit when descending
39cd238effSMauro Carvalho Chehab	   --- 6.5 Architecture-specific boot images
40cd238effSMauro Carvalho Chehab	   --- 6.6 Building non-kbuild targets
41cd238effSMauro Carvalho Chehab	   --- 6.7 Commands useful for building a boot image
42cd238effSMauro Carvalho Chehab	   --- 6.8 Custom kbuild commands
43cd238effSMauro Carvalho Chehab	   --- 6.9 Preprocessing linker scripts
44cd238effSMauro Carvalho Chehab	   --- 6.10 Generic header files
45cd238effSMauro Carvalho Chehab	   --- 6.11 Post-link pass
46cd238effSMauro Carvalho Chehab
47cd238effSMauro Carvalho Chehab	=== 7 Kbuild syntax for exported headers
48cd238effSMauro Carvalho Chehab		--- 7.1 no-export-headers
49cd238effSMauro Carvalho Chehab		--- 7.2 generic-y
50cd238effSMauro Carvalho Chehab		--- 7.3 generated-y
51cd238effSMauro Carvalho Chehab		--- 7.4 mandatory-y
52cd238effSMauro Carvalho Chehab
53cd238effSMauro Carvalho Chehab	=== 8 Kbuild Variables
54cd238effSMauro Carvalho Chehab	=== 9 Makefile language
55cd238effSMauro Carvalho Chehab	=== 10 Credits
56cd238effSMauro Carvalho Chehab	=== 11 TODO
57cd238effSMauro Carvalho Chehab
58cd238effSMauro Carvalho Chehab1 Overview
59cd238effSMauro Carvalho Chehab==========
60cd238effSMauro Carvalho Chehab
61cd238effSMauro Carvalho ChehabThe Makefiles have five parts::
62cd238effSMauro Carvalho Chehab
63cd238effSMauro Carvalho Chehab	Makefile		the top Makefile.
64cd238effSMauro Carvalho Chehab	.config			the kernel configuration file.
65cd238effSMauro Carvalho Chehab	arch/$(ARCH)/Makefile	the arch Makefile.
66cd238effSMauro Carvalho Chehab	scripts/Makefile.*	common rules etc. for all kbuild Makefiles.
67cd238effSMauro Carvalho Chehab	kbuild Makefiles	there are about 500 of these.
68cd238effSMauro Carvalho Chehab
69cd238effSMauro Carvalho ChehabThe top Makefile reads the .config file, which comes from the kernel
70cd238effSMauro Carvalho Chehabconfiguration process.
71cd238effSMauro Carvalho Chehab
72cd238effSMauro Carvalho ChehabThe top Makefile is responsible for building two major products: vmlinux
73cd238effSMauro Carvalho Chehab(the resident kernel image) and modules (any module files).
74cd238effSMauro Carvalho ChehabIt builds these goals by recursively descending into the subdirectories of
75cd238effSMauro Carvalho Chehabthe kernel source tree.
76cd238effSMauro Carvalho ChehabThe list of subdirectories which are visited depends upon the kernel
77cd238effSMauro Carvalho Chehabconfiguration. The top Makefile textually includes an arch Makefile
78cd238effSMauro Carvalho Chehabwith the name arch/$(ARCH)/Makefile. The arch Makefile supplies
79cd238effSMauro Carvalho Chehabarchitecture-specific information to the top Makefile.
80cd238effSMauro Carvalho Chehab
81cd238effSMauro Carvalho ChehabEach subdirectory has a kbuild Makefile which carries out the commands
82cd238effSMauro Carvalho Chehabpassed down from above. The kbuild Makefile uses information from the
83cd238effSMauro Carvalho Chehab.config file to construct various file lists used by kbuild to build
84cd238effSMauro Carvalho Chehabany built-in or modular targets.
85cd238effSMauro Carvalho Chehab
86cd238effSMauro Carvalho Chehabscripts/Makefile.* contains all the definitions/rules etc. that
87cd238effSMauro Carvalho Chehabare used to build the kernel based on the kbuild makefiles.
88cd238effSMauro Carvalho Chehab
89cd238effSMauro Carvalho Chehab
90cd238effSMauro Carvalho Chehab2 Who does what
91cd238effSMauro Carvalho Chehab===============
92cd238effSMauro Carvalho Chehab
93cd238effSMauro Carvalho ChehabPeople have four different relationships with the kernel Makefiles.
94cd238effSMauro Carvalho Chehab
95cd238effSMauro Carvalho Chehab*Users* are people who build kernels.  These people type commands such as
96cd238effSMauro Carvalho Chehab"make menuconfig" or "make".  They usually do not read or edit
97cd238effSMauro Carvalho Chehabany kernel Makefiles (or any other source files).
98cd238effSMauro Carvalho Chehab
99cd238effSMauro Carvalho Chehab*Normal developers* are people who work on features such as device
100cd238effSMauro Carvalho Chehabdrivers, file systems, and network protocols.  These people need to
101cd238effSMauro Carvalho Chehabmaintain the kbuild Makefiles for the subsystem they are
102cd238effSMauro Carvalho Chehabworking on.  In order to do this effectively, they need some overall
103cd238effSMauro Carvalho Chehabknowledge about the kernel Makefiles, plus detailed knowledge about the
104cd238effSMauro Carvalho Chehabpublic interface for kbuild.
105cd238effSMauro Carvalho Chehab
106cd238effSMauro Carvalho Chehab*Arch developers* are people who work on an entire architecture, such
107cd238effSMauro Carvalho Chehabas sparc or ia64.  Arch developers need to know about the arch Makefile
108cd238effSMauro Carvalho Chehabas well as kbuild Makefiles.
109cd238effSMauro Carvalho Chehab
110cd238effSMauro Carvalho Chehab*Kbuild developers* are people who work on the kernel build system itself.
111cd238effSMauro Carvalho ChehabThese people need to know about all aspects of the kernel Makefiles.
112cd238effSMauro Carvalho Chehab
113cd238effSMauro Carvalho ChehabThis document is aimed towards normal developers and arch developers.
114cd238effSMauro Carvalho Chehab
115cd238effSMauro Carvalho Chehab
116cd238effSMauro Carvalho Chehab3 The kbuild files
117cd238effSMauro Carvalho Chehab==================
118cd238effSMauro Carvalho Chehab
119cd238effSMauro Carvalho ChehabMost Makefiles within the kernel are kbuild Makefiles that use the
120cd238effSMauro Carvalho Chehabkbuild infrastructure. This chapter introduces the syntax used in the
121cd238effSMauro Carvalho Chehabkbuild makefiles.
122cd238effSMauro Carvalho ChehabThe preferred name for the kbuild files are 'Makefile' but 'Kbuild' can
123cd238effSMauro Carvalho Chehabbe used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild'
124cd238effSMauro Carvalho Chehabfile will be used.
125cd238effSMauro Carvalho Chehab
126cd238effSMauro Carvalho ChehabSection 3.1 "Goal definitions" is a quick intro, further chapters provide
127cd238effSMauro Carvalho Chehabmore details, with real examples.
128cd238effSMauro Carvalho Chehab
129cd238effSMauro Carvalho Chehab3.1 Goal definitions
130cd238effSMauro Carvalho Chehab--------------------
131cd238effSMauro Carvalho Chehab
132cd238effSMauro Carvalho Chehab	Goal definitions are the main part (heart) of the kbuild Makefile.
133cd238effSMauro Carvalho Chehab	These lines define the files to be built, any special compilation
134cd238effSMauro Carvalho Chehab	options, and any subdirectories to be entered recursively.
135cd238effSMauro Carvalho Chehab
136cd238effSMauro Carvalho Chehab	The most simple kbuild makefile contains one line:
137cd238effSMauro Carvalho Chehab
138cd238effSMauro Carvalho Chehab	Example::
139cd238effSMauro Carvalho Chehab
140cd238effSMauro Carvalho Chehab		obj-y += foo.o
141cd238effSMauro Carvalho Chehab
142cd238effSMauro Carvalho Chehab	This tells kbuild that there is one object in that directory, named
143cd238effSMauro Carvalho Chehab	foo.o. foo.o will be built from foo.c or foo.S.
144cd238effSMauro Carvalho Chehab
145cd238effSMauro Carvalho Chehab	If foo.o shall be built as a module, the variable obj-m is used.
146cd238effSMauro Carvalho Chehab	Therefore the following pattern is often used:
147cd238effSMauro Carvalho Chehab
148cd238effSMauro Carvalho Chehab	Example::
149cd238effSMauro Carvalho Chehab
150cd238effSMauro Carvalho Chehab		obj-$(CONFIG_FOO) += foo.o
151cd238effSMauro Carvalho Chehab
152cd238effSMauro Carvalho Chehab	$(CONFIG_FOO) evaluates to either y (for built-in) or m (for module).
153cd238effSMauro Carvalho Chehab	If CONFIG_FOO is neither y nor m, then the file will not be compiled
154cd238effSMauro Carvalho Chehab	nor linked.
155cd238effSMauro Carvalho Chehab
156cd238effSMauro Carvalho Chehab3.2 Built-in object goals - obj-y
157cd238effSMauro Carvalho Chehab---------------------------------
158cd238effSMauro Carvalho Chehab
159cd238effSMauro Carvalho Chehab	The kbuild Makefile specifies object files for vmlinux
160cd238effSMauro Carvalho Chehab	in the $(obj-y) lists.  These lists depend on the kernel
161cd238effSMauro Carvalho Chehab	configuration.
162cd238effSMauro Carvalho Chehab
163cd238effSMauro Carvalho Chehab	Kbuild compiles all the $(obj-y) files.  It then calls
164cd238effSMauro Carvalho Chehab	"$(AR) rcSTP" to merge these files into one built-in.a file.
165cd238effSMauro Carvalho Chehab	This is a thin archive without a symbol table. It will be later
166cd238effSMauro Carvalho Chehab	linked into vmlinux by scripts/link-vmlinux.sh
167cd238effSMauro Carvalho Chehab
168cd238effSMauro Carvalho Chehab	The order of files in $(obj-y) is significant.  Duplicates in
169cd238effSMauro Carvalho Chehab	the lists are allowed: the first instance will be linked into
170cd238effSMauro Carvalho Chehab	built-in.a and succeeding instances will be ignored.
171cd238effSMauro Carvalho Chehab
172cd238effSMauro Carvalho Chehab	Link order is significant, because certain functions
173cd238effSMauro Carvalho Chehab	(module_init() / __initcall) will be called during boot in the
174cd238effSMauro Carvalho Chehab	order they appear. So keep in mind that changing the link
175cd238effSMauro Carvalho Chehab	order may e.g. change the order in which your SCSI
176cd238effSMauro Carvalho Chehab	controllers are detected, and thus your disks are renumbered.
177cd238effSMauro Carvalho Chehab
178cd238effSMauro Carvalho Chehab	Example::
179cd238effSMauro Carvalho Chehab
180cd238effSMauro Carvalho Chehab		#drivers/isdn/i4l/Makefile
181cd238effSMauro Carvalho Chehab		# Makefile for the kernel ISDN subsystem and device drivers.
182cd238effSMauro Carvalho Chehab		# Each configuration option enables a list of files.
183cd238effSMauro Carvalho Chehab		obj-$(CONFIG_ISDN_I4L)         += isdn.o
184cd238effSMauro Carvalho Chehab		obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o
185cd238effSMauro Carvalho Chehab
186cd238effSMauro Carvalho Chehab3.3 Loadable module goals - obj-m
187cd238effSMauro Carvalho Chehab---------------------------------
188cd238effSMauro Carvalho Chehab
189cd238effSMauro Carvalho Chehab	$(obj-m) specifies object files which are built as loadable
190cd238effSMauro Carvalho Chehab	kernel modules.
191cd238effSMauro Carvalho Chehab
192cd238effSMauro Carvalho Chehab	A module may be built from one source file or several source
193cd238effSMauro Carvalho Chehab	files. In the case of one source file, the kbuild makefile
194cd238effSMauro Carvalho Chehab	simply adds the file to $(obj-m).
195cd238effSMauro Carvalho Chehab
196cd238effSMauro Carvalho Chehab	Example::
197cd238effSMauro Carvalho Chehab
198cd238effSMauro Carvalho Chehab		#drivers/isdn/i4l/Makefile
199cd238effSMauro Carvalho Chehab		obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o
200cd238effSMauro Carvalho Chehab
201cd238effSMauro Carvalho Chehab	Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm'
202cd238effSMauro Carvalho Chehab
203cd238effSMauro Carvalho Chehab	If a kernel module is built from several source files, you specify
204cd238effSMauro Carvalho Chehab	that you want to build a module in the same way as above; however,
205cd238effSMauro Carvalho Chehab	kbuild needs to know which object files you want to build your
206cd238effSMauro Carvalho Chehab	module from, so you have to tell it by setting a $(<module_name>-y)
207cd238effSMauro Carvalho Chehab	variable.
208cd238effSMauro Carvalho Chehab
209cd238effSMauro Carvalho Chehab	Example::
210cd238effSMauro Carvalho Chehab
211cd238effSMauro Carvalho Chehab		#drivers/isdn/i4l/Makefile
212cd238effSMauro Carvalho Chehab		obj-$(CONFIG_ISDN_I4L) += isdn.o
213cd238effSMauro Carvalho Chehab		isdn-y := isdn_net_lib.o isdn_v110.o isdn_common.o
214cd238effSMauro Carvalho Chehab
215cd238effSMauro Carvalho Chehab	In this example, the module name will be isdn.o. Kbuild will
216cd238effSMauro Carvalho Chehab	compile the objects listed in $(isdn-y) and then run
217cd238effSMauro Carvalho Chehab	"$(LD) -r" on the list of these files to generate isdn.o.
218cd238effSMauro Carvalho Chehab
219cd238effSMauro Carvalho Chehab	Due to kbuild recognizing $(<module_name>-y) for composite objects,
220cd238effSMauro Carvalho Chehab	you can use the value of a `CONFIG_` symbol to optionally include an
221cd238effSMauro Carvalho Chehab	object file as part of a composite object.
222cd238effSMauro Carvalho Chehab
223cd238effSMauro Carvalho Chehab	Example::
224cd238effSMauro Carvalho Chehab
225cd238effSMauro Carvalho Chehab		#fs/ext2/Makefile
226cd238effSMauro Carvalho Chehab	        obj-$(CONFIG_EXT2_FS) += ext2.o
227cd238effSMauro Carvalho Chehab		ext2-y := balloc.o dir.o file.o ialloc.o inode.o ioctl.o \
228cd238effSMauro Carvalho Chehab			  namei.o super.o symlink.o
229cd238effSMauro Carvalho Chehab	        ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o \
230cd238effSMauro Carvalho Chehab						xattr_trusted.o
231cd238effSMauro Carvalho Chehab
232cd238effSMauro Carvalho Chehab	In this example, xattr.o, xattr_user.o and xattr_trusted.o are only
233cd238effSMauro Carvalho Chehab	part of the composite object ext2.o if $(CONFIG_EXT2_FS_XATTR)
234cd238effSMauro Carvalho Chehab	evaluates to 'y'.
235cd238effSMauro Carvalho Chehab
236cd238effSMauro Carvalho Chehab	Note: Of course, when you are building objects into the kernel,
237cd238effSMauro Carvalho Chehab	the syntax above will also work. So, if you have CONFIG_EXT2_FS=y,
238cd238effSMauro Carvalho Chehab	kbuild will build an ext2.o file for you out of the individual
239cd238effSMauro Carvalho Chehab	parts and then link this into built-in.a, as you would expect.
240cd238effSMauro Carvalho Chehab
241cd238effSMauro Carvalho Chehab3.4 Objects which export symbols
242cd238effSMauro Carvalho Chehab--------------------------------
243cd238effSMauro Carvalho Chehab
244cd238effSMauro Carvalho Chehab	No special notation is required in the makefiles for
245cd238effSMauro Carvalho Chehab	modules exporting symbols.
246cd238effSMauro Carvalho Chehab
247cd238effSMauro Carvalho Chehab3.5 Library file goals - lib-y
248cd238effSMauro Carvalho Chehab------------------------------
249cd238effSMauro Carvalho Chehab
250cd238effSMauro Carvalho Chehab	Objects listed with obj-* are used for modules, or
251cd238effSMauro Carvalho Chehab	combined in a built-in.a for that specific directory.
252cd238effSMauro Carvalho Chehab	There is also the possibility to list objects that will
253cd238effSMauro Carvalho Chehab	be included in a library, lib.a.
254cd238effSMauro Carvalho Chehab	All objects listed with lib-y are combined in a single
255cd238effSMauro Carvalho Chehab	library for that directory.
256cd238effSMauro Carvalho Chehab	Objects that are listed in obj-y and additionally listed in
257cd238effSMauro Carvalho Chehab	lib-y will not be included in the library, since they will
258cd238effSMauro Carvalho Chehab	be accessible anyway.
259cd238effSMauro Carvalho Chehab	For consistency, objects listed in lib-m will be included in lib.a.
260cd238effSMauro Carvalho Chehab
261cd238effSMauro Carvalho Chehab	Note that the same kbuild makefile may list files to be built-in
262cd238effSMauro Carvalho Chehab	and to be part of a library. Therefore the same directory
263cd238effSMauro Carvalho Chehab	may contain both a built-in.a and a lib.a file.
264cd238effSMauro Carvalho Chehab
265cd238effSMauro Carvalho Chehab	Example::
266cd238effSMauro Carvalho Chehab
267cd238effSMauro Carvalho Chehab		#arch/x86/lib/Makefile
268cd238effSMauro Carvalho Chehab		lib-y    := delay.o
269cd238effSMauro Carvalho Chehab
270cd238effSMauro Carvalho Chehab	This will create a library lib.a based on delay.o. For kbuild to
271cd238effSMauro Carvalho Chehab	actually recognize that there is a lib.a being built, the directory
272cd238effSMauro Carvalho Chehab	shall be listed in libs-y.
273cd238effSMauro Carvalho Chehab
274cd238effSMauro Carvalho Chehab	See also "6.4 List directories to visit when descending".
275cd238effSMauro Carvalho Chehab
276cd238effSMauro Carvalho Chehab	Use of lib-y is normally restricted to `lib/` and `arch/*/lib`.
277cd238effSMauro Carvalho Chehab
278cd238effSMauro Carvalho Chehab3.6 Descending down in directories
279cd238effSMauro Carvalho Chehab----------------------------------
280cd238effSMauro Carvalho Chehab
281cd238effSMauro Carvalho Chehab	A Makefile is only responsible for building objects in its own
282cd238effSMauro Carvalho Chehab	directory. Files in subdirectories should be taken care of by
283cd238effSMauro Carvalho Chehab	Makefiles in these subdirs. The build system will automatically
284cd238effSMauro Carvalho Chehab	invoke make recursively in subdirectories, provided you let it know of
285cd238effSMauro Carvalho Chehab	them.
286cd238effSMauro Carvalho Chehab
287cd238effSMauro Carvalho Chehab	To do so, obj-y and obj-m are used.
288cd238effSMauro Carvalho Chehab	ext2 lives in a separate directory, and the Makefile present in fs/
289cd238effSMauro Carvalho Chehab	tells kbuild to descend down using the following assignment.
290cd238effSMauro Carvalho Chehab
291cd238effSMauro Carvalho Chehab	Example::
292cd238effSMauro Carvalho Chehab
293cd238effSMauro Carvalho Chehab		#fs/Makefile
294cd238effSMauro Carvalho Chehab		obj-$(CONFIG_EXT2_FS) += ext2/
295cd238effSMauro Carvalho Chehab
296cd238effSMauro Carvalho Chehab	If CONFIG_EXT2_FS is set to either 'y' (built-in) or 'm' (modular)
297cd238effSMauro Carvalho Chehab	the corresponding obj- variable will be set, and kbuild will descend
298cd238effSMauro Carvalho Chehab	down in the ext2 directory.
29928f94a44SMasahiro Yamada
30028f94a44SMasahiro Yamada	Kbuild uses this information not only to decide that it needs to visit
30128f94a44SMasahiro Yamada	the directory, but also to decide whether or not to link objects from
30228f94a44SMasahiro Yamada	the directory into vmlinux.
30328f94a44SMasahiro Yamada
30428f94a44SMasahiro Yamada	When Kbuild descends into the directory with 'y', all built-in objects
30528f94a44SMasahiro Yamada	from that directory are combined into the built-in.a, which will be
30628f94a44SMasahiro Yamada	eventually linked into vmlinux.
30728f94a44SMasahiro Yamada
30828f94a44SMasahiro Yamada	When Kbuild descends into the directory with 'm', in contrast, nothing
30928f94a44SMasahiro Yamada	from that directory will be linked into vmlinux. If the Makefile in
31028f94a44SMasahiro Yamada	that directory specifies obj-y, those objects will be left orphan.
31128f94a44SMasahiro Yamada	It is very likely a bug of the Makefile or of dependencies in Kconfig.
312cd238effSMauro Carvalho Chehab
313cd238effSMauro Carvalho Chehab	It is good practice to use a `CONFIG_` variable when assigning directory
314cd238effSMauro Carvalho Chehab	names. This allows kbuild to totally skip the directory if the
315cd238effSMauro Carvalho Chehab	corresponding `CONFIG_` option is neither 'y' nor 'm'.
316cd238effSMauro Carvalho Chehab
317cd238effSMauro Carvalho Chehab3.7 Compilation flags
318cd238effSMauro Carvalho Chehab---------------------
319cd238effSMauro Carvalho Chehab
320cd238effSMauro Carvalho Chehab    ccflags-y, asflags-y and ldflags-y
321cd238effSMauro Carvalho Chehab	These three flags apply only to the kbuild makefile in which they
322cd238effSMauro Carvalho Chehab	are assigned. They are used for all the normal cc, as and ld
323cd238effSMauro Carvalho Chehab	invocations happening during a recursive build.
324cd238effSMauro Carvalho Chehab	Note: Flags with the same behaviour were previously named:
325cd238effSMauro Carvalho Chehab	EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS.
326cd238effSMauro Carvalho Chehab	They are still supported but their usage is deprecated.
327cd238effSMauro Carvalho Chehab
328cd238effSMauro Carvalho Chehab	ccflags-y specifies options for compiling with $(CC).
329cd238effSMauro Carvalho Chehab
330cd238effSMauro Carvalho Chehab	Example::
331cd238effSMauro Carvalho Chehab
332cd238effSMauro Carvalho Chehab		# drivers/acpi/acpica/Makefile
333cd238effSMauro Carvalho Chehab		ccflags-y			:= -Os -D_LINUX -DBUILDING_ACPICA
334cd238effSMauro Carvalho Chehab		ccflags-$(CONFIG_ACPI_DEBUG)	+= -DACPI_DEBUG_OUTPUT
335cd238effSMauro Carvalho Chehab
336cd238effSMauro Carvalho Chehab	This variable is necessary because the top Makefile owns the
337cd238effSMauro Carvalho Chehab	variable $(KBUILD_CFLAGS) and uses it for compilation flags for the
338cd238effSMauro Carvalho Chehab	entire tree.
339cd238effSMauro Carvalho Chehab
3405ef87263SMasahiro Yamada	asflags-y specifies assembler options.
341cd238effSMauro Carvalho Chehab
342cd238effSMauro Carvalho Chehab	Example::
343cd238effSMauro Carvalho Chehab
344cd238effSMauro Carvalho Chehab		#arch/sparc/kernel/Makefile
345cd238effSMauro Carvalho Chehab		asflags-y := -ansi
346cd238effSMauro Carvalho Chehab
347cd238effSMauro Carvalho Chehab	ldflags-y specifies options for linking with $(LD).
348cd238effSMauro Carvalho Chehab
349cd238effSMauro Carvalho Chehab	Example::
350cd238effSMauro Carvalho Chehab
351cd238effSMauro Carvalho Chehab		#arch/cris/boot/compressed/Makefile
352cd238effSMauro Carvalho Chehab		ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds
353cd238effSMauro Carvalho Chehab
354cd238effSMauro Carvalho Chehab    subdir-ccflags-y, subdir-asflags-y
355cd238effSMauro Carvalho Chehab	The two flags listed above are similar to ccflags-y and asflags-y.
356cd238effSMauro Carvalho Chehab	The difference is that the subdir- variants have effect for the kbuild
357cd238effSMauro Carvalho Chehab	file where they are present and all subdirectories.
358cd238effSMauro Carvalho Chehab	Options specified using subdir-* are added to the commandline before
359cd238effSMauro Carvalho Chehab	the options specified using the non-subdir variants.
360cd238effSMauro Carvalho Chehab
361cd238effSMauro Carvalho Chehab	Example::
362cd238effSMauro Carvalho Chehab
363cd238effSMauro Carvalho Chehab		subdir-ccflags-y := -Werror
364cd238effSMauro Carvalho Chehab
365cd238effSMauro Carvalho Chehab    CFLAGS_$@, AFLAGS_$@
366cd238effSMauro Carvalho Chehab	CFLAGS_$@ and AFLAGS_$@ only apply to commands in current
367cd238effSMauro Carvalho Chehab	kbuild makefile.
368cd238effSMauro Carvalho Chehab
369cd238effSMauro Carvalho Chehab	$(CFLAGS_$@) specifies per-file options for $(CC).  The $@
370cd238effSMauro Carvalho Chehab	part has a literal value which specifies the file that it is for.
371cd238effSMauro Carvalho Chehab
372cd238effSMauro Carvalho Chehab	Example::
373cd238effSMauro Carvalho Chehab
374cd238effSMauro Carvalho Chehab		# drivers/scsi/Makefile
375cd238effSMauro Carvalho Chehab		CFLAGS_aha152x.o =   -DAHA152X_STAT -DAUTOCONF
376cd238effSMauro Carvalho Chehab		CFLAGS_gdth.o    = # -DDEBUG_GDTH=2 -D__SERIAL__ -D__COM2__ \
377cd238effSMauro Carvalho Chehab				     -DGDTH_STATISTICS
378cd238effSMauro Carvalho Chehab
379cd238effSMauro Carvalho Chehab	These two lines specify compilation flags for aha152x.o and gdth.o.
380cd238effSMauro Carvalho Chehab
381cd238effSMauro Carvalho Chehab	$(AFLAGS_$@) is a similar feature for source files in assembly
382cd238effSMauro Carvalho Chehab	languages.
383cd238effSMauro Carvalho Chehab
384cd238effSMauro Carvalho Chehab	Example::
385cd238effSMauro Carvalho Chehab
386cd238effSMauro Carvalho Chehab		# arch/arm/kernel/Makefile
387cd238effSMauro Carvalho Chehab		AFLAGS_head.o        := -DTEXT_OFFSET=$(TEXT_OFFSET)
388cd238effSMauro Carvalho Chehab		AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312
389cd238effSMauro Carvalho Chehab		AFLAGS_iwmmxt.o      := -Wa,-mcpu=iwmmxt
390cd238effSMauro Carvalho Chehab
391cd238effSMauro Carvalho Chehab
392cd238effSMauro Carvalho Chehab3.9 Dependency tracking
393cd238effSMauro Carvalho Chehab-----------------------
394cd238effSMauro Carvalho Chehab
395cd238effSMauro Carvalho Chehab	Kbuild tracks dependencies on the following:
39616886949SMauro Carvalho Chehab
397cd238effSMauro Carvalho Chehab	1) All prerequisite files (both `*.c` and `*.h`)
398cd238effSMauro Carvalho Chehab	2) `CONFIG_` options used in all prerequisite files
399cd238effSMauro Carvalho Chehab	3) Command-line used to compile target
400cd238effSMauro Carvalho Chehab
401cd238effSMauro Carvalho Chehab	Thus, if you change an option to $(CC) all affected files will
402cd238effSMauro Carvalho Chehab	be re-compiled.
403cd238effSMauro Carvalho Chehab
404cd238effSMauro Carvalho Chehab3.10 Special Rules
405cd238effSMauro Carvalho Chehab------------------
406cd238effSMauro Carvalho Chehab
407cd238effSMauro Carvalho Chehab	Special rules are used when the kbuild infrastructure does
408cd238effSMauro Carvalho Chehab	not provide the required support. A typical example is
409cd238effSMauro Carvalho Chehab	header files generated during the build process.
410cd238effSMauro Carvalho Chehab	Another example are the architecture-specific Makefiles which
411cd238effSMauro Carvalho Chehab	need special rules to prepare boot images etc.
412cd238effSMauro Carvalho Chehab
413cd238effSMauro Carvalho Chehab	Special rules are written as normal Make rules.
414cd238effSMauro Carvalho Chehab	Kbuild is not executing in the directory where the Makefile is
415cd238effSMauro Carvalho Chehab	located, so all special rules shall provide a relative
416cd238effSMauro Carvalho Chehab	path to prerequisite files and target files.
417cd238effSMauro Carvalho Chehab
418cd238effSMauro Carvalho Chehab	Two variables are used when defining special rules:
419cd238effSMauro Carvalho Chehab
420cd238effSMauro Carvalho Chehab	$(src)
421cd238effSMauro Carvalho Chehab	    $(src) is a relative path which points to the directory
422cd238effSMauro Carvalho Chehab	    where the Makefile is located. Always use $(src) when
423cd238effSMauro Carvalho Chehab	    referring to files located in the src tree.
424cd238effSMauro Carvalho Chehab
425cd238effSMauro Carvalho Chehab	$(obj)
426cd238effSMauro Carvalho Chehab	    $(obj) is a relative path which points to the directory
427cd238effSMauro Carvalho Chehab	    where the target is saved. Always use $(obj) when
428cd238effSMauro Carvalho Chehab	    referring to generated files.
429cd238effSMauro Carvalho Chehab
430cd238effSMauro Carvalho Chehab	    Example::
431cd238effSMauro Carvalho Chehab
432cd238effSMauro Carvalho Chehab		#drivers/scsi/Makefile
433cd238effSMauro Carvalho Chehab		$(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl
434cd238effSMauro Carvalho Chehab			$(CPP) -DCHIP=810 - < $< | ... $(src)/script_asm.pl
435cd238effSMauro Carvalho Chehab
436cd238effSMauro Carvalho Chehab	    This is a special rule, following the normal syntax
437cd238effSMauro Carvalho Chehab	    required by make.
438cd238effSMauro Carvalho Chehab
439cd238effSMauro Carvalho Chehab	    The target file depends on two prerequisite files. References
440cd238effSMauro Carvalho Chehab	    to the target file are prefixed with $(obj), references
441cd238effSMauro Carvalho Chehab	    to prerequisites are referenced with $(src) (because they are not
442cd238effSMauro Carvalho Chehab	    generated files).
443cd238effSMauro Carvalho Chehab
444cd238effSMauro Carvalho Chehab	$(kecho)
445cd238effSMauro Carvalho Chehab	    echoing information to user in a rule is often a good practice
446cd238effSMauro Carvalho Chehab	    but when execution "make -s" one does not expect to see any output
447cd238effSMauro Carvalho Chehab	    except for warnings/errors.
448cd238effSMauro Carvalho Chehab	    To support this kbuild defines $(kecho) which will echo out the
449cd238effSMauro Carvalho Chehab	    text following $(kecho) to stdout except if "make -s" is used.
450cd238effSMauro Carvalho Chehab
451cd238effSMauro Carvalho Chehab	Example::
452cd238effSMauro Carvalho Chehab
453cd238effSMauro Carvalho Chehab		#arch/blackfin/boot/Makefile
454cd238effSMauro Carvalho Chehab		$(obj)/vmImage: $(obj)/vmlinux.gz
455cd238effSMauro Carvalho Chehab			$(call if_changed,uimage)
456cd238effSMauro Carvalho Chehab			@$(kecho) 'Kernel: $@ is ready'
457cd238effSMauro Carvalho Chehab
458cd238effSMauro Carvalho Chehab
459cd238effSMauro Carvalho Chehab3.11 $(CC) support functions
460cd238effSMauro Carvalho Chehab----------------------------
461cd238effSMauro Carvalho Chehab
462cd238effSMauro Carvalho Chehab	The kernel may be built with several different versions of
463cd238effSMauro Carvalho Chehab	$(CC), each supporting a unique set of features and options.
464cd238effSMauro Carvalho Chehab	kbuild provides basic support to check for valid options for $(CC).
465cd238effSMauro Carvalho Chehab	$(CC) is usually the gcc compiler, but other alternatives are
466cd238effSMauro Carvalho Chehab	available.
467cd238effSMauro Carvalho Chehab
468cd238effSMauro Carvalho Chehab    as-option
469cd238effSMauro Carvalho Chehab	as-option is used to check if $(CC) -- when used to compile
470cd238effSMauro Carvalho Chehab	assembler (`*.S`) files -- supports the given option. An optional
471cd238effSMauro Carvalho Chehab	second option may be specified if the first option is not supported.
472cd238effSMauro Carvalho Chehab
473cd238effSMauro Carvalho Chehab	Example::
474cd238effSMauro Carvalho Chehab
475cd238effSMauro Carvalho Chehab		#arch/sh/Makefile
476cd238effSMauro Carvalho Chehab		cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),)
477cd238effSMauro Carvalho Chehab
478cd238effSMauro Carvalho Chehab	In the above example, cflags-y will be assigned the option
479cd238effSMauro Carvalho Chehab	-Wa$(comma)-isa=$(isa-y) if it is supported by $(CC).
480cd238effSMauro Carvalho Chehab	The second argument is optional, and if supplied will be used
481cd238effSMauro Carvalho Chehab	if first argument is not supported.
482cd238effSMauro Carvalho Chehab
483cd238effSMauro Carvalho Chehab    as-instr
484cd238effSMauro Carvalho Chehab	as-instr checks if the assembler reports a specific instruction
485cd238effSMauro Carvalho Chehab	and then outputs either option1 or option2
486cd238effSMauro Carvalho Chehab	C escapes are supported in the test instruction
4875ef87263SMasahiro Yamada	Note: as-instr-option uses KBUILD_AFLAGS for assembler options
488cd238effSMauro Carvalho Chehab
489cd238effSMauro Carvalho Chehab    cc-option
490cd238effSMauro Carvalho Chehab	cc-option is used to check if $(CC) supports a given option, and if
491cd238effSMauro Carvalho Chehab	not supported to use an optional second option.
492cd238effSMauro Carvalho Chehab
493cd238effSMauro Carvalho Chehab	Example::
494cd238effSMauro Carvalho Chehab
495cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
496cd238effSMauro Carvalho Chehab		cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
497cd238effSMauro Carvalho Chehab
498cd238effSMauro Carvalho Chehab	In the above example, cflags-y will be assigned the option
499cd238effSMauro Carvalho Chehab	-march=pentium-mmx if supported by $(CC), otherwise -march=i586.
500cd238effSMauro Carvalho Chehab	The second argument to cc-option is optional, and if omitted,
501cd238effSMauro Carvalho Chehab	cflags-y will be assigned no value if first option is not supported.
502cd238effSMauro Carvalho Chehab	Note: cc-option uses KBUILD_CFLAGS for $(CC) options
503cd238effSMauro Carvalho Chehab
504cd238effSMauro Carvalho Chehab   cc-option-yn
505cd238effSMauro Carvalho Chehab	cc-option-yn is used to check if gcc supports a given option
506cd238effSMauro Carvalho Chehab	and return 'y' if supported, otherwise 'n'.
507cd238effSMauro Carvalho Chehab
508cd238effSMauro Carvalho Chehab	Example::
509cd238effSMauro Carvalho Chehab
510cd238effSMauro Carvalho Chehab		#arch/ppc/Makefile
511cd238effSMauro Carvalho Chehab		biarch := $(call cc-option-yn, -m32)
512cd238effSMauro Carvalho Chehab		aflags-$(biarch) += -a32
513cd238effSMauro Carvalho Chehab		cflags-$(biarch) += -m32
514cd238effSMauro Carvalho Chehab
515cd238effSMauro Carvalho Chehab	In the above example, $(biarch) is set to y if $(CC) supports the -m32
516cd238effSMauro Carvalho Chehab	option. When $(biarch) equals 'y', the expanded variables $(aflags-y)
517cd238effSMauro Carvalho Chehab	and $(cflags-y) will be assigned the values -a32 and -m32,
518cd238effSMauro Carvalho Chehab	respectively.
519cd238effSMauro Carvalho Chehab	Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options
520cd238effSMauro Carvalho Chehab
521cd238effSMauro Carvalho Chehab    cc-disable-warning
522cd238effSMauro Carvalho Chehab	cc-disable-warning checks if gcc supports a given warning and returns
523cd238effSMauro Carvalho Chehab	the commandline switch to disable it. This special function is needed,
524cd238effSMauro Carvalho Chehab	because gcc 4.4 and later accept any unknown -Wno-* option and only
525cd238effSMauro Carvalho Chehab	warn about it if there is another warning in the source file.
526cd238effSMauro Carvalho Chehab
527cd238effSMauro Carvalho Chehab	Example::
528cd238effSMauro Carvalho Chehab
529cd238effSMauro Carvalho Chehab		KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
530cd238effSMauro Carvalho Chehab
531cd238effSMauro Carvalho Chehab	In the above example, -Wno-unused-but-set-variable will be added to
532cd238effSMauro Carvalho Chehab	KBUILD_CFLAGS only if gcc really accepts it.
533cd238effSMauro Carvalho Chehab
534cd238effSMauro Carvalho Chehab    cc-ifversion
535cd238effSMauro Carvalho Chehab	cc-ifversion tests the version of $(CC) and equals the fourth parameter
536cd238effSMauro Carvalho Chehab	if version expression is true, or the fifth (if given) if the version
537cd238effSMauro Carvalho Chehab	expression is false.
538cd238effSMauro Carvalho Chehab
539cd238effSMauro Carvalho Chehab	Example::
540cd238effSMauro Carvalho Chehab
541cd238effSMauro Carvalho Chehab		#fs/reiserfs/Makefile
542cd238effSMauro Carvalho Chehab		ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
543cd238effSMauro Carvalho Chehab
544cd238effSMauro Carvalho Chehab	In this example, ccflags-y will be assigned the value -O1 if the
545cd238effSMauro Carvalho Chehab	$(CC) version is less than 4.2.
546cd238effSMauro Carvalho Chehab	cc-ifversion takes all the shell operators:
547cd238effSMauro Carvalho Chehab	-eq, -ne, -lt, -le, -gt, and -ge
548cd238effSMauro Carvalho Chehab	The third parameter may be a text as in this example, but it may also
549cd238effSMauro Carvalho Chehab	be an expanded variable or a macro.
550cd238effSMauro Carvalho Chehab
551cd238effSMauro Carvalho Chehab    cc-cross-prefix
552cd238effSMauro Carvalho Chehab	cc-cross-prefix is used to check if there exists a $(CC) in path with
553cd238effSMauro Carvalho Chehab	one of the listed prefixes. The first prefix where there exist a
554cd238effSMauro Carvalho Chehab	prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found
555cd238effSMauro Carvalho Chehab	then nothing is returned.
556cd238effSMauro Carvalho Chehab	Additional prefixes are separated by a single space in the
557cd238effSMauro Carvalho Chehab	call of cc-cross-prefix.
558cd238effSMauro Carvalho Chehab	This functionality is useful for architecture Makefiles that try
559cd238effSMauro Carvalho Chehab	to set CROSS_COMPILE to well-known values but may have several
560cd238effSMauro Carvalho Chehab	values to select between.
561cd238effSMauro Carvalho Chehab	It is recommended only to try to set CROSS_COMPILE if it is a cross
562cd238effSMauro Carvalho Chehab	build (host arch is different from target arch). And if CROSS_COMPILE
563cd238effSMauro Carvalho Chehab	is already set then leave it with the old value.
564cd238effSMauro Carvalho Chehab
565cd238effSMauro Carvalho Chehab	Example::
566cd238effSMauro Carvalho Chehab
567cd238effSMauro Carvalho Chehab		#arch/m68k/Makefile
568cd238effSMauro Carvalho Chehab		ifneq ($(SUBARCH),$(ARCH))
569cd238effSMauro Carvalho Chehab		        ifeq ($(CROSS_COMPILE),)
570cd238effSMauro Carvalho Chehab		               CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-)
571cd238effSMauro Carvalho Chehab			endif
572cd238effSMauro Carvalho Chehab		endif
573cd238effSMauro Carvalho Chehab
574cd238effSMauro Carvalho Chehab3.12 $(LD) support functions
575cd238effSMauro Carvalho Chehab----------------------------
576cd238effSMauro Carvalho Chehab
577cd238effSMauro Carvalho Chehab    ld-option
578cd238effSMauro Carvalho Chehab	ld-option is used to check if $(LD) supports the supplied option.
579cd238effSMauro Carvalho Chehab	ld-option takes two options as arguments.
580cd238effSMauro Carvalho Chehab	The second argument is an optional option that can be used if the
581cd238effSMauro Carvalho Chehab	first option is not supported by $(LD).
582cd238effSMauro Carvalho Chehab
583cd238effSMauro Carvalho Chehab	Example::
584cd238effSMauro Carvalho Chehab
585cd238effSMauro Carvalho Chehab		#Makefile
586cd238effSMauro Carvalho Chehab		LDFLAGS_vmlinux += $(call ld-option, -X)
587cd238effSMauro Carvalho Chehab
588cd238effSMauro Carvalho Chehab
589cd238effSMauro Carvalho Chehab4 Host Program support
590cd238effSMauro Carvalho Chehab======================
591cd238effSMauro Carvalho Chehab
592cd238effSMauro Carvalho ChehabKbuild supports building executables on the host for use during the
593cd238effSMauro Carvalho Chehabcompilation stage.
594cd238effSMauro Carvalho ChehabTwo steps are required in order to use a host executable.
595cd238effSMauro Carvalho Chehab
596cd238effSMauro Carvalho ChehabThe first step is to tell kbuild that a host program exists. This is
5975f2fb52fSMasahiro Yamadadone utilising the variable "hostprogs".
598cd238effSMauro Carvalho Chehab
599cd238effSMauro Carvalho ChehabThe second step is to add an explicit dependency to the executable.
600cd238effSMauro Carvalho ChehabThis can be done in two ways. Either add the dependency in a rule,
6015f2fb52fSMasahiro Yamadaor utilise the variable "always-y".
602cd238effSMauro Carvalho ChehabBoth possibilities are described in the following.
603cd238effSMauro Carvalho Chehab
604cd238effSMauro Carvalho Chehab4.1 Simple Host Program
605cd238effSMauro Carvalho Chehab-----------------------
606cd238effSMauro Carvalho Chehab
607cd238effSMauro Carvalho Chehab	In some cases there is a need to compile and run a program on the
608cd238effSMauro Carvalho Chehab	computer where the build is running.
609cd238effSMauro Carvalho Chehab	The following line tells kbuild that the program bin2hex shall be
610cd238effSMauro Carvalho Chehab	built on the build host.
611cd238effSMauro Carvalho Chehab
612cd238effSMauro Carvalho Chehab	Example::
613cd238effSMauro Carvalho Chehab
6145f2fb52fSMasahiro Yamada		hostprogs := bin2hex
615cd238effSMauro Carvalho Chehab
616cd238effSMauro Carvalho Chehab	Kbuild assumes in the above example that bin2hex is made from a single
617cd238effSMauro Carvalho Chehab	c-source file named bin2hex.c located in the same directory as
618cd238effSMauro Carvalho Chehab	the Makefile.
619cd238effSMauro Carvalho Chehab
620cd238effSMauro Carvalho Chehab4.2 Composite Host Programs
621cd238effSMauro Carvalho Chehab---------------------------
622cd238effSMauro Carvalho Chehab
623cd238effSMauro Carvalho Chehab	Host programs can be made up based on composite objects.
624cd238effSMauro Carvalho Chehab	The syntax used to define composite objects for host programs is
625cd238effSMauro Carvalho Chehab	similar to the syntax used for kernel objects.
626cd238effSMauro Carvalho Chehab	$(<executable>-objs) lists all objects used to link the final
627cd238effSMauro Carvalho Chehab	executable.
628cd238effSMauro Carvalho Chehab
629cd238effSMauro Carvalho Chehab	Example::
630cd238effSMauro Carvalho Chehab
631cd238effSMauro Carvalho Chehab		#scripts/lxdialog/Makefile
6325f2fb52fSMasahiro Yamada		hostprogs     := lxdialog
633cd238effSMauro Carvalho Chehab		lxdialog-objs := checklist.o lxdialog.o
634cd238effSMauro Carvalho Chehab
635cd238effSMauro Carvalho Chehab	Objects with extension .o are compiled from the corresponding .c
636cd238effSMauro Carvalho Chehab	files. In the above example, checklist.c is compiled to checklist.o
637cd238effSMauro Carvalho Chehab	and lxdialog.c is compiled to lxdialog.o.
638cd238effSMauro Carvalho Chehab
639cd238effSMauro Carvalho Chehab	Finally, the two .o files are linked to the executable, lxdialog.
640cd238effSMauro Carvalho Chehab	Note: The syntax <executable>-y is not permitted for host-programs.
641cd238effSMauro Carvalho Chehab
642cd238effSMauro Carvalho Chehab4.3 Using C++ for host programs
643cd238effSMauro Carvalho Chehab-------------------------------
644cd238effSMauro Carvalho Chehab
645cd238effSMauro Carvalho Chehab	kbuild offers support for host programs written in C++. This was
646cd238effSMauro Carvalho Chehab	introduced solely to support kconfig, and is not recommended
647cd238effSMauro Carvalho Chehab	for general use.
648cd238effSMauro Carvalho Chehab
649cd238effSMauro Carvalho Chehab	Example::
650cd238effSMauro Carvalho Chehab
651cd238effSMauro Carvalho Chehab		#scripts/kconfig/Makefile
6525f2fb52fSMasahiro Yamada		hostprogs     := qconf
653cd238effSMauro Carvalho Chehab		qconf-cxxobjs := qconf.o
654cd238effSMauro Carvalho Chehab
655cd238effSMauro Carvalho Chehab	In the example above the executable is composed of the C++ file
656cd238effSMauro Carvalho Chehab	qconf.cc - identified by $(qconf-cxxobjs).
657cd238effSMauro Carvalho Chehab
658cd238effSMauro Carvalho Chehab	If qconf is composed of a mixture of .c and .cc files, then an
659cd238effSMauro Carvalho Chehab	additional line can be used to identify this.
660cd238effSMauro Carvalho Chehab
661cd238effSMauro Carvalho Chehab	Example::
662cd238effSMauro Carvalho Chehab
663cd238effSMauro Carvalho Chehab		#scripts/kconfig/Makefile
6645f2fb52fSMasahiro Yamada		hostprogs     := qconf
665cd238effSMauro Carvalho Chehab		qconf-cxxobjs := qconf.o
666cd238effSMauro Carvalho Chehab		qconf-objs    := check.o
667cd238effSMauro Carvalho Chehab
668cd238effSMauro Carvalho Chehab4.4 Controlling compiler options for host programs
669cd238effSMauro Carvalho Chehab--------------------------------------------------
670cd238effSMauro Carvalho Chehab
671cd238effSMauro Carvalho Chehab	When compiling host programs, it is possible to set specific flags.
672cd238effSMauro Carvalho Chehab	The programs will always be compiled utilising $(HOSTCC) passed
673cd238effSMauro Carvalho Chehab	the options specified in $(KBUILD_HOSTCFLAGS).
674cd238effSMauro Carvalho Chehab	To set flags that will take effect for all host programs created
675cd238effSMauro Carvalho Chehab	in that Makefile, use the variable HOST_EXTRACFLAGS.
676cd238effSMauro Carvalho Chehab
677cd238effSMauro Carvalho Chehab	Example::
678cd238effSMauro Carvalho Chehab
679cd238effSMauro Carvalho Chehab		#scripts/lxdialog/Makefile
680cd238effSMauro Carvalho Chehab		HOST_EXTRACFLAGS += -I/usr/include/ncurses
681cd238effSMauro Carvalho Chehab
682cd238effSMauro Carvalho Chehab	To set specific flags for a single file the following construction
683cd238effSMauro Carvalho Chehab	is used:
684cd238effSMauro Carvalho Chehab
685cd238effSMauro Carvalho Chehab	Example::
686cd238effSMauro Carvalho Chehab
687cd238effSMauro Carvalho Chehab		#arch/ppc64/boot/Makefile
688cd238effSMauro Carvalho Chehab		HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE)
689cd238effSMauro Carvalho Chehab
690cd238effSMauro Carvalho Chehab	It is also possible to specify additional options to the linker.
691cd238effSMauro Carvalho Chehab
692cd238effSMauro Carvalho Chehab	Example::
693cd238effSMauro Carvalho Chehab
694cd238effSMauro Carvalho Chehab		#scripts/kconfig/Makefile
695cd238effSMauro Carvalho Chehab		HOSTLDLIBS_qconf := -L$(QTDIR)/lib
696cd238effSMauro Carvalho Chehab
697cd238effSMauro Carvalho Chehab	When linking qconf, it will be passed the extra option
698cd238effSMauro Carvalho Chehab	"-L$(QTDIR)/lib".
699cd238effSMauro Carvalho Chehab
700cd238effSMauro Carvalho Chehab4.5 When host programs are actually built
701cd238effSMauro Carvalho Chehab-----------------------------------------
702cd238effSMauro Carvalho Chehab
703cd238effSMauro Carvalho Chehab	Kbuild will only build host-programs when they are referenced
704cd238effSMauro Carvalho Chehab	as a prerequisite.
705cd238effSMauro Carvalho Chehab	This is possible in two ways:
706cd238effSMauro Carvalho Chehab
707cd238effSMauro Carvalho Chehab	(1) List the prerequisite explicitly in a special rule.
708cd238effSMauro Carvalho Chehab
709cd238effSMauro Carvalho Chehab	Example::
710cd238effSMauro Carvalho Chehab
711cd238effSMauro Carvalho Chehab		#drivers/pci/Makefile
7125f2fb52fSMasahiro Yamada		hostprogs := gen-devlist
713cd238effSMauro Carvalho Chehab		$(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
714cd238effSMauro Carvalho Chehab			( cd $(obj); ./gen-devlist ) < $<
715cd238effSMauro Carvalho Chehab
716cd238effSMauro Carvalho Chehab	The target $(obj)/devlist.h will not be built before
717cd238effSMauro Carvalho Chehab	$(obj)/gen-devlist is updated. Note that references to
718cd238effSMauro Carvalho Chehab	the host programs in special rules must be prefixed with $(obj).
719cd238effSMauro Carvalho Chehab
7205f2fb52fSMasahiro Yamada	(2) Use always-y
721cd238effSMauro Carvalho Chehab
722cd238effSMauro Carvalho Chehab	When there is no suitable special rule, and the host program
7235f2fb52fSMasahiro Yamada	shall be built when a makefile is entered, the always-y
724cd238effSMauro Carvalho Chehab	variable shall be used.
725cd238effSMauro Carvalho Chehab
726cd238effSMauro Carvalho Chehab	Example::
727cd238effSMauro Carvalho Chehab
728cd238effSMauro Carvalho Chehab		#scripts/lxdialog/Makefile
7295f2fb52fSMasahiro Yamada		hostprogs     := lxdialog
7305f2fb52fSMasahiro Yamada		always-y      := $(hostprogs)
731cd238effSMauro Carvalho Chehab
732cd238effSMauro Carvalho Chehab	This will tell kbuild to build lxdialog even if not referenced in
733cd238effSMauro Carvalho Chehab	any rule.
734cd238effSMauro Carvalho Chehab
735cd238effSMauro Carvalho Chehab5 Kbuild clean infrastructure
736cd238effSMauro Carvalho Chehab=============================
737cd238effSMauro Carvalho Chehab
738cd238effSMauro Carvalho Chehab"make clean" deletes most generated files in the obj tree where the kernel
739cd238effSMauro Carvalho Chehabis compiled. This includes generated files such as host programs.
7405f2fb52fSMasahiro YamadaKbuild knows targets listed in $(hostprogs), $(always-y), $(always-m),
7415f2fb52fSMasahiro Yamada$(always-), $(extra-y), $(extra-) and $(targets). They are all deleted
7425f2fb52fSMasahiro Yamadaduring "make clean". Files matching the patterns "*.[oas]", "*.ko", plus
7435f2fb52fSMasahiro Yamadasome additional files generated by kbuild are deleted all over the kernel
7445f2fb52fSMasahiro Yamadasource tree when "make clean" is executed.
745cd238effSMauro Carvalho Chehab
7461634f2bfSMasahiro YamadaAdditional files or directories can be specified in kbuild makefiles by use of
7471634f2bfSMasahiro Yamada$(clean-files).
748cd238effSMauro Carvalho Chehab
749cd238effSMauro Carvalho Chehab	Example::
750cd238effSMauro Carvalho Chehab
751cd238effSMauro Carvalho Chehab		#lib/Makefile
752cd238effSMauro Carvalho Chehab		clean-files := crc32table.h
753cd238effSMauro Carvalho Chehab
754cd238effSMauro Carvalho ChehabWhen executing "make clean", the file "crc32table.h" will be deleted.
755cd238effSMauro Carvalho ChehabKbuild will assume files to be in the same relative directory as the
756cd238effSMauro Carvalho ChehabMakefile, except if prefixed with $(objtree).
757cd238effSMauro Carvalho Chehab
7581634f2bfSMasahiro YamadaTo exclude certain files or directories from make clean, use the
7591634f2bfSMasahiro Yamada$(no-clean-files) variable.
760cd238effSMauro Carvalho Chehab
761cd238effSMauro Carvalho ChehabUsually kbuild descends down in subdirectories due to "obj-* := dir/",
762cd238effSMauro Carvalho Chehabbut in the architecture makefiles where the kbuild infrastructure
763cd238effSMauro Carvalho Chehabis not sufficient this sometimes needs to be explicit.
764cd238effSMauro Carvalho Chehab
765cd238effSMauro Carvalho Chehab	Example::
766cd238effSMauro Carvalho Chehab
767cd238effSMauro Carvalho Chehab		#arch/x86/boot/Makefile
768*eabc8bcbSMasahiro Yamada		subdir- := compressed
769cd238effSMauro Carvalho Chehab
770cd238effSMauro Carvalho ChehabThe above assignment instructs kbuild to descend down in the
771cd238effSMauro Carvalho Chehabdirectory compressed/ when "make clean" is executed.
772cd238effSMauro Carvalho Chehab
773cd238effSMauro Carvalho ChehabTo support the clean infrastructure in the Makefiles that build the
774cd238effSMauro Carvalho Chehabfinal bootimage there is an optional target named archclean:
775cd238effSMauro Carvalho Chehab
776cd238effSMauro Carvalho Chehab	Example::
777cd238effSMauro Carvalho Chehab
778cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
779cd238effSMauro Carvalho Chehab		archclean:
780cd238effSMauro Carvalho Chehab			$(Q)$(MAKE) $(clean)=arch/x86/boot
781cd238effSMauro Carvalho Chehab
782cd238effSMauro Carvalho ChehabWhen "make clean" is executed, make will descend down in arch/x86/boot,
783cd238effSMauro Carvalho Chehaband clean as usual. The Makefile located in arch/x86/boot/ may use
784cd238effSMauro Carvalho Chehabthe subdir- trick to descend further down.
785cd238effSMauro Carvalho Chehab
786cd238effSMauro Carvalho ChehabNote 1: arch/$(ARCH)/Makefile cannot use "subdir-", because that file is
787cd238effSMauro Carvalho Chehabincluded in the top level makefile, and the kbuild infrastructure
788cd238effSMauro Carvalho Chehabis not operational at that point.
789cd238effSMauro Carvalho Chehab
790cd238effSMauro Carvalho ChehabNote 2: All directories listed in core-y, libs-y, drivers-y and net-y will
791cd238effSMauro Carvalho Chehabbe visited during "make clean".
792cd238effSMauro Carvalho Chehab
793cd238effSMauro Carvalho Chehab6 Architecture Makefiles
794cd238effSMauro Carvalho Chehab========================
795cd238effSMauro Carvalho Chehab
796cd238effSMauro Carvalho ChehabThe top level Makefile sets up the environment and does the preparation,
797cd238effSMauro Carvalho Chehabbefore starting to descend down in the individual directories.
798cd238effSMauro Carvalho ChehabThe top level makefile contains the generic part, whereas
799cd238effSMauro Carvalho Chehabarch/$(ARCH)/Makefile contains what is required to set up kbuild
800cd238effSMauro Carvalho Chehabfor said architecture.
801cd238effSMauro Carvalho ChehabTo do so, arch/$(ARCH)/Makefile sets up a number of variables and defines
802cd238effSMauro Carvalho Chehaba few targets.
803cd238effSMauro Carvalho Chehab
804cd238effSMauro Carvalho ChehabWhen kbuild executes, the following steps are followed (roughly):
805cd238effSMauro Carvalho Chehab
806cd238effSMauro Carvalho Chehab1) Configuration of the kernel => produce .config
807cd238effSMauro Carvalho Chehab2) Store kernel version in include/linux/version.h
808cd238effSMauro Carvalho Chehab3) Updating all other prerequisites to the target prepare:
809cd238effSMauro Carvalho Chehab   - Additional prerequisites are specified in arch/$(ARCH)/Makefile
810cd238effSMauro Carvalho Chehab4) Recursively descend down in all directories listed in
811cd238effSMauro Carvalho Chehab   init-* core* drivers-* net-* libs-* and build all targets.
812cd238effSMauro Carvalho Chehab   - The values of the above variables are expanded in arch/$(ARCH)/Makefile.
813cd238effSMauro Carvalho Chehab5) All object files are then linked and the resulting file vmlinux is
814cd238effSMauro Carvalho Chehab   located at the root of the obj tree.
815cd238effSMauro Carvalho Chehab   The very first objects linked are listed in head-y, assigned by
816cd238effSMauro Carvalho Chehab   arch/$(ARCH)/Makefile.
817cd238effSMauro Carvalho Chehab6) Finally, the architecture-specific part does any required post processing
818cd238effSMauro Carvalho Chehab   and builds the final bootimage.
819cd238effSMauro Carvalho Chehab   - This includes building boot records
820cd238effSMauro Carvalho Chehab   - Preparing initrd images and the like
821cd238effSMauro Carvalho Chehab
822cd238effSMauro Carvalho Chehab
823cd238effSMauro Carvalho Chehab6.1 Set variables to tweak the build to the architecture
824cd238effSMauro Carvalho Chehab--------------------------------------------------------
825cd238effSMauro Carvalho Chehab
826cd238effSMauro Carvalho Chehab    LDFLAGS
827cd238effSMauro Carvalho Chehab	Generic $(LD) options
828cd238effSMauro Carvalho Chehab
829cd238effSMauro Carvalho Chehab	Flags used for all invocations of the linker.
830cd238effSMauro Carvalho Chehab	Often specifying the emulation is sufficient.
831cd238effSMauro Carvalho Chehab
832cd238effSMauro Carvalho Chehab	Example::
833cd238effSMauro Carvalho Chehab
834cd238effSMauro Carvalho Chehab		#arch/s390/Makefile
835cd238effSMauro Carvalho Chehab		LDFLAGS         := -m elf_s390
836cd238effSMauro Carvalho Chehab
837cd238effSMauro Carvalho Chehab	Note: ldflags-y can be used to further customise
838cd238effSMauro Carvalho Chehab	the flags used. See chapter 3.7.
839cd238effSMauro Carvalho Chehab
840cd238effSMauro Carvalho Chehab    LDFLAGS_vmlinux
841cd238effSMauro Carvalho Chehab	Options for $(LD) when linking vmlinux
842cd238effSMauro Carvalho Chehab
843cd238effSMauro Carvalho Chehab	LDFLAGS_vmlinux is used to specify additional flags to pass to
844cd238effSMauro Carvalho Chehab	the linker when linking the final vmlinux image.
845cd238effSMauro Carvalho Chehab	LDFLAGS_vmlinux uses the LDFLAGS_$@ support.
846cd238effSMauro Carvalho Chehab
847cd238effSMauro Carvalho Chehab	Example::
848cd238effSMauro Carvalho Chehab
849cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
850cd238effSMauro Carvalho Chehab		LDFLAGS_vmlinux := -e stext
851cd238effSMauro Carvalho Chehab
852cd238effSMauro Carvalho Chehab    OBJCOPYFLAGS
853cd238effSMauro Carvalho Chehab	objcopy flags
854cd238effSMauro Carvalho Chehab
855cd238effSMauro Carvalho Chehab	When $(call if_changed,objcopy) is used to translate a .o file,
856cd238effSMauro Carvalho Chehab	the flags specified in OBJCOPYFLAGS will be used.
857cd238effSMauro Carvalho Chehab	$(call if_changed,objcopy) is often used to generate raw binaries on
858cd238effSMauro Carvalho Chehab	vmlinux.
859cd238effSMauro Carvalho Chehab
860cd238effSMauro Carvalho Chehab	Example::
861cd238effSMauro Carvalho Chehab
862cd238effSMauro Carvalho Chehab		#arch/s390/Makefile
863cd238effSMauro Carvalho Chehab		OBJCOPYFLAGS := -O binary
864cd238effSMauro Carvalho Chehab
865cd238effSMauro Carvalho Chehab		#arch/s390/boot/Makefile
866cd238effSMauro Carvalho Chehab		$(obj)/image: vmlinux FORCE
867cd238effSMauro Carvalho Chehab			$(call if_changed,objcopy)
868cd238effSMauro Carvalho Chehab
869cd238effSMauro Carvalho Chehab	In this example, the binary $(obj)/image is a binary version of
870cd238effSMauro Carvalho Chehab	vmlinux. The usage of $(call if_changed,xxx) will be described later.
871cd238effSMauro Carvalho Chehab
872cd238effSMauro Carvalho Chehab    KBUILD_AFLAGS
8735ef87263SMasahiro Yamada	Assembler flags
874cd238effSMauro Carvalho Chehab
875cd238effSMauro Carvalho Chehab	Default value - see top level Makefile
876cd238effSMauro Carvalho Chehab	Append or modify as required per architecture.
877cd238effSMauro Carvalho Chehab
878cd238effSMauro Carvalho Chehab	Example::
879cd238effSMauro Carvalho Chehab
880cd238effSMauro Carvalho Chehab		#arch/sparc64/Makefile
881cd238effSMauro Carvalho Chehab		KBUILD_AFLAGS += -m64 -mcpu=ultrasparc
882cd238effSMauro Carvalho Chehab
883cd238effSMauro Carvalho Chehab    KBUILD_CFLAGS
884cd238effSMauro Carvalho Chehab	$(CC) compiler flags
885cd238effSMauro Carvalho Chehab
886cd238effSMauro Carvalho Chehab	Default value - see top level Makefile
887cd238effSMauro Carvalho Chehab	Append or modify as required per architecture.
888cd238effSMauro Carvalho Chehab
889cd238effSMauro Carvalho Chehab	Often, the KBUILD_CFLAGS variable depends on the configuration.
890cd238effSMauro Carvalho Chehab
891cd238effSMauro Carvalho Chehab	Example::
892cd238effSMauro Carvalho Chehab
893cd238effSMauro Carvalho Chehab		#arch/x86/boot/compressed/Makefile
894cd238effSMauro Carvalho Chehab		cflags-$(CONFIG_X86_32) := -march=i386
895cd238effSMauro Carvalho Chehab		cflags-$(CONFIG_X86_64) := -mcmodel=small
896cd238effSMauro Carvalho Chehab		KBUILD_CFLAGS += $(cflags-y)
897cd238effSMauro Carvalho Chehab
898cd238effSMauro Carvalho Chehab	Many arch Makefiles dynamically run the target C compiler to
899cd238effSMauro Carvalho Chehab	probe supported options::
900cd238effSMauro Carvalho Chehab
901cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
902cd238effSMauro Carvalho Chehab
903cd238effSMauro Carvalho Chehab		...
904cd238effSMauro Carvalho Chehab		cflags-$(CONFIG_MPENTIUMII)     += $(call cc-option,\
905cd238effSMauro Carvalho Chehab						-march=pentium2,-march=i686)
906cd238effSMauro Carvalho Chehab		...
907cd238effSMauro Carvalho Chehab		# Disable unit-at-a-time mode ...
908cd238effSMauro Carvalho Chehab		KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time)
909cd238effSMauro Carvalho Chehab		...
910cd238effSMauro Carvalho Chehab
911cd238effSMauro Carvalho Chehab
912cd238effSMauro Carvalho Chehab	The first example utilises the trick that a config option expands
913cd238effSMauro Carvalho Chehab	to 'y' when selected.
914cd238effSMauro Carvalho Chehab
915cd238effSMauro Carvalho Chehab    KBUILD_AFLAGS_KERNEL
9165ef87263SMasahiro Yamada	Assembler options specific for built-in
917cd238effSMauro Carvalho Chehab
918cd238effSMauro Carvalho Chehab	$(KBUILD_AFLAGS_KERNEL) contains extra C compiler flags used to compile
919cd238effSMauro Carvalho Chehab	resident kernel code.
920cd238effSMauro Carvalho Chehab
921cd238effSMauro Carvalho Chehab    KBUILD_AFLAGS_MODULE
9225ef87263SMasahiro Yamada	Assembler options specific for modules
923cd238effSMauro Carvalho Chehab
924cd238effSMauro Carvalho Chehab	$(KBUILD_AFLAGS_MODULE) is used to add arch-specific options that
9255ef87263SMasahiro Yamada	are used for assembler.
926cd238effSMauro Carvalho Chehab
927cd238effSMauro Carvalho Chehab	From commandline AFLAGS_MODULE shall be used (see kbuild.txt).
928cd238effSMauro Carvalho Chehab
929cd238effSMauro Carvalho Chehab    KBUILD_CFLAGS_KERNEL
930cd238effSMauro Carvalho Chehab	$(CC) options specific for built-in
931cd238effSMauro Carvalho Chehab
932cd238effSMauro Carvalho Chehab	$(KBUILD_CFLAGS_KERNEL) contains extra C compiler flags used to compile
933cd238effSMauro Carvalho Chehab	resident kernel code.
934cd238effSMauro Carvalho Chehab
935cd238effSMauro Carvalho Chehab    KBUILD_CFLAGS_MODULE
936cd238effSMauro Carvalho Chehab	Options for $(CC) when building modules
937cd238effSMauro Carvalho Chehab
938cd238effSMauro Carvalho Chehab	$(KBUILD_CFLAGS_MODULE) is used to add arch-specific options that
939cd238effSMauro Carvalho Chehab	are used for $(CC).
940cd238effSMauro Carvalho Chehab	From commandline CFLAGS_MODULE shall be used (see kbuild.txt).
941cd238effSMauro Carvalho Chehab
942cd238effSMauro Carvalho Chehab    KBUILD_LDFLAGS_MODULE
943cd238effSMauro Carvalho Chehab	Options for $(LD) when linking modules
944cd238effSMauro Carvalho Chehab
945cd238effSMauro Carvalho Chehab	$(KBUILD_LDFLAGS_MODULE) is used to add arch-specific options
946cd238effSMauro Carvalho Chehab	used when linking modules. This is often a linker script.
947cd238effSMauro Carvalho Chehab
948cd238effSMauro Carvalho Chehab	From commandline LDFLAGS_MODULE shall be used (see kbuild.txt).
949cd238effSMauro Carvalho Chehab
950888f0c34SMasahiro Yamada    KBUILD_LDS
951888f0c34SMasahiro Yamada
952888f0c34SMasahiro Yamada	The linker script with full path. Assigned by the top-level Makefile.
953888f0c34SMasahiro Yamada
95410df0638SMasahiro Yamada    KBUILD_LDS_MODULE
95510df0638SMasahiro Yamada
95610df0638SMasahiro Yamada	The module linker script with full path. Assigned by the top-level
95710df0638SMasahiro Yamada	Makefile and additionally by the arch Makefile.
95810df0638SMasahiro Yamada
959888f0c34SMasahiro Yamada    KBUILD_VMLINUX_OBJS
960888f0c34SMasahiro Yamada
961888f0c34SMasahiro Yamada	All object files for vmlinux. They are linked to vmlinux in the same
962888f0c34SMasahiro Yamada	order as listed in KBUILD_VMLINUX_OBJS.
963888f0c34SMasahiro Yamada
964888f0c34SMasahiro Yamada    KBUILD_VMLINUX_LIBS
965888f0c34SMasahiro Yamada
966888f0c34SMasahiro Yamada	All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and
967888f0c34SMasahiro Yamada	KBUILD_VMLINUX_LIBS together specify all the object files used to
968888f0c34SMasahiro Yamada	link vmlinux.
969cd238effSMauro Carvalho Chehab
970cd238effSMauro Carvalho Chehab6.2 Add prerequisites to archheaders
971cd238effSMauro Carvalho Chehab------------------------------------
972cd238effSMauro Carvalho Chehab
973cd238effSMauro Carvalho Chehab	The archheaders: rule is used to generate header files that
97439ceda5cSLinus Torvalds	may be installed into user space by "make header_install".
975cd238effSMauro Carvalho Chehab
976cd238effSMauro Carvalho Chehab	It is run before "make archprepare" when run on the
977cd238effSMauro Carvalho Chehab	architecture itself.
978cd238effSMauro Carvalho Chehab
979cd238effSMauro Carvalho Chehab
980cd238effSMauro Carvalho Chehab6.3 Add prerequisites to archprepare
981cd238effSMauro Carvalho Chehab------------------------------------
982cd238effSMauro Carvalho Chehab
983cd238effSMauro Carvalho Chehab	The archprepare: rule is used to list prerequisites that need to be
984cd238effSMauro Carvalho Chehab	built before starting to descend down in the subdirectories.
985cd238effSMauro Carvalho Chehab	This is usually used for header files containing assembler constants.
986cd238effSMauro Carvalho Chehab
987cd238effSMauro Carvalho Chehab	Example::
988cd238effSMauro Carvalho Chehab
989cd238effSMauro Carvalho Chehab		#arch/arm/Makefile
990cd238effSMauro Carvalho Chehab		archprepare: maketools
991cd238effSMauro Carvalho Chehab
992cd238effSMauro Carvalho Chehab	In this example, the file target maketools will be processed
993cd238effSMauro Carvalho Chehab	before descending down in the subdirectories.
994cd238effSMauro Carvalho Chehab	See also chapter XXX-TODO that describe how kbuild supports
995cd238effSMauro Carvalho Chehab	generating offset header files.
996cd238effSMauro Carvalho Chehab
997cd238effSMauro Carvalho Chehab
998cd238effSMauro Carvalho Chehab6.4 List directories to visit when descending
999cd238effSMauro Carvalho Chehab---------------------------------------------
1000cd238effSMauro Carvalho Chehab
1001cd238effSMauro Carvalho Chehab	An arch Makefile cooperates with the top Makefile to define variables
1002cd238effSMauro Carvalho Chehab	which specify how to build the vmlinux file.  Note that there is no
1003cd238effSMauro Carvalho Chehab	corresponding arch-specific section for modules; the module-building
1004cd238effSMauro Carvalho Chehab	machinery is all architecture-independent.
1005cd238effSMauro Carvalho Chehab
1006cd238effSMauro Carvalho Chehab
1007cd238effSMauro Carvalho Chehab	head-y, init-y, core-y, libs-y, drivers-y, net-y
1008cd238effSMauro Carvalho Chehab	    $(head-y) lists objects to be linked first in vmlinux.
1009cd238effSMauro Carvalho Chehab
1010cd238effSMauro Carvalho Chehab	    $(libs-y) lists directories where a lib.a archive can be located.
1011cd238effSMauro Carvalho Chehab
1012cd238effSMauro Carvalho Chehab	    The rest list directories where a built-in.a object file can be
1013cd238effSMauro Carvalho Chehab	    located.
1014cd238effSMauro Carvalho Chehab
1015cd238effSMauro Carvalho Chehab	    $(init-y) objects will be located after $(head-y).
1016cd238effSMauro Carvalho Chehab
1017cd238effSMauro Carvalho Chehab	    Then the rest follows in this order:
1018cd238effSMauro Carvalho Chehab
1019cd238effSMauro Carvalho Chehab		$(core-y), $(libs-y), $(drivers-y) and $(net-y).
1020cd238effSMauro Carvalho Chehab
1021cd238effSMauro Carvalho Chehab	    The top level Makefile defines values for all generic directories,
1022cd238effSMauro Carvalho Chehab	    and arch/$(ARCH)/Makefile only adds architecture-specific
1023cd238effSMauro Carvalho Chehab	    directories.
1024cd238effSMauro Carvalho Chehab
1025cd238effSMauro Carvalho Chehab	    Example::
1026cd238effSMauro Carvalho Chehab
1027cd238effSMauro Carvalho Chehab		#arch/sparc64/Makefile
1028cd238effSMauro Carvalho Chehab		core-y += arch/sparc64/kernel/
1029cd238effSMauro Carvalho Chehab		libs-y += arch/sparc64/prom/ arch/sparc64/lib/
1030cd238effSMauro Carvalho Chehab		drivers-$(CONFIG_OPROFILE)  += arch/sparc64/oprofile/
1031cd238effSMauro Carvalho Chehab
1032cd238effSMauro Carvalho Chehab
1033cd238effSMauro Carvalho Chehab6.5 Architecture-specific boot images
1034cd238effSMauro Carvalho Chehab-------------------------------------
1035cd238effSMauro Carvalho Chehab
1036cd238effSMauro Carvalho Chehab	An arch Makefile specifies goals that take the vmlinux file, compress
1037cd238effSMauro Carvalho Chehab	it, wrap it in bootstrapping code, and copy the resulting files
1038cd238effSMauro Carvalho Chehab	somewhere. This includes various kinds of installation commands.
1039cd238effSMauro Carvalho Chehab	The actual goals are not standardized across architectures.
1040cd238effSMauro Carvalho Chehab
1041cd238effSMauro Carvalho Chehab	It is common to locate any additional processing in a boot/
1042cd238effSMauro Carvalho Chehab	directory below arch/$(ARCH)/.
1043cd238effSMauro Carvalho Chehab
1044cd238effSMauro Carvalho Chehab	Kbuild does not provide any smart way to support building a
1045cd238effSMauro Carvalho Chehab	target specified in boot/. Therefore arch/$(ARCH)/Makefile shall
1046cd238effSMauro Carvalho Chehab	call make manually to build a target in boot/.
1047cd238effSMauro Carvalho Chehab
1048cd238effSMauro Carvalho Chehab	The recommended approach is to include shortcuts in
1049cd238effSMauro Carvalho Chehab	arch/$(ARCH)/Makefile, and use the full path when calling down
1050cd238effSMauro Carvalho Chehab	into the arch/$(ARCH)/boot/Makefile.
1051cd238effSMauro Carvalho Chehab
1052cd238effSMauro Carvalho Chehab	Example::
1053cd238effSMauro Carvalho Chehab
1054cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
1055cd238effSMauro Carvalho Chehab		boot := arch/x86/boot
1056cd238effSMauro Carvalho Chehab		bzImage: vmlinux
1057cd238effSMauro Carvalho Chehab			$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
1058cd238effSMauro Carvalho Chehab
1059cd238effSMauro Carvalho Chehab	"$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke
1060cd238effSMauro Carvalho Chehab	make in a subdirectory.
1061cd238effSMauro Carvalho Chehab
1062cd238effSMauro Carvalho Chehab	There are no rules for naming architecture-specific targets,
1063cd238effSMauro Carvalho Chehab	but executing "make help" will list all relevant targets.
1064cd238effSMauro Carvalho Chehab	To support this, $(archhelp) must be defined.
1065cd238effSMauro Carvalho Chehab
1066cd238effSMauro Carvalho Chehab	Example::
1067cd238effSMauro Carvalho Chehab
1068cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
1069cd238effSMauro Carvalho Chehab		define archhelp
1070cd238effSMauro Carvalho Chehab		  echo  '* bzImage      - Image (arch/$(ARCH)/boot/bzImage)'
1071cd238effSMauro Carvalho Chehab		endif
1072cd238effSMauro Carvalho Chehab
1073cd238effSMauro Carvalho Chehab	When make is executed without arguments, the first goal encountered
1074cd238effSMauro Carvalho Chehab	will be built. In the top level Makefile the first goal present
1075cd238effSMauro Carvalho Chehab	is all:.
1076cd238effSMauro Carvalho Chehab	An architecture shall always, per default, build a bootable image.
1077cd238effSMauro Carvalho Chehab	In "make help", the default goal is highlighted with a '*'.
1078cd238effSMauro Carvalho Chehab	Add a new prerequisite to all: to select a default goal different
1079cd238effSMauro Carvalho Chehab	from vmlinux.
1080cd238effSMauro Carvalho Chehab
1081cd238effSMauro Carvalho Chehab	Example::
1082cd238effSMauro Carvalho Chehab
1083cd238effSMauro Carvalho Chehab		#arch/x86/Makefile
1084cd238effSMauro Carvalho Chehab		all: bzImage
1085cd238effSMauro Carvalho Chehab
1086cd238effSMauro Carvalho Chehab	When "make" is executed without arguments, bzImage will be built.
1087cd238effSMauro Carvalho Chehab
1088cd238effSMauro Carvalho Chehab6.6 Building non-kbuild targets
1089cd238effSMauro Carvalho Chehab-------------------------------
1090cd238effSMauro Carvalho Chehab
1091cd238effSMauro Carvalho Chehab    extra-y
1092cd238effSMauro Carvalho Chehab	extra-y specifies additional targets created in the current
1093cd238effSMauro Carvalho Chehab	directory, in addition to any targets specified by `obj-*`.
1094cd238effSMauro Carvalho Chehab
1095cd238effSMauro Carvalho Chehab	Listing all targets in extra-y is required for two purposes:
1096cd238effSMauro Carvalho Chehab
1097cd238effSMauro Carvalho Chehab	1) Enable kbuild to check changes in command lines
1098cd238effSMauro Carvalho Chehab
1099cd238effSMauro Carvalho Chehab	   - When $(call if_changed,xxx) is used
1100cd238effSMauro Carvalho Chehab
1101cd238effSMauro Carvalho Chehab	2) kbuild knows what files to delete during "make clean"
1102cd238effSMauro Carvalho Chehab
1103cd238effSMauro Carvalho Chehab	Example::
1104cd238effSMauro Carvalho Chehab
1105cd238effSMauro Carvalho Chehab		#arch/x86/kernel/Makefile
1106cd238effSMauro Carvalho Chehab		extra-y := head.o init_task.o
1107cd238effSMauro Carvalho Chehab
1108cd238effSMauro Carvalho Chehab	In this example, extra-y is used to list object files that
1109cd238effSMauro Carvalho Chehab	shall be built, but shall not be linked as part of built-in.a.
1110cd238effSMauro Carvalho Chehab
1111cd238effSMauro Carvalho Chehab6.7 Commands useful for building a boot image
1112cd238effSMauro Carvalho Chehab---------------------------------------------
1113cd238effSMauro Carvalho Chehab
1114cd238effSMauro Carvalho Chehab    Kbuild provides a few macros that are useful when building a
1115cd238effSMauro Carvalho Chehab    boot image.
1116cd238effSMauro Carvalho Chehab
1117cd238effSMauro Carvalho Chehab    if_changed
1118cd238effSMauro Carvalho Chehab	if_changed is the infrastructure used for the following commands.
1119cd238effSMauro Carvalho Chehab
1120cd238effSMauro Carvalho Chehab	Usage::
1121cd238effSMauro Carvalho Chehab
1122cd238effSMauro Carvalho Chehab		target: source(s) FORCE
1123cd238effSMauro Carvalho Chehab			$(call if_changed,ld/objcopy/gzip/...)
1124cd238effSMauro Carvalho Chehab
1125cd238effSMauro Carvalho Chehab	When the rule is evaluated, it is checked to see if any files
1126cd238effSMauro Carvalho Chehab	need an update, or the command line has changed since the last
1127cd238effSMauro Carvalho Chehab	invocation. The latter will force a rebuild if any options
1128cd238effSMauro Carvalho Chehab	to the executable have changed.
1129cd238effSMauro Carvalho Chehab	Any target that utilises if_changed must be listed in $(targets),
1130cd238effSMauro Carvalho Chehab	otherwise the command line check will fail, and the target will
1131cd238effSMauro Carvalho Chehab	always be built.
1132cd238effSMauro Carvalho Chehab	Assignments to $(targets) are without $(obj)/ prefix.
1133cd238effSMauro Carvalho Chehab	if_changed may be used in conjunction with custom commands as
1134cd238effSMauro Carvalho Chehab	defined in 6.8 "Custom kbuild commands".
1135cd238effSMauro Carvalho Chehab
1136cd238effSMauro Carvalho Chehab	Note: It is a typical mistake to forget the FORCE prerequisite.
1137cd238effSMauro Carvalho Chehab	Another common pitfall is that whitespace is sometimes
1138cd238effSMauro Carvalho Chehab	significant; for instance, the below will fail (note the extra space
1139cd238effSMauro Carvalho Chehab	after the comma)::
1140cd238effSMauro Carvalho Chehab
1141cd238effSMauro Carvalho Chehab		target: source(s) FORCE
1142cd238effSMauro Carvalho Chehab
1143cd238effSMauro Carvalho Chehab	**WRONG!**	$(call if_changed, ld/objcopy/gzip/...)
1144cd238effSMauro Carvalho Chehab
1145cd238effSMauro Carvalho Chehab        Note:
1146cd238effSMauro Carvalho Chehab	      if_changed should not be used more than once per target.
1147cd238effSMauro Carvalho Chehab              It stores the executed command in a corresponding .cmd
1148cd238effSMauro Carvalho Chehab
1149cd238effSMauro Carvalho Chehab        file and multiple calls would result in overwrites and
1150cd238effSMauro Carvalho Chehab        unwanted results when the target is up to date and only the
1151cd238effSMauro Carvalho Chehab        tests on changed commands trigger execution of commands.
1152cd238effSMauro Carvalho Chehab
1153cd238effSMauro Carvalho Chehab    ld
1154cd238effSMauro Carvalho Chehab	Link target. Often, LDFLAGS_$@ is used to set specific options to ld.
1155cd238effSMauro Carvalho Chehab
1156cd238effSMauro Carvalho Chehab	Example::
1157cd238effSMauro Carvalho Chehab
1158cd238effSMauro Carvalho Chehab		#arch/x86/boot/Makefile
1159cd238effSMauro Carvalho Chehab		LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary
1160cd238effSMauro Carvalho Chehab		LDFLAGS_setup    := -Ttext 0x0 -s --oformat binary -e begtext
1161cd238effSMauro Carvalho Chehab
1162cd238effSMauro Carvalho Chehab		targets += setup setup.o bootsect bootsect.o
1163cd238effSMauro Carvalho Chehab		$(obj)/setup $(obj)/bootsect: %: %.o FORCE
1164cd238effSMauro Carvalho Chehab			$(call if_changed,ld)
1165cd238effSMauro Carvalho Chehab
1166cd238effSMauro Carvalho Chehab	In this example, there are two possible targets, requiring different
1167cd238effSMauro Carvalho Chehab	options to the linker. The linker options are specified using the
1168cd238effSMauro Carvalho Chehab	LDFLAGS_$@ syntax - one for each potential target.
1169cd238effSMauro Carvalho Chehab	$(targets) are assigned all potential targets, by which kbuild knows
1170cd238effSMauro Carvalho Chehab	the targets and will:
1171cd238effSMauro Carvalho Chehab
1172cd238effSMauro Carvalho Chehab		1) check for commandline changes
1173cd238effSMauro Carvalho Chehab		2) delete target during make clean
1174cd238effSMauro Carvalho Chehab
1175cd238effSMauro Carvalho Chehab	The ": %: %.o" part of the prerequisite is a shorthand that
1176cd238effSMauro Carvalho Chehab	frees us from listing the setup.o and bootsect.o files.
1177cd238effSMauro Carvalho Chehab
1178cd238effSMauro Carvalho Chehab	Note:
1179cd238effSMauro Carvalho Chehab	      It is a common mistake to forget the "targets :=" assignment,
1180cd238effSMauro Carvalho Chehab	      resulting in the target file being recompiled for no
1181cd238effSMauro Carvalho Chehab	      obvious reason.
1182cd238effSMauro Carvalho Chehab
1183cd238effSMauro Carvalho Chehab    objcopy
1184cd238effSMauro Carvalho Chehab	Copy binary. Uses OBJCOPYFLAGS usually specified in
1185cd238effSMauro Carvalho Chehab	arch/$(ARCH)/Makefile.
1186cd238effSMauro Carvalho Chehab	OBJCOPYFLAGS_$@ may be used to set additional options.
1187cd238effSMauro Carvalho Chehab
1188cd238effSMauro Carvalho Chehab    gzip
1189cd238effSMauro Carvalho Chehab	Compress target. Use maximum compression to compress target.
1190cd238effSMauro Carvalho Chehab
1191cd238effSMauro Carvalho Chehab	Example::
1192cd238effSMauro Carvalho Chehab
1193cd238effSMauro Carvalho Chehab		#arch/x86/boot/compressed/Makefile
1194cd238effSMauro Carvalho Chehab		$(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
1195cd238effSMauro Carvalho Chehab			$(call if_changed,gzip)
1196cd238effSMauro Carvalho Chehab
1197cd238effSMauro Carvalho Chehab    dtc
1198cd238effSMauro Carvalho Chehab	Create flattened device tree blob object suitable for linking
1199cd238effSMauro Carvalho Chehab	into vmlinux. Device tree blobs linked into vmlinux are placed
1200cd238effSMauro Carvalho Chehab	in an init section in the image. Platform code *must* copy the
1201cd238effSMauro Carvalho Chehab	blob to non-init memory prior to calling unflatten_device_tree().
1202cd238effSMauro Carvalho Chehab
1203cd238effSMauro Carvalho Chehab	To use this command, simply add `*.dtb` into obj-y or targets, or make
1204cd238effSMauro Carvalho Chehab	some other target depend on `%.dtb`
1205cd238effSMauro Carvalho Chehab
1206cd238effSMauro Carvalho Chehab	A central rule exists to create `$(obj)/%.dtb` from `$(src)/%.dts`;
1207cd238effSMauro Carvalho Chehab	architecture Makefiles do no need to explicitly write out that rule.
1208cd238effSMauro Carvalho Chehab
1209cd238effSMauro Carvalho Chehab	Example::
1210cd238effSMauro Carvalho Chehab
1211cd238effSMauro Carvalho Chehab		targets += $(dtb-y)
1212cd238effSMauro Carvalho Chehab		DTC_FLAGS ?= -p 1024
1213cd238effSMauro Carvalho Chehab
1214cd238effSMauro Carvalho Chehab6.8 Custom kbuild commands
1215cd238effSMauro Carvalho Chehab--------------------------
1216cd238effSMauro Carvalho Chehab
1217cd238effSMauro Carvalho Chehab	When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
1218cd238effSMauro Carvalho Chehab	of a command is normally displayed.
1219cd238effSMauro Carvalho Chehab	To enable this behaviour for custom commands kbuild requires
1220cd238effSMauro Carvalho Chehab	two variables to be set::
1221cd238effSMauro Carvalho Chehab
1222cd238effSMauro Carvalho Chehab		quiet_cmd_<command>	- what shall be echoed
1223cd238effSMauro Carvalho Chehab		      cmd_<command>	- the command to execute
1224cd238effSMauro Carvalho Chehab
1225cd238effSMauro Carvalho Chehab	Example::
1226cd238effSMauro Carvalho Chehab
1227cd238effSMauro Carvalho Chehab		#
1228cd238effSMauro Carvalho Chehab		quiet_cmd_image = BUILD   $@
1229cd238effSMauro Carvalho Chehab		      cmd_image = $(obj)/tools/build $(BUILDFLAGS) \
1230cd238effSMauro Carvalho Chehab		                                     $(obj)/vmlinux.bin > $@
1231cd238effSMauro Carvalho Chehab
1232cd238effSMauro Carvalho Chehab		targets += bzImage
1233cd238effSMauro Carvalho Chehab		$(obj)/bzImage: $(obj)/vmlinux.bin $(obj)/tools/build FORCE
1234cd238effSMauro Carvalho Chehab			$(call if_changed,image)
1235cd238effSMauro Carvalho Chehab			@echo 'Kernel: $@ is ready'
1236cd238effSMauro Carvalho Chehab
1237cd238effSMauro Carvalho Chehab	When updating the $(obj)/bzImage target, the line:
1238cd238effSMauro Carvalho Chehab
1239cd238effSMauro Carvalho Chehab		BUILD    arch/x86/boot/bzImage
1240cd238effSMauro Carvalho Chehab
1241cd238effSMauro Carvalho Chehab	will be displayed with "make KBUILD_VERBOSE=0".
1242cd238effSMauro Carvalho Chehab
1243cd238effSMauro Carvalho Chehab
1244cd238effSMauro Carvalho Chehab--- 6.9 Preprocessing linker scripts
1245cd238effSMauro Carvalho Chehab
1246cd238effSMauro Carvalho Chehab	When the vmlinux image is built, the linker script
1247cd238effSMauro Carvalho Chehab	arch/$(ARCH)/kernel/vmlinux.lds is used.
1248cd238effSMauro Carvalho Chehab	The script is a preprocessed variant of the file vmlinux.lds.S
1249cd238effSMauro Carvalho Chehab	located in the same directory.
1250cd238effSMauro Carvalho Chehab	kbuild knows .lds files and includes a rule `*lds.S` -> `*lds`.
1251cd238effSMauro Carvalho Chehab
1252cd238effSMauro Carvalho Chehab	Example::
1253cd238effSMauro Carvalho Chehab
1254cd238effSMauro Carvalho Chehab		#arch/x86/kernel/Makefile
1255faa7bdd7SMasahiro Yamada		extra-y := vmlinux.lds
1256cd238effSMauro Carvalho Chehab
1257cd238effSMauro Carvalho Chehab		#Makefile
1258cd238effSMauro Carvalho Chehab		export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
1259cd238effSMauro Carvalho Chehab
1260faa7bdd7SMasahiro Yamada	The assignment to extra-y is used to tell kbuild to build the
1261cd238effSMauro Carvalho Chehab	target vmlinux.lds.
1262cd238effSMauro Carvalho Chehab	The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the
1263cd238effSMauro Carvalho Chehab	specified options when building the target vmlinux.lds.
1264cd238effSMauro Carvalho Chehab
1265cd238effSMauro Carvalho Chehab	When building the `*.lds` target, kbuild uses the variables::
1266cd238effSMauro Carvalho Chehab
1267cd238effSMauro Carvalho Chehab		KBUILD_CPPFLAGS	: Set in top-level Makefile
1268cd238effSMauro Carvalho Chehab		cppflags-y	: May be set in the kbuild makefile
1269cd238effSMauro Carvalho Chehab		CPPFLAGS_$(@F)  : Target-specific flags.
1270cd238effSMauro Carvalho Chehab				Note that the full filename is used in this
1271cd238effSMauro Carvalho Chehab				assignment.
1272cd238effSMauro Carvalho Chehab
1273cd238effSMauro Carvalho Chehab	The kbuild infrastructure for `*lds` files is used in several
1274cd238effSMauro Carvalho Chehab	architecture-specific files.
1275cd238effSMauro Carvalho Chehab
1276cd238effSMauro Carvalho Chehab6.10 Generic header files
1277cd238effSMauro Carvalho Chehab-------------------------
1278cd238effSMauro Carvalho Chehab
1279cd238effSMauro Carvalho Chehab	The directory include/asm-generic contains the header files
1280cd238effSMauro Carvalho Chehab	that may be shared between individual architectures.
1281cd238effSMauro Carvalho Chehab	The recommended approach how to use a generic header file is
1282cd238effSMauro Carvalho Chehab	to list the file in the Kbuild file.
1283cd238effSMauro Carvalho Chehab	See "7.2 generic-y" for further info on syntax etc.
1284cd238effSMauro Carvalho Chehab
1285cd238effSMauro Carvalho Chehab6.11 Post-link pass
1286cd238effSMauro Carvalho Chehab-------------------
1287cd238effSMauro Carvalho Chehab
1288cd238effSMauro Carvalho Chehab	If the file arch/xxx/Makefile.postlink exists, this makefile
1289cd238effSMauro Carvalho Chehab	will be invoked for post-link objects (vmlinux and modules.ko)
1290cd238effSMauro Carvalho Chehab	for architectures to run post-link passes on. Must also handle
1291cd238effSMauro Carvalho Chehab	the clean target.
1292cd238effSMauro Carvalho Chehab
1293cd238effSMauro Carvalho Chehab	This pass runs after kallsyms generation. If the architecture
1294cd238effSMauro Carvalho Chehab	needs to modify symbol locations, rather than manipulate the
1295cd238effSMauro Carvalho Chehab	kallsyms, it may be easier to add another postlink target for
1296cd238effSMauro Carvalho Chehab	.tmp_vmlinux? targets to be called from link-vmlinux.sh.
1297cd238effSMauro Carvalho Chehab
1298cd238effSMauro Carvalho Chehab	For example, powerpc uses this to check relocation sanity of
1299cd238effSMauro Carvalho Chehab	the linked vmlinux file.
1300cd238effSMauro Carvalho Chehab
1301cd238effSMauro Carvalho Chehab7 Kbuild syntax for exported headers
1302cd238effSMauro Carvalho Chehab------------------------------------
1303cd238effSMauro Carvalho Chehab
1304cd238effSMauro Carvalho ChehabThe kernel includes a set of headers that is exported to userspace.
1305cd238effSMauro Carvalho ChehabMany headers can be exported as-is but other headers require a
1306cd238effSMauro Carvalho Chehabminimal pre-processing before they are ready for user-space.
1307cd238effSMauro Carvalho ChehabThe pre-processing does:
1308cd238effSMauro Carvalho Chehab
1309cd238effSMauro Carvalho Chehab- drop kernel-specific annotations
1310cd238effSMauro Carvalho Chehab- drop include of compiler.h
1311cd238effSMauro Carvalho Chehab- drop all sections that are kernel internal (guarded by `ifdef __KERNEL__`)
1312cd238effSMauro Carvalho Chehab
1313cd238effSMauro Carvalho ChehabAll headers under include/uapi/, include/generated/uapi/,
1314cd238effSMauro Carvalho Chehabarch/<arch>/include/uapi/ and arch/<arch>/include/generated/uapi/
1315cd238effSMauro Carvalho Chehabare exported.
1316cd238effSMauro Carvalho Chehab
1317cd238effSMauro Carvalho ChehabA Kbuild file may be defined under arch/<arch>/include/uapi/asm/ and
1318cd238effSMauro Carvalho Chehabarch/<arch>/include/asm/ to list asm files coming from asm-generic.
1319cd238effSMauro Carvalho ChehabSee subsequent chapter for the syntax of the Kbuild file.
1320cd238effSMauro Carvalho Chehab
1321cd238effSMauro Carvalho Chehab7.1 no-export-headers
1322cd238effSMauro Carvalho Chehab---------------------
1323cd238effSMauro Carvalho Chehab
1324cd238effSMauro Carvalho Chehab	no-export-headers is essentially used by include/uapi/linux/Kbuild to
1325cd238effSMauro Carvalho Chehab	avoid exporting specific headers (e.g. kvm.h) on architectures that do
1326cd238effSMauro Carvalho Chehab	not support it. It should be avoided as much as possible.
1327cd238effSMauro Carvalho Chehab
1328cd238effSMauro Carvalho Chehab7.2 generic-y
1329cd238effSMauro Carvalho Chehab-------------
1330cd238effSMauro Carvalho Chehab
1331cd238effSMauro Carvalho Chehab	If an architecture uses a verbatim copy of a header from
1332cd238effSMauro Carvalho Chehab	include/asm-generic then this is listed in the file
1333cd238effSMauro Carvalho Chehab	arch/$(ARCH)/include/asm/Kbuild like this:
1334cd238effSMauro Carvalho Chehab
1335cd238effSMauro Carvalho Chehab		Example::
1336cd238effSMauro Carvalho Chehab
1337cd238effSMauro Carvalho Chehab			#arch/x86/include/asm/Kbuild
1338cd238effSMauro Carvalho Chehab			generic-y += termios.h
1339cd238effSMauro Carvalho Chehab			generic-y += rtc.h
1340cd238effSMauro Carvalho Chehab
1341cd238effSMauro Carvalho Chehab	During the prepare phase of the build a wrapper include
1342cd238effSMauro Carvalho Chehab	file is generated in the directory::
1343cd238effSMauro Carvalho Chehab
1344cd238effSMauro Carvalho Chehab		arch/$(ARCH)/include/generated/asm
1345cd238effSMauro Carvalho Chehab
1346cd238effSMauro Carvalho Chehab	When a header is exported where the architecture uses
1347cd238effSMauro Carvalho Chehab	the generic header a similar wrapper is generated as part
1348cd238effSMauro Carvalho Chehab	of the set of exported headers in the directory::
1349cd238effSMauro Carvalho Chehab
1350cd238effSMauro Carvalho Chehab		usr/include/asm
1351cd238effSMauro Carvalho Chehab
1352cd238effSMauro Carvalho Chehab	The generated wrapper will in both cases look like the following:
1353cd238effSMauro Carvalho Chehab
1354cd238effSMauro Carvalho Chehab		Example: termios.h::
1355cd238effSMauro Carvalho Chehab
1356cd238effSMauro Carvalho Chehab			#include <asm-generic/termios.h>
1357cd238effSMauro Carvalho Chehab
1358cd238effSMauro Carvalho Chehab7.3 generated-y
1359cd238effSMauro Carvalho Chehab---------------
1360cd238effSMauro Carvalho Chehab
1361cd238effSMauro Carvalho Chehab	If an architecture generates other header files alongside generic-y
1362cd238effSMauro Carvalho Chehab	wrappers, generated-y specifies them.
1363cd238effSMauro Carvalho Chehab
1364cd238effSMauro Carvalho Chehab	This prevents them being treated as stale asm-generic wrappers and
1365cd238effSMauro Carvalho Chehab	removed.
1366cd238effSMauro Carvalho Chehab
1367cd238effSMauro Carvalho Chehab		Example::
1368cd238effSMauro Carvalho Chehab
1369cd238effSMauro Carvalho Chehab			#arch/x86/include/asm/Kbuild
1370cd238effSMauro Carvalho Chehab			generated-y += syscalls_32.h
1371cd238effSMauro Carvalho Chehab
1372cd238effSMauro Carvalho Chehab7.4 mandatory-y
1373cd238effSMauro Carvalho Chehab---------------
1374cd238effSMauro Carvalho Chehab
1375cd238effSMauro Carvalho Chehab	mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild
1376cd238effSMauro Carvalho Chehab	to define the minimum set of ASM headers that all architectures must have.
1377cd238effSMauro Carvalho Chehab
1378cd238effSMauro Carvalho Chehab	This works like optional generic-y. If a mandatory header is missing
1379cd238effSMauro Carvalho Chehab	in arch/$(ARCH)/include/(uapi/)/asm, Kbuild will automatically generate
1380cd238effSMauro Carvalho Chehab	a wrapper of the asm-generic one.
1381cd238effSMauro Carvalho Chehab
1382cd238effSMauro Carvalho Chehab8 Kbuild Variables
1383cd238effSMauro Carvalho Chehab==================
1384cd238effSMauro Carvalho Chehab
1385cd238effSMauro Carvalho ChehabThe top Makefile exports the following variables:
1386cd238effSMauro Carvalho Chehab
1387cd238effSMauro Carvalho Chehab    VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
1388cd238effSMauro Carvalho Chehab	These variables define the current kernel version.  A few arch
1389cd238effSMauro Carvalho Chehab	Makefiles actually use these values directly; they should use
1390cd238effSMauro Carvalho Chehab	$(KERNELRELEASE) instead.
1391cd238effSMauro Carvalho Chehab
1392cd238effSMauro Carvalho Chehab	$(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic
1393cd238effSMauro Carvalho Chehab	three-part version number, such as "2", "4", and "0".  These three
1394cd238effSMauro Carvalho Chehab	values are always numeric.
1395cd238effSMauro Carvalho Chehab
1396cd238effSMauro Carvalho Chehab	$(EXTRAVERSION) defines an even tinier sublevel for pre-patches
1397cd238effSMauro Carvalho Chehab	or additional patches.	It is usually some non-numeric string
1398cd238effSMauro Carvalho Chehab	such as "-pre4", and is often blank.
1399cd238effSMauro Carvalho Chehab
1400cd238effSMauro Carvalho Chehab    KERNELRELEASE
1401cd238effSMauro Carvalho Chehab	$(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable
1402cd238effSMauro Carvalho Chehab	for constructing installation directory names or showing in
1403cd238effSMauro Carvalho Chehab	version strings.  Some arch Makefiles use it for this purpose.
1404cd238effSMauro Carvalho Chehab
1405cd238effSMauro Carvalho Chehab    ARCH
1406cd238effSMauro Carvalho Chehab	This variable defines the target architecture, such as "i386",
1407cd238effSMauro Carvalho Chehab	"arm", or "sparc". Some kbuild Makefiles test $(ARCH) to
1408cd238effSMauro Carvalho Chehab	determine which files to compile.
1409cd238effSMauro Carvalho Chehab
1410cd238effSMauro Carvalho Chehab	By default, the top Makefile sets $(ARCH) to be the same as the
1411cd238effSMauro Carvalho Chehab	host system architecture.  For a cross build, a user may
1412cd238effSMauro Carvalho Chehab	override the value of $(ARCH) on the command line::
1413cd238effSMauro Carvalho Chehab
1414cd238effSMauro Carvalho Chehab	    make ARCH=m68k ...
1415cd238effSMauro Carvalho Chehab
1416cd238effSMauro Carvalho Chehab
1417cd238effSMauro Carvalho Chehab    INSTALL_PATH
1418cd238effSMauro Carvalho Chehab	This variable defines a place for the arch Makefiles to install
1419cd238effSMauro Carvalho Chehab	the resident kernel image and System.map file.
1420cd238effSMauro Carvalho Chehab	Use this for architecture-specific install targets.
1421cd238effSMauro Carvalho Chehab
1422cd238effSMauro Carvalho Chehab    INSTALL_MOD_PATH, MODLIB
1423cd238effSMauro Carvalho Chehab	$(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module
1424cd238effSMauro Carvalho Chehab	installation.  This variable is not defined in the Makefile but
1425cd238effSMauro Carvalho Chehab	may be passed in by the user if desired.
1426cd238effSMauro Carvalho Chehab
1427cd238effSMauro Carvalho Chehab	$(MODLIB) specifies the directory for module installation.
1428cd238effSMauro Carvalho Chehab	The top Makefile defines $(MODLIB) to
1429cd238effSMauro Carvalho Chehab	$(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE).  The user may
1430cd238effSMauro Carvalho Chehab	override this value on the command line if desired.
1431cd238effSMauro Carvalho Chehab
1432cd238effSMauro Carvalho Chehab    INSTALL_MOD_STRIP
1433cd238effSMauro Carvalho Chehab	If this variable is specified, it will cause modules to be stripped
1434cd238effSMauro Carvalho Chehab	after they are installed.  If INSTALL_MOD_STRIP is '1', then the
1435cd238effSMauro Carvalho Chehab	default option --strip-debug will be used.  Otherwise, the
1436cd238effSMauro Carvalho Chehab	INSTALL_MOD_STRIP value will be used as the option(s) to the strip
1437cd238effSMauro Carvalho Chehab	command.
1438cd238effSMauro Carvalho Chehab
1439cd238effSMauro Carvalho Chehab
1440cd238effSMauro Carvalho Chehab9 Makefile language
1441cd238effSMauro Carvalho Chehab===================
1442cd238effSMauro Carvalho Chehab
1443cd238effSMauro Carvalho ChehabThe kernel Makefiles are designed to be run with GNU Make.  The Makefiles
1444cd238effSMauro Carvalho Chehabuse only the documented features of GNU Make, but they do use many
1445cd238effSMauro Carvalho ChehabGNU extensions.
1446cd238effSMauro Carvalho Chehab
1447cd238effSMauro Carvalho ChehabGNU Make supports elementary list-processing functions.  The kernel
1448cd238effSMauro Carvalho ChehabMakefiles use a novel style of list building and manipulation with few
1449cd238effSMauro Carvalho Chehab"if" statements.
1450cd238effSMauro Carvalho Chehab
1451cd238effSMauro Carvalho ChehabGNU Make has two assignment operators, ":=" and "=".  ":=" performs
1452cd238effSMauro Carvalho Chehabimmediate evaluation of the right-hand side and stores an actual string
1453cd238effSMauro Carvalho Chehabinto the left-hand side.  "=" is like a formula definition; it stores the
1454cd238effSMauro Carvalho Chehabright-hand side in an unevaluated form and then evaluates this form each
1455cd238effSMauro Carvalho Chehabtime the left-hand side is used.
1456cd238effSMauro Carvalho Chehab
1457cd238effSMauro Carvalho ChehabThere are some cases where "=" is appropriate.  Usually, though, ":="
1458cd238effSMauro Carvalho Chehabis the right choice.
1459cd238effSMauro Carvalho Chehab
1460cd238effSMauro Carvalho Chehab10 Credits
1461cd238effSMauro Carvalho Chehab==========
1462cd238effSMauro Carvalho Chehab
1463cd238effSMauro Carvalho Chehab- Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
1464cd238effSMauro Carvalho Chehab- Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
1465cd238effSMauro Carvalho Chehab- Updates by Sam Ravnborg <sam@ravnborg.org>
1466cd238effSMauro Carvalho Chehab- Language QA by Jan Engelhardt <jengelh@gmx.de>
1467cd238effSMauro Carvalho Chehab
1468cd238effSMauro Carvalho Chehab11 TODO
1469cd238effSMauro Carvalho Chehab=======
1470cd238effSMauro Carvalho Chehab
1471cd238effSMauro Carvalho Chehab- Describe how kbuild supports shipped files with _shipped.
1472cd238effSMauro Carvalho Chehab- Generating offset header files.
1473cd238effSMauro Carvalho Chehab- Add more variables to section 7?
1474