makefiles.txt 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. Linux Kernel Makefiles
  2. This document describes the Linux kernel Makefiles.
  3. === Table of Contents
  4. === 1 Overview
  5. === 2 Who does what
  6. === 3 The kbuild files
  7. --- 3.1 Goal definitions
  8. --- 3.2 Built-in object goals - obj-y
  9. --- 3.3 Loadable module goals - obj-m
  10. --- 3.4 Objects which export symbols
  11. --- 3.5 Library file goals - lib-y
  12. --- 3.6 Descending down in directories
  13. --- 3.7 Compilation flags
  14. --- 3.8 Command line dependency
  15. --- 3.9 Dependency tracking
  16. --- 3.10 Special Rules
  17. --- 3.11 $(CC) support functions
  18. --- 3.12 $(LD) support functions
  19. === 4 Host Program support
  20. --- 4.1 Simple Host Program
  21. --- 4.2 Composite Host Programs
  22. --- 4.3 Using C++ for host programs
  23. --- 4.4 Controlling compiler options for host programs
  24. --- 4.5 When host programs are actually built
  25. --- 4.6 Using hostprogs-$(CONFIG_FOO)
  26. === 5 Kbuild clean infrastructure
  27. === 6 Architecture Makefiles
  28. --- 6.1 Set variables to tweak the build to the architecture
  29. --- 6.2 Add prerequisites to archheaders:
  30. --- 6.3 Add prerequisites to archprepare:
  31. --- 6.4 List directories to visit when descending
  32. --- 6.5 Architecture-specific boot images
  33. --- 6.6 Building non-kbuild targets
  34. --- 6.7 Commands useful for building a boot image
  35. --- 6.8 Custom kbuild commands
  36. --- 6.9 Preprocessing linker scripts
  37. --- 6.10 Generic header files
  38. --- 6.11 Post-link pass
  39. === 7 Kbuild syntax for exported headers
  40. --- 7.1 no-export-headers
  41. --- 7.2 generic-y
  42. --- 7.3 generated-y
  43. --- 7.4 mandatory-y
  44. === 8 Kbuild Variables
  45. === 9 Makefile language
  46. === 10 Credits
  47. === 11 TODO
  48. === 1 Overview
  49. The Makefiles have five parts:
  50. Makefile the top Makefile.
  51. .config the kernel configuration file.
  52. arch/$(ARCH)/Makefile the arch Makefile.
  53. scripts/Makefile.* common rules etc. for all kbuild Makefiles.
  54. kbuild Makefiles there are about 500 of these.
  55. The top Makefile reads the .config file, which comes from the kernel
  56. configuration process.
  57. The top Makefile is responsible for building two major products: vmlinux
  58. (the resident kernel image) and modules (any module files).
  59. It builds these goals by recursively descending into the subdirectories of
  60. the kernel source tree.
  61. The list of subdirectories which are visited depends upon the kernel
  62. configuration. The top Makefile textually includes an arch Makefile
  63. with the name arch/$(ARCH)/Makefile. The arch Makefile supplies
  64. architecture-specific information to the top Makefile.
  65. Each subdirectory has a kbuild Makefile which carries out the commands
  66. passed down from above. The kbuild Makefile uses information from the
  67. .config file to construct various file lists used by kbuild to build
  68. any built-in or modular targets.
  69. scripts/Makefile.* contains all the definitions/rules etc. that
  70. are used to build the kernel based on the kbuild makefiles.
  71. === 2 Who does what
  72. People have four different relationships with the kernel Makefiles.
  73. *Users* are people who build kernels. These people type commands such as
  74. "make menuconfig" or "make". They usually do not read or edit
  75. any kernel Makefiles (or any other source files).
  76. *Normal developers* are people who work on features such as device
  77. drivers, file systems, and network protocols. These people need to
  78. maintain the kbuild Makefiles for the subsystem they are
  79. working on. In order to do this effectively, they need some overall
  80. knowledge about the kernel Makefiles, plus detailed knowledge about the
  81. public interface for kbuild.
  82. *Arch developers* are people who work on an entire architecture, such
  83. as sparc or ia64. Arch developers need to know about the arch Makefile
  84. as well as kbuild Makefiles.
  85. *Kbuild developers* are people who work on the kernel build system itself.
  86. These people need to know about all aspects of the kernel Makefiles.
  87. This document is aimed towards normal developers and arch developers.
  88. === 3 The kbuild files
  89. Most Makefiles within the kernel are kbuild Makefiles that use the
  90. kbuild infrastructure. This chapter introduces the syntax used in the
  91. kbuild makefiles.
  92. The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can
  93. be used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild'
  94. file will be used.
  95. Section 3.1 "Goal definitions" is a quick intro, further chapters provide
  96. more details, with real examples.
  97. --- 3.1 Goal definitions
  98. Goal definitions are the main part (heart) of the kbuild Makefile.
  99. These lines define the files to be built, any special compilation
  100. options, and any subdirectories to be entered recursively.
  101. The most simple kbuild makefile contains one line:
  102. Example:
  103. obj-y += foo.o
  104. This tells kbuild that there is one object in that directory, named
  105. foo.o. foo.o will be built from foo.c or foo.S.
  106. If foo.o shall be built as a module, the variable obj-m is used.
  107. Therefore the following pattern is often used:
  108. Example:
  109. obj-$(CONFIG_FOO) += foo.o
  110. $(CONFIG_FOO) evaluates to either y (for built-in) or m (for module).
  111. If CONFIG_FOO is neither y nor m, then the file will not be compiled
  112. nor linked.
  113. --- 3.2 Built-in object goals - obj-y
  114. The kbuild Makefile specifies object files for vmlinux
  115. in the $(obj-y) lists. These lists depend on the kernel
  116. configuration.
  117. Kbuild compiles all the $(obj-y) files. It then calls
  118. "$(LD) -r" to merge these files into one built-in.o file.
  119. built-in.o is later linked into vmlinux by the parent Makefile.
  120. The order of files in $(obj-y) is significant. Duplicates in
  121. the lists are allowed: the first instance will be linked into
  122. built-in.o and succeeding instances will be ignored.
  123. Link order is significant, because certain functions
  124. (module_init() / __initcall) will be called during boot in the
  125. order they appear. So keep in mind that changing the link
  126. order may e.g. change the order in which your SCSI
  127. controllers are detected, and thus your disks are renumbered.
  128. Example:
  129. #drivers/isdn/i4l/Makefile
  130. # Makefile for the kernel ISDN subsystem and device drivers.
  131. # Each configuration option enables a list of files.
  132. obj-$(CONFIG_ISDN_I4L) += isdn.o
  133. obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o
  134. --- 3.3 Loadable module goals - obj-m
  135. $(obj-m) specifies object files which are built as loadable
  136. kernel modules.
  137. A module may be built from one source file or several source
  138. files. In the case of one source file, the kbuild makefile
  139. simply adds the file to $(obj-m).
  140. Example:
  141. #drivers/isdn/i4l/Makefile
  142. obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o
  143. Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm'
  144. If a kernel module is built from several source files, you specify
  145. that you want to build a module in the same way as above; however,
  146. kbuild needs to know which object files you want to build your
  147. module from, so you have to tell it by setting a $(<module_name>-y)
  148. variable.
  149. Example:
  150. #drivers/isdn/i4l/Makefile
  151. obj-$(CONFIG_ISDN_I4L) += isdn.o
  152. isdn-y := isdn_net_lib.o isdn_v110.o isdn_common.o
  153. In this example, the module name will be isdn.o. Kbuild will
  154. compile the objects listed in $(isdn-y) and then run
  155. "$(LD) -r" on the list of these files to generate isdn.o.
  156. Due to kbuild recognizing $(<module_name>-y) for composite objects,
  157. you can use the value of a CONFIG_ symbol to optionally include an
  158. object file as part of a composite object.
  159. Example:
  160. #fs/ext2/Makefile
  161. obj-$(CONFIG_EXT2_FS) += ext2.o
  162. ext2-y := balloc.o dir.o file.o ialloc.o inode.o ioctl.o \
  163. namei.o super.o symlink.o
  164. ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o \
  165. xattr_trusted.o
  166. In this example, xattr.o, xattr_user.o and xattr_trusted.o are only
  167. part of the composite object ext2.o if $(CONFIG_EXT2_FS_XATTR)
  168. evaluates to 'y'.
  169. Note: Of course, when you are building objects into the kernel,
  170. the syntax above will also work. So, if you have CONFIG_EXT2_FS=y,
  171. kbuild will build an ext2.o file for you out of the individual
  172. parts and then link this into built-in.o, as you would expect.
  173. --- 3.4 Objects which export symbols
  174. No special notation is required in the makefiles for
  175. modules exporting symbols.
  176. --- 3.5 Library file goals - lib-y
  177. Objects listed with obj-* are used for modules, or
  178. combined in a built-in.o for that specific directory.
  179. There is also the possibility to list objects that will
  180. be included in a library, lib.a.
  181. All objects listed with lib-y are combined in a single
  182. library for that directory.
  183. Objects that are listed in obj-y and additionally listed in
  184. lib-y will not be included in the library, since they will
  185. be accessible anyway.
  186. For consistency, objects listed in lib-m will be included in lib.a.
  187. Note that the same kbuild makefile may list files to be built-in
  188. and to be part of a library. Therefore the same directory
  189. may contain both a built-in.o and a lib.a file.
  190. Example:
  191. #arch/x86/lib/Makefile
  192. lib-y := delay.o
  193. This will create a library lib.a based on delay.o. For kbuild to
  194. actually recognize that there is a lib.a being built, the directory
  195. shall be listed in libs-y.
  196. See also "6.4 List directories to visit when descending".
  197. Use of lib-y is normally restricted to lib/ and arch/*/lib.
  198. --- 3.6 Descending down in directories
  199. A Makefile is only responsible for building objects in its own
  200. directory. Files in subdirectories should be taken care of by
  201. Makefiles in these subdirs. The build system will automatically
  202. invoke make recursively in subdirectories, provided you let it know of
  203. them.
  204. To do so, obj-y and obj-m are used.
  205. ext2 lives in a separate directory, and the Makefile present in fs/
  206. tells kbuild to descend down using the following assignment.
  207. Example:
  208. #fs/Makefile
  209. obj-$(CONFIG_EXT2_FS) += ext2/
  210. If CONFIG_EXT2_FS is set to either 'y' (built-in) or 'm' (modular)
  211. the corresponding obj- variable will be set, and kbuild will descend
  212. down in the ext2 directory.
  213. Kbuild only uses this information to decide that it needs to visit
  214. the directory, it is the Makefile in the subdirectory that
  215. specifies what is modular and what is built-in.
  216. It is good practice to use a CONFIG_ variable when assigning directory
  217. names. This allows kbuild to totally skip the directory if the
  218. corresponding CONFIG_ option is neither 'y' nor 'm'.
  219. --- 3.7 Compilation flags
  220. ccflags-y, asflags-y and ldflags-y
  221. These three flags apply only to the kbuild makefile in which they
  222. are assigned. They are used for all the normal cc, as and ld
  223. invocations happening during a recursive build.
  224. Note: Flags with the same behaviour were previously named:
  225. EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS.
  226. They are still supported but their usage is deprecated.
  227. ccflags-y specifies options for compiling with $(CC).
  228. Example:
  229. # drivers/acpi/acpica/Makefile
  230. ccflags-y := -Os -D_LINUX -DBUILDING_ACPICA
  231. ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT
  232. This variable is necessary because the top Makefile owns the
  233. variable $(KBUILD_CFLAGS) and uses it for compilation flags for the
  234. entire tree.
  235. asflags-y specifies options for assembling with $(AS).
  236. Example:
  237. #arch/sparc/kernel/Makefile
  238. asflags-y := -ansi
  239. ldflags-y specifies options for linking with $(LD).
  240. Example:
  241. #arch/cris/boot/compressed/Makefile
  242. ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds
  243. subdir-ccflags-y, subdir-asflags-y
  244. The two flags listed above are similar to ccflags-y and asflags-y.
  245. The difference is that the subdir- variants have effect for the kbuild
  246. file where they are present and all subdirectories.
  247. Options specified using subdir-* are added to the commandline before
  248. the options specified using the non-subdir variants.
  249. Example:
  250. subdir-ccflags-y := -Werror
  251. CFLAGS_$@, AFLAGS_$@
  252. CFLAGS_$@ and AFLAGS_$@ only apply to commands in current
  253. kbuild makefile.
  254. $(CFLAGS_$@) specifies per-file options for $(CC). The $@
  255. part has a literal value which specifies the file that it is for.
  256. Example:
  257. # drivers/scsi/Makefile
  258. CFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONF
  259. CFLAGS_gdth.o = # -DDEBUG_GDTH=2 -D__SERIAL__ -D__COM2__ \
  260. -DGDTH_STATISTICS
  261. These two lines specify compilation flags for aha152x.o and gdth.o.
  262. $(AFLAGS_$@) is a similar feature for source files in assembly
  263. languages.
  264. Example:
  265. # arch/arm/kernel/Makefile
  266. AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
  267. AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312
  268. AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt
  269. --- 3.9 Dependency tracking
  270. Kbuild tracks dependencies on the following:
  271. 1) All prerequisite files (both *.c and *.h)
  272. 2) CONFIG_ options used in all prerequisite files
  273. 3) Command-line used to compile target
  274. Thus, if you change an option to $(CC) all affected files will
  275. be re-compiled.
  276. --- 3.10 Special Rules
  277. Special rules are used when the kbuild infrastructure does
  278. not provide the required support. A typical example is
  279. header files generated during the build process.
  280. Another example are the architecture-specific Makefiles which
  281. need special rules to prepare boot images etc.
  282. Special rules are written as normal Make rules.
  283. Kbuild is not executing in the directory where the Makefile is
  284. located, so all special rules shall provide a relative
  285. path to prerequisite files and target files.
  286. Two variables are used when defining special rules:
  287. $(src)
  288. $(src) is a relative path which points to the directory
  289. where the Makefile is located. Always use $(src) when
  290. referring to files located in the src tree.
  291. $(obj)
  292. $(obj) is a relative path which points to the directory
  293. where the target is saved. Always use $(obj) when
  294. referring to generated files.
  295. Example:
  296. #drivers/scsi/Makefile
  297. $(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl
  298. $(CPP) -DCHIP=810 - < $< | ... $(src)/script_asm.pl
  299. This is a special rule, following the normal syntax
  300. required by make.
  301. The target file depends on two prerequisite files. References
  302. to the target file are prefixed with $(obj), references
  303. to prerequisites are referenced with $(src) (because they are not
  304. generated files).
  305. $(kecho)
  306. echoing information to user in a rule is often a good practice
  307. but when execution "make -s" one does not expect to see any output
  308. except for warnings/errors.
  309. To support this kbuild defines $(kecho) which will echo out the
  310. text following $(kecho) to stdout except if "make -s" is used.
  311. Example:
  312. #arch/blackfin/boot/Makefile
  313. $(obj)/vmImage: $(obj)/vmlinux.gz
  314. $(call if_changed,uimage)
  315. @$(kecho) 'Kernel: $@ is ready'
  316. --- 3.11 $(CC) support functions
  317. The kernel may be built with several different versions of
  318. $(CC), each supporting a unique set of features and options.
  319. kbuild provides basic support to check for valid options for $(CC).
  320. $(CC) is usually the gcc compiler, but other alternatives are
  321. available.
  322. as-option
  323. as-option is used to check if $(CC) -- when used to compile
  324. assembler (*.S) files -- supports the given option. An optional
  325. second option may be specified if the first option is not supported.
  326. Example:
  327. #arch/sh/Makefile
  328. cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),)
  329. In the above example, cflags-y will be assigned the option
  330. -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC).
  331. The second argument is optional, and if supplied will be used
  332. if first argument is not supported.
  333. cc-ldoption
  334. cc-ldoption is used to check if $(CC) when used to link object files
  335. supports the given option. An optional second option may be
  336. specified if first option are not supported.
  337. Example:
  338. #arch/x86/kernel/Makefile
  339. vsyscall-flags += $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  340. In the above example, vsyscall-flags will be assigned the option
  341. -Wl$(comma)--hash-style=sysv if it is supported by $(CC).
  342. The second argument is optional, and if supplied will be used
  343. if first argument is not supported.
  344. as-instr
  345. as-instr checks if the assembler reports a specific instruction
  346. and then outputs either option1 or option2
  347. C escapes are supported in the test instruction
  348. Note: as-instr-option uses KBUILD_AFLAGS for $(AS) options
  349. cc-option
  350. cc-option is used to check if $(CC) supports a given option, and if
  351. not supported to use an optional second option.
  352. Example:
  353. #arch/x86/Makefile
  354. cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586)
  355. In the above example, cflags-y will be assigned the option
  356. -march=pentium-mmx if supported by $(CC), otherwise -march=i586.
  357. The second argument to cc-option is optional, and if omitted,
  358. cflags-y will be assigned no value if first option is not supported.
  359. Note: cc-option uses KBUILD_CFLAGS for $(CC) options
  360. cc-option-yn
  361. cc-option-yn is used to check if gcc supports a given option
  362. and return 'y' if supported, otherwise 'n'.
  363. Example:
  364. #arch/ppc/Makefile
  365. biarch := $(call cc-option-yn, -m32)
  366. aflags-$(biarch) += -a32
  367. cflags-$(biarch) += -m32
  368. In the above example, $(biarch) is set to y if $(CC) supports the -m32
  369. option. When $(biarch) equals 'y', the expanded variables $(aflags-y)
  370. and $(cflags-y) will be assigned the values -a32 and -m32,
  371. respectively.
  372. Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options
  373. cc-disable-warning
  374. cc-disable-warning checks if gcc supports a given warning and returns
  375. the commandline switch to disable it. This special function is needed,
  376. because gcc 4.4 and later accept any unknown -Wno-* option and only
  377. warn about it if there is another warning in the source file.
  378. Example:
  379. KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
  380. In the above example, -Wno-unused-but-set-variable will be added to
  381. KBUILD_CFLAGS only if gcc really accepts it.
  382. cc-version
  383. cc-version returns a numerical version of the $(CC) compiler version.
  384. The format is <major><minor> where both are two digits. So for example
  385. gcc 3.41 would return 0341.
  386. cc-version is useful when a specific $(CC) version is faulty in one
  387. area, for example -mregparm=3 was broken in some gcc versions
  388. even though the option was accepted by gcc.
  389. Example:
  390. #arch/x86/Makefile
  391. cflags-y += $(shell \
  392. if [ $(cc-version) -ge 0300 ] ; then \
  393. echo "-mregparm=3"; fi ;)
  394. In the above example, -mregparm=3 is only used for gcc version greater
  395. than or equal to gcc 3.0.
  396. cc-ifversion
  397. cc-ifversion tests the version of $(CC) and equals the fourth parameter
  398. if version expression is true, or the fifth (if given) if the version
  399. expression is false.
  400. Example:
  401. #fs/reiserfs/Makefile
  402. ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
  403. In this example, ccflags-y will be assigned the value -O1 if the
  404. $(CC) version is less than 4.2.
  405. cc-ifversion takes all the shell operators:
  406. -eq, -ne, -lt, -le, -gt, and -ge
  407. The third parameter may be a text as in this example, but it may also
  408. be an expanded variable or a macro.
  409. cc-fullversion
  410. cc-fullversion is useful when the exact version of gcc is needed.
  411. One typical use-case is when a specific GCC version is broken.
  412. cc-fullversion points out a more specific version than cc-version does.
  413. Example:
  414. #arch/powerpc/Makefile
  415. $(Q)if test "$(cc-fullversion)" = "040200" ; then \
  416. echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \
  417. false ; \
  418. fi
  419. In this example for a specific GCC version the build will error out
  420. explaining to the user why it stops.
  421. cc-cross-prefix
  422. cc-cross-prefix is used to check if there exists a $(CC) in path with
  423. one of the listed prefixes. The first prefix where there exist a
  424. prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found
  425. then nothing is returned.
  426. Additional prefixes are separated by a single space in the
  427. call of cc-cross-prefix.
  428. This functionality is useful for architecture Makefiles that try
  429. to set CROSS_COMPILE to well-known values but may have several
  430. values to select between.
  431. It is recommended only to try to set CROSS_COMPILE if it is a cross
  432. build (host arch is different from target arch). And if CROSS_COMPILE
  433. is already set then leave it with the old value.
  434. Example:
  435. #arch/m68k/Makefile
  436. ifneq ($(SUBARCH),$(ARCH))
  437. ifeq ($(CROSS_COMPILE),)
  438. CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-)
  439. endif
  440. endif
  441. --- 3.12 $(LD) support functions
  442. ld-option
  443. ld-option is used to check if $(LD) supports the supplied option.
  444. ld-option takes two options as arguments.
  445. The second argument is an optional option that can be used if the
  446. first option is not supported by $(LD).
  447. Example:
  448. #Makefile
  449. LDFLAGS_vmlinux += $(call ld-option, -X)
  450. === 4 Host Program support
  451. Kbuild supports building executables on the host for use during the
  452. compilation stage.
  453. Two steps are required in order to use a host executable.
  454. The first step is to tell kbuild that a host program exists. This is
  455. done utilising the variable hostprogs-y.
  456. The second step is to add an explicit dependency to the executable.
  457. This can be done in two ways. Either add the dependency in a rule,
  458. or utilise the variable $(always).
  459. Both possibilities are described in the following.
  460. --- 4.1 Simple Host Program
  461. In some cases there is a need to compile and run a program on the
  462. computer where the build is running.
  463. The following line tells kbuild that the program bin2hex shall be
  464. built on the build host.
  465. Example:
  466. hostprogs-y := bin2hex
  467. Kbuild assumes in the above example that bin2hex is made from a single
  468. c-source file named bin2hex.c located in the same directory as
  469. the Makefile.
  470. --- 4.2 Composite Host Programs
  471. Host programs can be made up based on composite objects.
  472. The syntax used to define composite objects for host programs is
  473. similar to the syntax used for kernel objects.
  474. $(<executable>-objs) lists all objects used to link the final
  475. executable.
  476. Example:
  477. #scripts/lxdialog/Makefile
  478. hostprogs-y := lxdialog
  479. lxdialog-objs := checklist.o lxdialog.o
  480. Objects with extension .o are compiled from the corresponding .c
  481. files. In the above example, checklist.c is compiled to checklist.o
  482. and lxdialog.c is compiled to lxdialog.o.
  483. Finally, the two .o files are linked to the executable, lxdialog.
  484. Note: The syntax <executable>-y is not permitted for host-programs.
  485. --- 4.3 Using C++ for host programs
  486. kbuild offers support for host programs written in C++. This was
  487. introduced solely to support kconfig, and is not recommended
  488. for general use.
  489. Example:
  490. #scripts/kconfig/Makefile
  491. hostprogs-y := qconf
  492. qconf-cxxobjs := qconf.o
  493. In the example above the executable is composed of the C++ file
  494. qconf.cc - identified by $(qconf-cxxobjs).
  495. If qconf is composed of a mixture of .c and .cc files, then an
  496. additional line can be used to identify this.
  497. Example:
  498. #scripts/kconfig/Makefile
  499. hostprogs-y := qconf
  500. qconf-cxxobjs := qconf.o
  501. qconf-objs := check.o
  502. --- 4.4 Controlling compiler options for host programs
  503. When compiling host programs, it is possible to set specific flags.
  504. The programs will always be compiled utilising $(HOSTCC) passed
  505. the options specified in $(HOSTCFLAGS).
  506. To set flags that will take effect for all host programs created
  507. in that Makefile, use the variable HOST_EXTRACFLAGS.
  508. Example:
  509. #scripts/lxdialog/Makefile
  510. HOST_EXTRACFLAGS += -I/usr/include/ncurses
  511. To set specific flags for a single file the following construction
  512. is used:
  513. Example:
  514. #arch/ppc64/boot/Makefile
  515. HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE)
  516. It is also possible to specify additional options to the linker.
  517. Example:
  518. #scripts/kconfig/Makefile
  519. HOSTLOADLIBES_qconf := -L$(QTDIR)/lib
  520. When linking qconf, it will be passed the extra option
  521. "-L$(QTDIR)/lib".
  522. --- 4.5 When host programs are actually built
  523. Kbuild will only build host-programs when they are referenced
  524. as a prerequisite.
  525. This is possible in two ways:
  526. (1) List the prerequisite explicitly in a special rule.
  527. Example:
  528. #drivers/pci/Makefile
  529. hostprogs-y := gen-devlist
  530. $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
  531. ( cd $(obj); ./gen-devlist ) < $<
  532. The target $(obj)/devlist.h will not be built before
  533. $(obj)/gen-devlist is updated. Note that references to
  534. the host programs in special rules must be prefixed with $(obj).
  535. (2) Use $(always)
  536. When there is no suitable special rule, and the host program
  537. shall be built when a makefile is entered, the $(always)
  538. variable shall be used.
  539. Example:
  540. #scripts/lxdialog/Makefile
  541. hostprogs-y := lxdialog
  542. always := $(hostprogs-y)
  543. This will tell kbuild to build lxdialog even if not referenced in
  544. any rule.
  545. --- 4.6 Using hostprogs-$(CONFIG_FOO)
  546. A typical pattern in a Kbuild file looks like this:
  547. Example:
  548. #scripts/Makefile
  549. hostprogs-$(CONFIG_KALLSYMS) += kallsyms
  550. Kbuild knows about both 'y' for built-in and 'm' for module.
  551. So if a config symbol evaluates to 'm', kbuild will still build
  552. the binary. In other words, Kbuild handles hostprogs-m exactly
  553. like hostprogs-y. But only hostprogs-y is recommended to be used
  554. when no CONFIG symbols are involved.
  555. === 5 Kbuild clean infrastructure
  556. "make clean" deletes most generated files in the obj tree where the kernel
  557. is compiled. This includes generated files such as host programs.
  558. Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always),
  559. $(extra-y) and $(targets). They are all deleted during "make clean".
  560. Files matching the patterns "*.[oas]", "*.ko", plus some additional files
  561. generated by kbuild are deleted all over the kernel src tree when
  562. "make clean" is executed.
  563. Additional files can be specified in kbuild makefiles by use of $(clean-files).
  564. Example:
  565. #lib/Makefile
  566. clean-files := crc32table.h
  567. When executing "make clean", the file "crc32table.h" will be deleted.
  568. Kbuild will assume files to be in the same relative directory as the
  569. Makefile, except if prefixed with $(objtree).
  570. To delete a directory hierarchy use:
  571. Example:
  572. #scripts/package/Makefile
  573. clean-dirs := $(objtree)/debian/
  574. This will delete the directory debian in the toplevel directory, including all
  575. subdirectories.
  576. To exclude certain files from make clean, use the $(no-clean-files) variable.
  577. This is only a special case used in the top level Kbuild file:
  578. Example:
  579. #Kbuild
  580. no-clean-files := $(bounds-file) $(offsets-file)
  581. Usually kbuild descends down in subdirectories due to "obj-* := dir/",
  582. but in the architecture makefiles where the kbuild infrastructure
  583. is not sufficient this sometimes needs to be explicit.
  584. Example:
  585. #arch/x86/boot/Makefile
  586. subdir- := compressed/
  587. The above assignment instructs kbuild to descend down in the
  588. directory compressed/ when "make clean" is executed.
  589. To support the clean infrastructure in the Makefiles that build the
  590. final bootimage there is an optional target named archclean:
  591. Example:
  592. #arch/x86/Makefile
  593. archclean:
  594. $(Q)$(MAKE) $(clean)=arch/x86/boot
  595. When "make clean" is executed, make will descend down in arch/x86/boot,
  596. and clean as usual. The Makefile located in arch/x86/boot/ may use
  597. the subdir- trick to descend further down.
  598. Note 1: arch/$(ARCH)/Makefile cannot use "subdir-", because that file is
  599. included in the top level makefile, and the kbuild infrastructure
  600. is not operational at that point.
  601. Note 2: All directories listed in core-y, libs-y, drivers-y and net-y will
  602. be visited during "make clean".
  603. === 6 Architecture Makefiles
  604. The top level Makefile sets up the environment and does the preparation,
  605. before starting to descend down in the individual directories.
  606. The top level makefile contains the generic part, whereas
  607. arch/$(ARCH)/Makefile contains what is required to set up kbuild
  608. for said architecture.
  609. To do so, arch/$(ARCH)/Makefile sets up a number of variables and defines
  610. a few targets.
  611. When kbuild executes, the following steps are followed (roughly):
  612. 1) Configuration of the kernel => produce .config
  613. 2) Store kernel version in include/linux/version.h
  614. 3) Updating all other prerequisites to the target prepare:
  615. - Additional prerequisites are specified in arch/$(ARCH)/Makefile
  616. 4) Recursively descend down in all directories listed in
  617. init-* core* drivers-* net-* libs-* and build all targets.
  618. - The values of the above variables are expanded in arch/$(ARCH)/Makefile.
  619. 5) All object files are then linked and the resulting file vmlinux is
  620. located at the root of the obj tree.
  621. The very first objects linked are listed in head-y, assigned by
  622. arch/$(ARCH)/Makefile.
  623. 6) Finally, the architecture-specific part does any required post processing
  624. and builds the final bootimage.
  625. - This includes building boot records
  626. - Preparing initrd images and the like
  627. --- 6.1 Set variables to tweak the build to the architecture
  628. LDFLAGS Generic $(LD) options
  629. Flags used for all invocations of the linker.
  630. Often specifying the emulation is sufficient.
  631. Example:
  632. #arch/s390/Makefile
  633. LDFLAGS := -m elf_s390
  634. Note: ldflags-y can be used to further customise
  635. the flags used. See chapter 3.7.
  636. LDFLAGS_MODULE Options for $(LD) when linking modules
  637. LDFLAGS_MODULE is used to set specific flags for $(LD) when
  638. linking the .ko files used for modules.
  639. Default is "-r", for relocatable output.
  640. LDFLAGS_vmlinux Options for $(LD) when linking vmlinux
  641. LDFLAGS_vmlinux is used to specify additional flags to pass to
  642. the linker when linking the final vmlinux image.
  643. LDFLAGS_vmlinux uses the LDFLAGS_$@ support.
  644. Example:
  645. #arch/x86/Makefile
  646. LDFLAGS_vmlinux := -e stext
  647. OBJCOPYFLAGS objcopy flags
  648. When $(call if_changed,objcopy) is used to translate a .o file,
  649. the flags specified in OBJCOPYFLAGS will be used.
  650. $(call if_changed,objcopy) is often used to generate raw binaries on
  651. vmlinux.
  652. Example:
  653. #arch/s390/Makefile
  654. OBJCOPYFLAGS := -O binary
  655. #arch/s390/boot/Makefile
  656. $(obj)/image: vmlinux FORCE
  657. $(call if_changed,objcopy)
  658. In this example, the binary $(obj)/image is a binary version of
  659. vmlinux. The usage of $(call if_changed,xxx) will be described later.
  660. KBUILD_AFLAGS $(AS) assembler flags
  661. Default value - see top level Makefile
  662. Append or modify as required per architecture.
  663. Example:
  664. #arch/sparc64/Makefile
  665. KBUILD_AFLAGS += -m64 -mcpu=ultrasparc
  666. KBUILD_CFLAGS $(CC) compiler flags
  667. Default value - see top level Makefile
  668. Append or modify as required per architecture.
  669. Often, the KBUILD_CFLAGS variable depends on the configuration.
  670. Example:
  671. #arch/x86/boot/compressed/Makefile
  672. cflags-$(CONFIG_X86_32) := -march=i386
  673. cflags-$(CONFIG_X86_64) := -mcmodel=small
  674. KBUILD_CFLAGS += $(cflags-y)
  675. Many arch Makefiles dynamically run the target C compiler to
  676. probe supported options:
  677. #arch/x86/Makefile
  678. ...
  679. cflags-$(CONFIG_MPENTIUMII) += $(call cc-option,\
  680. -march=pentium2,-march=i686)
  681. ...
  682. # Disable unit-at-a-time mode ...
  683. KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time)
  684. ...
  685. The first example utilises the trick that a config option expands
  686. to 'y' when selected.
  687. KBUILD_AFLAGS_KERNEL $(AS) options specific for built-in
  688. $(KBUILD_AFLAGS_KERNEL) contains extra C compiler flags used to compile
  689. resident kernel code.
  690. KBUILD_AFLAGS_MODULE Options for $(AS) when building modules
  691. $(KBUILD_AFLAGS_MODULE) is used to add arch-specific options that
  692. are used for $(AS).
  693. From commandline AFLAGS_MODULE shall be used (see kbuild.txt).
  694. KBUILD_CFLAGS_KERNEL $(CC) options specific for built-in
  695. $(KBUILD_CFLAGS_KERNEL) contains extra C compiler flags used to compile
  696. resident kernel code.
  697. KBUILD_CFLAGS_MODULE Options for $(CC) when building modules
  698. $(KBUILD_CFLAGS_MODULE) is used to add arch-specific options that
  699. are used for $(CC).
  700. From commandline CFLAGS_MODULE shall be used (see kbuild.txt).
  701. KBUILD_LDFLAGS_MODULE Options for $(LD) when linking modules
  702. $(KBUILD_LDFLAGS_MODULE) is used to add arch-specific options
  703. used when linking modules. This is often a linker script.
  704. From commandline LDFLAGS_MODULE shall be used (see kbuild.txt).
  705. KBUILD_ARFLAGS Options for $(AR) when creating archives
  706. $(KBUILD_ARFLAGS) set by the top level Makefile to "D" (deterministic
  707. mode) if this option is supported by $(AR).
  708. ARCH_CPPFLAGS, ARCH_AFLAGS, ARCH_CFLAGS Overrides the kbuild defaults
  709. These variables are appended to the KBUILD_CPPFLAGS,
  710. KBUILD_AFLAGS, and KBUILD_CFLAGS, respectively, after the
  711. top-level Makefile has set any other flags. This provides a
  712. means for an architecture to override the defaults.
  713. --- 6.2 Add prerequisites to archheaders:
  714. The archheaders: rule is used to generate header files that
  715. may be installed into user space by "make header_install" or
  716. "make headers_install_all". In order to support
  717. "make headers_install_all", this target has to be able to run
  718. on an unconfigured tree, or a tree configured for another
  719. architecture.
  720. It is run before "make archprepare" when run on the
  721. architecture itself.
  722. --- 6.3 Add prerequisites to archprepare:
  723. The archprepare: rule is used to list prerequisites that need to be
  724. built before starting to descend down in the subdirectories.
  725. This is usually used for header files containing assembler constants.
  726. Example:
  727. #arch/arm/Makefile
  728. archprepare: maketools
  729. In this example, the file target maketools will be processed
  730. before descending down in the subdirectories.
  731. See also chapter XXX-TODO that describe how kbuild supports
  732. generating offset header files.
  733. --- 6.4 List directories to visit when descending
  734. An arch Makefile cooperates with the top Makefile to define variables
  735. which specify how to build the vmlinux file. Note that there is no
  736. corresponding arch-specific section for modules; the module-building
  737. machinery is all architecture-independent.
  738. head-y, init-y, core-y, libs-y, drivers-y, net-y
  739. $(head-y) lists objects to be linked first in vmlinux.
  740. $(libs-y) lists directories where a lib.a archive can be located.
  741. The rest list directories where a built-in.o object file can be
  742. located.
  743. $(init-y) objects will be located after $(head-y).
  744. Then the rest follows in this order:
  745. $(core-y), $(libs-y), $(drivers-y) and $(net-y).
  746. The top level Makefile defines values for all generic directories,
  747. and arch/$(ARCH)/Makefile only adds architecture-specific directories.
  748. Example:
  749. #arch/sparc64/Makefile
  750. core-y += arch/sparc64/kernel/
  751. libs-y += arch/sparc64/prom/ arch/sparc64/lib/
  752. drivers-$(CONFIG_OPROFILE) += arch/sparc64/oprofile/
  753. --- 6.5 Architecture-specific boot images
  754. An arch Makefile specifies goals that take the vmlinux file, compress
  755. it, wrap it in bootstrapping code, and copy the resulting files
  756. somewhere. This includes various kinds of installation commands.
  757. The actual goals are not standardized across architectures.
  758. It is common to locate any additional processing in a boot/
  759. directory below arch/$(ARCH)/.
  760. Kbuild does not provide any smart way to support building a
  761. target specified in boot/. Therefore arch/$(ARCH)/Makefile shall
  762. call make manually to build a target in boot/.
  763. The recommended approach is to include shortcuts in
  764. arch/$(ARCH)/Makefile, and use the full path when calling down
  765. into the arch/$(ARCH)/boot/Makefile.
  766. Example:
  767. #arch/x86/Makefile
  768. boot := arch/x86/boot
  769. bzImage: vmlinux
  770. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  771. "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke
  772. make in a subdirectory.
  773. There are no rules for naming architecture-specific targets,
  774. but executing "make help" will list all relevant targets.
  775. To support this, $(archhelp) must be defined.
  776. Example:
  777. #arch/x86/Makefile
  778. define archhelp
  779. echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)'
  780. endif
  781. When make is executed without arguments, the first goal encountered
  782. will be built. In the top level Makefile the first goal present
  783. is all:.
  784. An architecture shall always, per default, build a bootable image.
  785. In "make help", the default goal is highlighted with a '*'.
  786. Add a new prerequisite to all: to select a default goal different
  787. from vmlinux.
  788. Example:
  789. #arch/x86/Makefile
  790. all: bzImage
  791. When "make" is executed without arguments, bzImage will be built.
  792. --- 6.6 Building non-kbuild targets
  793. extra-y
  794. extra-y specifies additional targets created in the current
  795. directory, in addition to any targets specified by obj-*.
  796. Listing all targets in extra-y is required for two purposes:
  797. 1) Enable kbuild to check changes in command lines
  798. - When $(call if_changed,xxx) is used
  799. 2) kbuild knows what files to delete during "make clean"
  800. Example:
  801. #arch/x86/kernel/Makefile
  802. extra-y := head.o init_task.o
  803. In this example, extra-y is used to list object files that
  804. shall be built, but shall not be linked as part of built-in.o.
  805. --- 6.7 Commands useful for building a boot image
  806. Kbuild provides a few macros that are useful when building a
  807. boot image.
  808. if_changed
  809. if_changed is the infrastructure used for the following commands.
  810. Usage:
  811. target: source(s) FORCE
  812. $(call if_changed,ld/objcopy/gzip/...)
  813. When the rule is evaluated, it is checked to see if any files
  814. need an update, or the command line has changed since the last
  815. invocation. The latter will force a rebuild if any options
  816. to the executable have changed.
  817. Any target that utilises if_changed must be listed in $(targets),
  818. otherwise the command line check will fail, and the target will
  819. always be built.
  820. Assignments to $(targets) are without $(obj)/ prefix.
  821. if_changed may be used in conjunction with custom commands as
  822. defined in 6.8 "Custom kbuild commands".
  823. Note: It is a typical mistake to forget the FORCE prerequisite.
  824. Another common pitfall is that whitespace is sometimes
  825. significant; for instance, the below will fail (note the extra space
  826. after the comma):
  827. target: source(s) FORCE
  828. #WRONG!# $(call if_changed, ld/objcopy/gzip/...)
  829. ld
  830. Link target. Often, LDFLAGS_$@ is used to set specific options to ld.
  831. Example:
  832. #arch/x86/boot/Makefile
  833. LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary
  834. LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext
  835. targets += setup setup.o bootsect bootsect.o
  836. $(obj)/setup $(obj)/bootsect: %: %.o FORCE
  837. $(call if_changed,ld)
  838. In this example, there are two possible targets, requiring different
  839. options to the linker. The linker options are specified using the
  840. LDFLAGS_$@ syntax - one for each potential target.
  841. $(targets) are assigned all potential targets, by which kbuild knows
  842. the targets and will:
  843. 1) check for commandline changes
  844. 2) delete target during make clean
  845. The ": %: %.o" part of the prerequisite is a shorthand that
  846. frees us from listing the setup.o and bootsect.o files.
  847. Note: It is a common mistake to forget the "targets :=" assignment,
  848. resulting in the target file being recompiled for no
  849. obvious reason.
  850. objcopy
  851. Copy binary. Uses OBJCOPYFLAGS usually specified in
  852. arch/$(ARCH)/Makefile.
  853. OBJCOPYFLAGS_$@ may be used to set additional options.
  854. gzip
  855. Compress target. Use maximum compression to compress target.
  856. Example:
  857. #arch/x86/boot/compressed/Makefile
  858. $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
  859. $(call if_changed,gzip)
  860. dtc
  861. Create flattened device tree blob object suitable for linking
  862. into vmlinux. Device tree blobs linked into vmlinux are placed
  863. in an init section in the image. Platform code *must* copy the
  864. blob to non-init memory prior to calling unflatten_device_tree().
  865. To use this command, simply add *.dtb into obj-y or targets, or make
  866. some other target depend on %.dtb
  867. A central rule exists to create $(obj)/%.dtb from $(src)/%.dts;
  868. architecture Makefiles do no need to explicitly write out that rule.
  869. Example:
  870. targets += $(dtb-y)
  871. clean-files += *.dtb
  872. DTC_FLAGS ?= -p 1024
  873. --- 6.8 Custom kbuild commands
  874. When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
  875. of a command is normally displayed.
  876. To enable this behaviour for custom commands kbuild requires
  877. two variables to be set:
  878. quiet_cmd_<command> - what shall be echoed
  879. cmd_<command> - the command to execute
  880. Example:
  881. #
  882. quiet_cmd_image = BUILD $@
  883. cmd_image = $(obj)/tools/build $(BUILDFLAGS) \
  884. $(obj)/vmlinux.bin > $@
  885. targets += bzImage
  886. $(obj)/bzImage: $(obj)/vmlinux.bin $(obj)/tools/build FORCE
  887. $(call if_changed,image)
  888. @echo 'Kernel: $@ is ready'
  889. When updating the $(obj)/bzImage target, the line
  890. BUILD arch/x86/boot/bzImage
  891. will be displayed with "make KBUILD_VERBOSE=0".
  892. --- 6.9 Preprocessing linker scripts
  893. When the vmlinux image is built, the linker script
  894. arch/$(ARCH)/kernel/vmlinux.lds is used.
  895. The script is a preprocessed variant of the file vmlinux.lds.S
  896. located in the same directory.
  897. kbuild knows .lds files and includes a rule *lds.S -> *lds.
  898. Example:
  899. #arch/x86/kernel/Makefile
  900. always := vmlinux.lds
  901. #Makefile
  902. export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
  903. The assignment to $(always) is used to tell kbuild to build the
  904. target vmlinux.lds.
  905. The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the
  906. specified options when building the target vmlinux.lds.
  907. When building the *.lds target, kbuild uses the variables:
  908. KBUILD_CPPFLAGS : Set in top-level Makefile
  909. cppflags-y : May be set in the kbuild makefile
  910. CPPFLAGS_$(@F) : Target-specific flags.
  911. Note that the full filename is used in this
  912. assignment.
  913. The kbuild infrastructure for *lds files is used in several
  914. architecture-specific files.
  915. --- 6.10 Generic header files
  916. The directory include/asm-generic contains the header files
  917. that may be shared between individual architectures.
  918. The recommended approach how to use a generic header file is
  919. to list the file in the Kbuild file.
  920. See "7.2 generic-y" for further info on syntax etc.
  921. --- 6.11 Post-link pass
  922. If the file arch/xxx/Makefile.postlink exists, this makefile
  923. will be invoked for post-link objects (vmlinux and modules.ko)
  924. for architectures to run post-link passes on. Must also handle
  925. the clean target.
  926. This pass runs after kallsyms generation. If the architecture
  927. needs to modify symbol locations, rather than manipulate the
  928. kallsyms, it may be easier to add another postlink target for
  929. .tmp_vmlinux? targets to be called from link-vmlinux.sh.
  930. For example, powerpc uses this to check relocation sanity of
  931. the linked vmlinux file.
  932. === 7 Kbuild syntax for exported headers
  933. The kernel includes a set of headers that is exported to userspace.
  934. Many headers can be exported as-is but other headers require a
  935. minimal pre-processing before they are ready for user-space.
  936. The pre-processing does:
  937. - drop kernel-specific annotations
  938. - drop include of compiler.h
  939. - drop all sections that are kernel internal (guarded by ifdef __KERNEL__)
  940. All headers under include/uapi/, include/generated/uapi/,
  941. arch/<arch>/include/uapi/ and arch/<arch>/include/generated/uapi/
  942. are exported.
  943. A Kbuild file may be defined under arch/<arch>/include/uapi/asm/ and
  944. arch/<arch>/include/asm/ to list asm files coming from asm-generic.
  945. See subsequent chapter for the syntax of the Kbuild file.
  946. --- 7.1 no-export-headers
  947. no-export-headers is essentially used by include/uapi/linux/Kbuild to
  948. avoid exporting specific headers (e.g. kvm.h) on architectures that do
  949. not support it. It should be avoided as much as possible.
  950. --- 7.2 generic-y
  951. If an architecture uses a verbatim copy of a header from
  952. include/asm-generic then this is listed in the file
  953. arch/$(ARCH)/include/asm/Kbuild like this:
  954. Example:
  955. #arch/x86/include/asm/Kbuild
  956. generic-y += termios.h
  957. generic-y += rtc.h
  958. During the prepare phase of the build a wrapper include
  959. file is generated in the directory:
  960. arch/$(ARCH)/include/generated/asm
  961. When a header is exported where the architecture uses
  962. the generic header a similar wrapper is generated as part
  963. of the set of exported headers in the directory:
  964. usr/include/asm
  965. The generated wrapper will in both cases look like the following:
  966. Example: termios.h
  967. #include <asm-generic/termios.h>
  968. --- 7.3 generated-y
  969. If an architecture generates other header files alongside generic-y
  970. wrappers, generated-y specifies them.
  971. This prevents them being treated as stale asm-generic wrappers and
  972. removed.
  973. Example:
  974. #arch/x86/include/asm/Kbuild
  975. generated-y += syscalls_32.h
  976. --- 7.4 mandatory-y
  977. mandatory-y is essentially used by include/uapi/asm-generic/Kbuild.asm
  978. to define the minimum set of headers that must be exported in
  979. include/asm.
  980. The convention is to list one subdir per line and
  981. preferably in alphabetic order.
  982. === 8 Kbuild Variables
  983. The top Makefile exports the following variables:
  984. VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
  985. These variables define the current kernel version. A few arch
  986. Makefiles actually use these values directly; they should use
  987. $(KERNELRELEASE) instead.
  988. $(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic
  989. three-part version number, such as "2", "4", and "0". These three
  990. values are always numeric.
  991. $(EXTRAVERSION) defines an even tinier sublevel for pre-patches
  992. or additional patches. It is usually some non-numeric string
  993. such as "-pre4", and is often blank.
  994. KERNELRELEASE
  995. $(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable
  996. for constructing installation directory names or showing in
  997. version strings. Some arch Makefiles use it for this purpose.
  998. ARCH
  999. This variable defines the target architecture, such as "i386",
  1000. "arm", or "sparc". Some kbuild Makefiles test $(ARCH) to
  1001. determine which files to compile.
  1002. By default, the top Makefile sets $(ARCH) to be the same as the
  1003. host system architecture. For a cross build, a user may
  1004. override the value of $(ARCH) on the command line:
  1005. make ARCH=m68k ...
  1006. INSTALL_PATH
  1007. This variable defines a place for the arch Makefiles to install
  1008. the resident kernel image and System.map file.
  1009. Use this for architecture-specific install targets.
  1010. INSTALL_MOD_PATH, MODLIB
  1011. $(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module
  1012. installation. This variable is not defined in the Makefile but
  1013. may be passed in by the user if desired.
  1014. $(MODLIB) specifies the directory for module installation.
  1015. The top Makefile defines $(MODLIB) to
  1016. $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may
  1017. override this value on the command line if desired.
  1018. INSTALL_MOD_STRIP
  1019. If this variable is specified, it will cause modules to be stripped
  1020. after they are installed. If INSTALL_MOD_STRIP is '1', then the
  1021. default option --strip-debug will be used. Otherwise, the
  1022. INSTALL_MOD_STRIP value will be used as the option(s) to the strip
  1023. command.
  1024. === 9 Makefile language
  1025. The kernel Makefiles are designed to be run with GNU Make. The Makefiles
  1026. use only the documented features of GNU Make, but they do use many
  1027. GNU extensions.
  1028. GNU Make supports elementary list-processing functions. The kernel
  1029. Makefiles use a novel style of list building and manipulation with few
  1030. "if" statements.
  1031. GNU Make has two assignment operators, ":=" and "=". ":=" performs
  1032. immediate evaluation of the right-hand side and stores an actual string
  1033. into the left-hand side. "=" is like a formula definition; it stores the
  1034. right-hand side in an unevaluated form and then evaluates this form each
  1035. time the left-hand side is used.
  1036. There are some cases where "=" is appropriate. Usually, though, ":="
  1037. is the right choice.
  1038. === 10 Credits
  1039. Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
  1040. Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
  1041. Updates by Sam Ravnborg <sam@ravnborg.org>
  1042. Language QA by Jan Engelhardt <jengelh@gmx.de>
  1043. === 11 TODO
  1044. - Describe how kbuild supports shipped files with _shipped.
  1045. - Generating offset header files.
  1046. - Add more variables to section 7?