kbuild.rst 10 KB

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