xref: /linux/Documentation/kbuild/kbuild.rst (revision 34f7c6e7d4396090692a09789db231e12cb4762b)
1======
2Kbuild
3======
4
5
6Output files
7============
8
9modules.order
10-------------
11This file records the order in which modules appear in Makefiles. This
12is used by modprobe to deterministically resolve aliases that match
13multiple modules.
14
15modules.builtin
16---------------
17This file lists all modules that are built into the kernel. This is used
18by modprobe to not fail when trying to load something builtin.
19
20modules.builtin.modinfo
21-----------------------
22This file contains modinfo from all modules that are built into the kernel.
23Unlike modinfo of a separate module, all fields are prefixed with module name.
24
25
26Environment variables
27=====================
28
29KCPPFLAGS
30---------
31Additional options to pass when preprocessing. The preprocessing options
32will be used in all cases where kbuild does preprocessing including
33building C files and assembler files.
34
35KAFLAGS
36-------
37Additional options to the assembler (for built-in and modules).
38
39AFLAGS_MODULE
40-------------
41Additional assembler options for modules.
42
43AFLAGS_KERNEL
44-------------
45Additional assembler options for built-in.
46
47KCFLAGS
48-------
49Additional options to the C compiler (for built-in and modules).
50
51CFLAGS_KERNEL
52-------------
53Additional options for $(CC) when used to compile
54code that is compiled as built-in.
55
56CFLAGS_MODULE
57-------------
58Additional module specific options to use for $(CC).
59
60LDFLAGS_MODULE
61--------------
62Additional options used for $(LD) when linking modules.
63
64HOSTCFLAGS
65----------
66Additional flags to be passed to $(HOSTCC) when building host programs.
67
68HOSTCXXFLAGS
69------------
70Additional flags to be passed to $(HOSTCXX) when building host programs.
71
72HOSTLDFLAGS
73-----------
74Additional flags to be passed when linking host programs.
75
76HOSTLDLIBS
77----------
78Additional libraries to link against when building host programs.
79
80.. _userkbuildflags:
81
82USERCFLAGS
83----------
84Additional options used for $(CC) when compiling userprogs.
85
86USERLDFLAGS
87-----------
88Additional options used for $(LD) when linking userprogs. userprogs are linked
89with CC, so $(USERLDFLAGS) should include "-Wl," prefix as applicable.
90
91KBUILD_KCONFIG
92--------------
93Set the top-level Kconfig file to the value of this environment
94variable.  The default name is "Kconfig".
95
96KBUILD_VERBOSE
97--------------
98Set the kbuild verbosity. Can be assigned same values as "V=...".
99
100See make help for the full list.
101
102Setting "V=..." takes precedence over KBUILD_VERBOSE.
103
104KBUILD_EXTMOD
105-------------
106Set the directory to look for the kernel source when building external
107modules.
108
109Setting "M=..." takes precedence over KBUILD_EXTMOD.
110
111KBUILD_OUTPUT
112-------------
113Specify the output directory when building the kernel.
114
115The output directory can also be specified using "O=...".
116
117Setting "O=..." takes precedence over KBUILD_OUTPUT.
118
119KBUILD_EXTRA_WARN
120-----------------
121Specify the extra build checks. The same value can be assigned by passing
122W=... from the command line.
123
124See `make help` for the list of the supported values.
125
126Setting "W=..." takes precedence over KBUILD_EXTRA_WARN.
127
128KBUILD_DEBARCH
129--------------
130For the deb-pkg target, allows overriding the normal heuristics deployed by
131deb-pkg. Normally deb-pkg attempts to guess the right architecture based on
132the UTS_MACHINE variable, and on some architectures also the kernel config.
133The value of KBUILD_DEBARCH is assumed (not checked) to be a valid Debian
134architecture.
135
136ARCH
137----
138Set ARCH to the architecture to be built.
139
140In most cases the name of the architecture is the same as the
141directory name found in the arch/ directory.
142
143But some architectures such as x86 and sparc have aliases.
144
145- x86: i386 for 32 bit, x86_64 for 64 bit
146- sh: sh for 32 bit, sh64 for 64 bit
147- sparc: sparc32 for 32 bit, sparc64 for 64 bit
148
149CROSS_COMPILE
150-------------
151Specify an optional fixed part of the binutils filename.
152CROSS_COMPILE can be a part of the filename or the full path.
153
154CROSS_COMPILE is also used for ccache in some setups.
155
156CF
157--
158Additional options for sparse.
159
160CF is often used on the command-line like this::
161
162    make CF=-Wbitwise C=2
163
164INSTALL_PATH
165------------
166INSTALL_PATH specifies where to place the updated kernel and system map
167images. Default is /boot, but you can set it to other values.
168
169INSTALLKERNEL
170-------------
171Install script called when using "make install".
172The default name is "installkernel".
173
174The script will be called with the following arguments:
175
176   - $1 - kernel version
177   - $2 - kernel image file
178   - $3 - kernel map file
179   - $4 - default install path (use root directory if blank)
180
181The implementation of "make install" is architecture specific
182and it may differ from the above.
183
184INSTALLKERNEL is provided to enable the possibility to
185specify a custom installer when cross compiling a kernel.
186
187MODLIB
188------
189Specify where to install modules.
190The default value is::
191
192     $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
193
194The value can be overridden in which case the default value is ignored.
195
196INSTALL_MOD_PATH
197----------------
198INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
199relocations required by build roots.  This is not defined in the
200makefile but the argument can be passed to make if needed.
201
202INSTALL_MOD_STRIP
203-----------------
204INSTALL_MOD_STRIP, if defined, will cause modules to be
205stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
206the default option --strip-debug will be used.  Otherwise,
207INSTALL_MOD_STRIP value will be used as the options to the strip command.
208
209INSTALL_HDR_PATH
210----------------
211INSTALL_HDR_PATH specifies where to install user space headers when
212executing "make headers_*".
213
214The default value is::
215
216    $(objtree)/usr
217
218$(objtree) is the directory where output files are saved.
219The output directory is often set using "O=..." on the commandline.
220
221The value can be overridden in which case the default value is ignored.
222
223KBUILD_ABS_SRCTREE
224--------------------------------------------------
225Kbuild uses a relative path to point to the tree when possible. For instance,
226when building in the source tree, the source tree path is '.'
227
228Setting this flag requests Kbuild to use absolute path to the source tree.
229There are some useful cases to do so, like when generating tag files with
230absolute path entries etc.
231
232KBUILD_SIGN_PIN
233---------------
234This variable allows a passphrase or PIN to be passed to the sign-file
235utility when signing kernel modules, if the private key requires such.
236
237KBUILD_MODPOST_WARN
238-------------------
239KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined
240symbols in the final module linking stage. It changes such errors
241into warnings.
242
243KBUILD_MODPOST_NOFINAL
244----------------------
245KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
246This is solely useful to speed up test compiles.
247
248KBUILD_EXTRA_SYMBOLS
249--------------------
250For modules that use symbols from other modules.
251See more details in modules.rst.
252
253ALLSOURCE_ARCHS
254---------------
255For tags/TAGS/cscope targets, you can specify more than one arch
256to be included in the databases, separated by blank space. E.g.::
257
258    $ make ALLSOURCE_ARCHS="x86 mips arm" tags
259
260To get all available archs you can also specify all. E.g.::
261
262    $ make ALLSOURCE_ARCHS=all tags
263
264KBUILD_BUILD_TIMESTAMP
265----------------------
266Setting this to a date string overrides the timestamp used in the
267UTS_VERSION definition (uname -v in the running kernel). The value has to
268be a string that can be passed to date -d. The default value
269is the output of the date command at one point during build.
270
271KBUILD_BUILD_USER, KBUILD_BUILD_HOST
272------------------------------------
273These two variables allow to override the user@host string displayed during
274boot and in /proc/version. The default value is the output of the commands
275whoami and host, respectively.
276
277LLVM
278----
279If this variable is set to 1, Kbuild will use Clang and LLVM utilities instead
280of GCC and GNU binutils to build the kernel.
281