xref: /linux/Documentation/kbuild/kbuild.rst (revision f96a974170b749e3a56844e25b31d46a7233b6f6)
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
25modules.builtin.ranges
26----------------------
27This file contains address offset ranges (per ELF section) for all modules
28that are built into the kernel. Together with System.map, it can be used
29to associate module names with symbols.
30
31Environment variables
32=====================
33
34KCPPFLAGS
35---------
36Additional options to pass when preprocessing. The preprocessing options
37will be used in all cases where kbuild does preprocessing including
38building C files and assembler files.
39
40KAFLAGS
41-------
42Additional options to the assembler (for built-in and modules).
43
44AFLAGS_MODULE
45-------------
46Additional assembler options for modules.
47
48AFLAGS_KERNEL
49-------------
50Additional assembler options for built-in.
51
52KCFLAGS
53-------
54Additional options to the C compiler (for built-in and modules).
55
56KRUSTFLAGS
57----------
58Additional options to the Rust compiler (for built-in and modules).
59
60CFLAGS_KERNEL
61-------------
62Additional options for $(CC) when used to compile
63code that is compiled as built-in.
64
65CFLAGS_MODULE
66-------------
67Additional module specific options to use for $(CC).
68
69RUSTFLAGS_KERNEL
70----------------
71Additional options for $(RUSTC) when used to compile
72code that is compiled as built-in.
73
74RUSTFLAGS_MODULE
75----------------
76Additional module specific options to use for $(RUSTC).
77
78LDFLAGS_MODULE
79--------------
80Additional options used for $(LD) when linking modules.
81
82HOSTCFLAGS
83----------
84Additional flags to be passed to $(HOSTCC) when building host programs.
85
86HOSTCXXFLAGS
87------------
88Additional flags to be passed to $(HOSTCXX) when building host programs.
89
90HOSTRUSTFLAGS
91-------------
92Additional flags to be passed to $(HOSTRUSTC) when building host programs.
93
94PROCMACROLDFLAGS
95----------------
96Flags to be passed when linking Rust proc macros. Since proc macros are loaded
97by rustc at build time, they must be linked in a way that is compatible with
98the rustc toolchain being used.
99
100For instance, it can be useful when rustc uses a different C library than
101the one the user wants to use for host programs.
102
103If unset, it defaults to the flags passed when linking host programs.
104
105HOSTLDFLAGS
106-----------
107Additional flags to be passed when linking host programs.
108
109HOSTLDLIBS
110----------
111Additional libraries to link against when building host programs.
112
113.. _userkbuildflags:
114
115USERCFLAGS
116----------
117Additional options used for $(CC) when compiling userprogs.
118
119USERLDFLAGS
120-----------
121Additional options used for $(LD) when linking userprogs. userprogs are linked
122with CC, so $(USERLDFLAGS) should include "-Wl," prefix as applicable.
123
124KBUILD_KCONFIG
125--------------
126Set the top-level Kconfig file to the value of this environment
127variable.  The default name is "Kconfig".
128
129KBUILD_VERBOSE
130--------------
131Set the kbuild verbosity. Can be assigned same values as "V=...".
132
133See make help for the full list.
134
135Setting "V=..." takes precedence over KBUILD_VERBOSE.
136
137KBUILD_EXTMOD
138-------------
139Set the directory to look for the kernel source when building external
140modules.
141
142Setting "M=..." takes precedence over KBUILD_EXTMOD.
143
144KBUILD_OUTPUT
145-------------
146Specify the output directory when building the kernel.
147
148This variable can also be used to point to the kernel output directory when
149building external modules against a pre-built kernel in a separate build
150directory. Please note that this does NOT specify the output directory for the
151external modules themselves. (Use KBUILD_EXTMOD_OUTPUT for that purpose.)
152
153The output directory can also be specified using "O=...".
154
155Setting "O=..." takes precedence over KBUILD_OUTPUT.
156
157KBUILD_EXTMOD_OUTPUT
158--------------------
159Specify the output directory for external modules.
160
161Setting "MO=..." takes precedence over KBUILD_EXTMOD_OUTPUT.
162
163KBUILD_EXTRA_WARN
164-----------------
165Specify the extra build checks. The same value can be assigned by passing
166W=... from the command line.
167
168See `make help` for the list of the supported values.
169
170Setting "W=..." takes precedence over KBUILD_EXTRA_WARN.
171
172KBUILD_DEBARCH
173--------------
174For the deb-pkg target, allows overriding the normal heuristics deployed by
175deb-pkg. Normally deb-pkg attempts to guess the right architecture based on
176the UTS_MACHINE variable, and on some architectures also the kernel config.
177The value of KBUILD_DEBARCH is assumed (not checked) to be a valid Debian
178architecture.
179
180KDOCFLAGS
181---------
182Specify extra (warning/error) flags for kernel-doc checks during the build,
183see scripts/kernel-doc for which flags are supported. Note that this doesn't
184(currently) apply to documentation builds.
185
186ARCH
187----
188Set ARCH to the architecture to be built.
189
190In most cases the name of the architecture is the same as the
191directory name found in the arch/ directory.
192
193But some architectures such as x86 and sparc have aliases.
194
195- x86: i386 for 32 bit, x86_64 for 64 bit
196- parisc: parisc64 for 64 bit
197- sparc: sparc32 for 32 bit, sparc64 for 64 bit
198
199CROSS_COMPILE
200-------------
201Specify an optional fixed part of the binutils filename.
202CROSS_COMPILE can be a part of the filename or the full path.
203
204CROSS_COMPILE is also used for ccache in some setups.
205
206CF
207--
208Additional options for sparse.
209
210CF is often used on the command-line like this::
211
212    make CF=-Wbitwise C=2
213
214INSTALL_PATH
215------------
216INSTALL_PATH specifies where to place the updated kernel and system map
217images. Default is /boot, but you can set it to other values.
218
219INSTALLKERNEL
220-------------
221Install script called when using "make install".
222The default name is "installkernel".
223
224The script will be called with the following arguments:
225
226   - $1 - kernel version
227   - $2 - kernel image file
228   - $3 - kernel map file
229   - $4 - default install path (use root directory if blank)
230
231The implementation of "make install" is architecture specific
232and it may differ from the above.
233
234INSTALLKERNEL is provided to enable the possibility to
235specify a custom installer when cross compiling a kernel.
236
237MODLIB
238------
239Specify where to install modules.
240The default value is::
241
242     $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
243
244The value can be overridden in which case the default value is ignored.
245
246INSTALL_MOD_PATH
247----------------
248INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
249relocations required by build roots.  This is not defined in the
250makefile but the argument can be passed to make if needed.
251
252INSTALL_MOD_STRIP
253-----------------
254INSTALL_MOD_STRIP, if defined, will cause modules to be
255stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
256the default option --strip-debug will be used.  Otherwise,
257INSTALL_MOD_STRIP value will be used as the options to the strip command.
258
259INSTALL_HDR_PATH
260----------------
261INSTALL_HDR_PATH specifies where to install user space headers when
262executing "make headers_*".
263
264The default value is::
265
266    $(objtree)/usr
267
268$(objtree) is the directory where output files are saved.
269The output directory is often set using "O=..." on the commandline.
270
271The value can be overridden in which case the default value is ignored.
272
273INSTALL_DTBS_PATH
274-----------------
275INSTALL_DTBS_PATH specifies where to install device tree blobs for
276relocations required by build roots.  This is not defined in the
277makefile but the argument can be passed to make if needed.
278
279KBUILD_ABS_SRCTREE
280--------------------------------------------------
281Kbuild uses a relative path to point to the tree when possible. For instance,
282when building in the source tree, the source tree path is '.'
283
284Setting this flag requests Kbuild to use absolute path to the source tree.
285There are some useful cases to do so, like when generating tag files with
286absolute path entries etc.
287
288KBUILD_SIGN_PIN
289---------------
290This variable allows a passphrase or PIN to be passed to the sign-file
291utility when signing kernel modules, if the private key requires such.
292
293KBUILD_MODPOST_WARN
294-------------------
295KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined
296symbols in the final module linking stage. It changes such errors
297into warnings.
298
299KBUILD_MODPOST_NOFINAL
300----------------------
301KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
302This is solely useful to speed up test compiles.
303
304KBUILD_EXTRA_SYMBOLS
305--------------------
306For modules that use symbols from other modules.
307See more details in modules.rst.
308
309ALLSOURCE_ARCHS
310---------------
311For tags/TAGS/cscope targets, you can specify more than one arch
312to be included in the databases, separated by blank space. E.g.::
313
314    $ make ALLSOURCE_ARCHS="x86 mips arm" tags
315
316To get all available archs you can also specify all. E.g.::
317
318    $ make ALLSOURCE_ARCHS=all tags
319
320IGNORE_DIRS
321-----------
322For tags/TAGS/cscope targets, you can choose which directories won't
323be included in the databases, separated by blank space. E.g.::
324
325    $ make IGNORE_DIRS="drivers/gpu/drm/radeon tools" cscope
326
327KBUILD_BUILD_TIMESTAMP
328----------------------
329Setting this to a date string overrides the timestamp used in the
330UTS_VERSION definition (uname -v in the running kernel). The value has to
331be a string that can be passed to date -d. The default value
332is the output of the date command at one point during build.
333
334KBUILD_BUILD_USER, KBUILD_BUILD_HOST
335------------------------------------
336These two variables allow to override the user@host string displayed during
337boot and in /proc/version. The default value is the output of the commands
338whoami and host, respectively.
339
340LLVM
341----
342If this variable is set to 1, Kbuild will use Clang and LLVM utilities instead
343of GCC and GNU binutils to build the kernel.
344