kbuild.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. HOSTLDFLAGS
  73. -----------
  74. Additional flags to be passed when linking host programs.
  75. HOSTLDLIBS
  76. ----------
  77. Additional libraries to link against when building host programs.
  78. .. _userkbuildflags:
  79. USERCFLAGS
  80. ----------
  81. Additional options used for $(CC) when compiling userprogs.
  82. USERLDFLAGS
  83. -----------
  84. Additional options used for $(LD) when linking userprogs. userprogs are linked
  85. with CC, so $(USERLDFLAGS) should include "-Wl," prefix as applicable.
  86. KBUILD_KCONFIG
  87. --------------
  88. Set the top-level Kconfig file to the value of this environment
  89. variable. The default name is "Kconfig".
  90. KBUILD_VERBOSE
  91. --------------
  92. Set the kbuild verbosity. Can be assigned same values as "V=...".
  93. See make help for the full list.
  94. Setting "V=..." takes precedence over KBUILD_VERBOSE.
  95. KBUILD_EXTMOD
  96. -------------
  97. Set the directory to look for the kernel source when building external
  98. modules.
  99. Setting "M=..." takes precedence over KBUILD_EXTMOD.
  100. KBUILD_OUTPUT
  101. -------------
  102. Specify the output directory when building the kernel.
  103. This variable can also be used to point to the kernel output directory when
  104. building external modules against a pre-built kernel in a separate build
  105. directory. Please note that this does NOT specify the output directory for the
  106. external modules themselves.
  107. The output directory can also be specified using "O=...".
  108. Setting "O=..." takes precedence over KBUILD_OUTPUT.
  109. KBUILD_EXTRA_WARN
  110. -----------------
  111. Specify the extra build checks. The same value can be assigned by passing
  112. W=... from the command line.
  113. See `make help` for the list of the supported values.
  114. Setting "W=..." takes precedence over KBUILD_EXTRA_WARN.
  115. KBUILD_DEBARCH
  116. --------------
  117. For the deb-pkg target, allows overriding the normal heuristics deployed by
  118. deb-pkg. Normally deb-pkg attempts to guess the right architecture based on
  119. the UTS_MACHINE variable, and on some architectures also the kernel config.
  120. The value of KBUILD_DEBARCH is assumed (not checked) to be a valid Debian
  121. architecture.
  122. KDOCFLAGS
  123. ---------
  124. Specify extra (warning/error) flags for kernel-doc checks during the build,
  125. see scripts/kernel-doc for which flags are supported. Note that this doesn't
  126. (currently) apply to documentation builds.
  127. ARCH
  128. ----
  129. Set ARCH to the architecture to be built.
  130. In most cases the name of the architecture is the same as the
  131. directory name found in the arch/ directory.
  132. But some architectures such as x86 and sparc have aliases.
  133. - x86: i386 for 32 bit, x86_64 for 64 bit
  134. - parisc: parisc64 for 64 bit
  135. - sparc: sparc32 for 32 bit, sparc64 for 64 bit
  136. CROSS_COMPILE
  137. -------------
  138. Specify an optional fixed part of the binutils filename.
  139. CROSS_COMPILE can be a part of the filename or the full path.
  140. CROSS_COMPILE is also used for ccache in some setups.
  141. CF
  142. --
  143. Additional options for sparse.
  144. CF is often used on the command-line like this::
  145. make CF=-Wbitwise C=2
  146. INSTALL_PATH
  147. ------------
  148. INSTALL_PATH specifies where to place the updated kernel and system map
  149. images. Default is /boot, but you can set it to other values.
  150. INSTALLKERNEL
  151. -------------
  152. Install script called when using "make install".
  153. The default name is "installkernel".
  154. The script will be called with the following arguments:
  155. - $1 - kernel version
  156. - $2 - kernel image file
  157. - $3 - kernel map file
  158. - $4 - default install path (use root directory if blank)
  159. The implementation of "make install" is architecture specific
  160. and it may differ from the above.
  161. INSTALLKERNEL is provided to enable the possibility to
  162. specify a custom installer when cross compiling a kernel.
  163. MODLIB
  164. ------
  165. Specify where to install modules.
  166. The default value is::
  167. $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
  168. The value can be overridden in which case the default value is ignored.
  169. INSTALL_MOD_PATH
  170. ----------------
  171. INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
  172. relocations required by build roots. This is not defined in the
  173. makefile but the argument can be passed to make if needed.
  174. INSTALL_MOD_STRIP
  175. -----------------
  176. INSTALL_MOD_STRIP, if defined, will cause modules to be
  177. stripped after they are installed. If INSTALL_MOD_STRIP is '1', then
  178. the default option --strip-debug will be used. Otherwise,
  179. INSTALL_MOD_STRIP value will be used as the options to the strip command.
  180. INSTALL_HDR_PATH
  181. ----------------
  182. INSTALL_HDR_PATH specifies where to install user space headers when
  183. executing "make headers_*".
  184. The default value is::
  185. $(objtree)/usr
  186. $(objtree) is the directory where output files are saved.
  187. The output directory is often set using "O=..." on the commandline.
  188. The value can be overridden in which case the default value is ignored.
  189. INSTALL_DTBS_PATH
  190. -----------------
  191. INSTALL_DTBS_PATH specifies where to install device tree blobs for
  192. relocations required by build roots. This is not defined in the
  193. makefile but the argument can be passed to make if needed.
  194. KBUILD_ABS_SRCTREE
  195. --------------------------------------------------
  196. Kbuild uses a relative path to point to the tree when possible. For instance,
  197. when building in the source tree, the source tree path is '.'
  198. Setting this flag requests Kbuild to use absolute path to the source tree.
  199. There are some useful cases to do so, like when generating tag files with
  200. absolute path entries etc.
  201. KBUILD_SIGN_PIN
  202. ---------------
  203. This variable allows a passphrase or PIN to be passed to the sign-file
  204. utility when signing kernel modules, if the private key requires such.
  205. KBUILD_MODPOST_WARN
  206. -------------------
  207. KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined
  208. symbols in the final module linking stage. It changes such errors
  209. into warnings.
  210. KBUILD_MODPOST_NOFINAL
  211. ----------------------
  212. KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
  213. This is solely useful to speed up test compiles.
  214. KBUILD_EXTRA_SYMBOLS
  215. --------------------
  216. For modules that use symbols from other modules.
  217. See more details in modules.rst.
  218. ALLSOURCE_ARCHS
  219. ---------------
  220. For tags/TAGS/cscope targets, you can specify more than one arch
  221. to be included in the databases, separated by blank space. E.g.::
  222. $ make ALLSOURCE_ARCHS="x86 mips arm" tags
  223. To get all available archs you can also specify all. E.g.::
  224. $ make ALLSOURCE_ARCHS=all tags
  225. IGNORE_DIRS
  226. -----------
  227. For tags/TAGS/cscope targets, you can choose which directories won't
  228. be included in the databases, separated by blank space. E.g.::
  229. $ make IGNORE_DIRS="drivers/gpu/drm/radeon tools" cscope
  230. KBUILD_BUILD_TIMESTAMP
  231. ----------------------
  232. Setting this to a date string overrides the timestamp used in the
  233. UTS_VERSION definition (uname -v in the running kernel). The value has to
  234. be a string that can be passed to date -d. The default value
  235. is the output of the date command at one point during build.
  236. KBUILD_BUILD_USER, KBUILD_BUILD_HOST
  237. ------------------------------------
  238. These two variables allow to override the user@host string displayed during
  239. boot and in /proc/version. The default value is the output of the commands
  240. whoami and host, respectively.
  241. LLVM
  242. ----
  243. If this variable is set to 1, Kbuild will use Clang and LLVM utilities instead
  244. of GCC and GNU binutils to build the kernel.