makefiles.txt 45 KB

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