makefiles.txt 46 KB

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