makefiles.txt 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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) specifies 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 modular 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 defines $(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 provides 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 if
  350. not 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 [ $(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 the fourth parameter
  410. if version expression is true, or the fifth (if given) if the version
  411. expression is false.
  412. Example:
  413. #fs/reiserfs/Makefile
  414. ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
  415. In this example, ccflags-y will be assigned the value -O1 if the
  416. $(CC) version is less than 4.2.
  417. cc-ifversion takes all the shell operators:
  418. -eq, -ne, -lt, -le, -gt, and -ge
  419. The third parameter may be a text as in this example, but it may also
  420. be an expanded variable or a macro.
  421. cc-fullversion
  422. cc-fullversion is useful when the exact version of gcc is needed.
  423. One typical use-case is when a specific GCC version is broken.
  424. cc-fullversion points out a more specific version than cc-version does.
  425. Example:
  426. #arch/powerpc/Makefile
  427. $(Q)if test "$(cc-fullversion)" = "040200" ; then \
  428. echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \
  429. false ; \
  430. fi
  431. In this example for a specific GCC version the build will error out
  432. explaining to the user why it stops.
  433. cc-cross-prefix
  434. cc-cross-prefix is used to check if there exists a $(CC) in path with
  435. one of the listed prefixes. The first prefix where there exist a
  436. prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found
  437. then nothing is returned.
  438. Additional prefixes are separated by a single space in the
  439. call of cc-cross-prefix.
  440. This functionality is useful for architecture Makefiles that try
  441. to set CROSS_COMPILE to well-known values but may have several
  442. values to select between.
  443. It is recommended only to try to set CROSS_COMPILE if it is a cross
  444. build (host arch is different from target arch). And if CROSS_COMPILE
  445. is already set then leave it with the old value.
  446. Example:
  447. #arch/m68k/Makefile
  448. ifneq ($(SUBARCH),$(ARCH))
  449. ifeq ($(CROSS_COMPILE),)
  450. CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-)
  451. endif
  452. endif
  453. --- 3.12 $(LD) support functions
  454. ld-option
  455. ld-option is used to check if $(LD) supports the supplied option.
  456. ld-option takes two options as arguments.
  457. The second argument is an optional option that can be used if the
  458. first option is not supported by $(LD).
  459. Example:
  460. #Makefile
  461. LDFLAGS_vmlinux += $(call ld-option, -X)
  462. === 4 Host Program support
  463. Kbuild supports building executables on the host for use during the
  464. compilation stage.
  465. Two steps are required in order to use a host executable.
  466. The first step is to tell kbuild that a host program exists. This is
  467. done utilising the variable hostprogs-y.
  468. The second step is to add an explicit dependency to the executable.
  469. This can be done in two ways. Either add the dependency in a rule,
  470. or utilise the variable $(always).
  471. Both possibilities are described in the following.
  472. --- 4.1 Simple Host Program
  473. In some cases there is a need to compile and run a program on the
  474. computer where the build is running.
  475. The following line tells kbuild that the program bin2hex shall be
  476. built on the build host.
  477. Example:
  478. hostprogs-y := bin2hex
  479. Kbuild assumes in the above example that bin2hex is made from a single
  480. c-source file named bin2hex.c located in the same directory as
  481. the Makefile.
  482. --- 4.2 Composite Host Programs
  483. Host programs can be made up based on composite objects.
  484. The syntax used to define composite objects for host programs is
  485. similar to the syntax used for kernel objects.
  486. $(<executable>-objs) lists all objects used to link the final
  487. executable.
  488. Example:
  489. #scripts/lxdialog/Makefile
  490. hostprogs-y := lxdialog
  491. lxdialog-objs := checklist.o lxdialog.o
  492. Objects with extension .o are compiled from the corresponding .c
  493. files. In the above example, checklist.c is compiled to checklist.o
  494. and lxdialog.c is compiled to lxdialog.o.
  495. Finally, the two .o files are linked to the executable, lxdialog.
  496. Note: The syntax <executable>-y is not permitted for host-programs.
  497. --- 4.3 Using C++ for host programs
  498. kbuild offers support for host programs written in C++. This was
  499. introduced solely to support kconfig, and is not recommended
  500. for general use.
  501. Example:
  502. #scripts/kconfig/Makefile
  503. hostprogs-y := qconf
  504. qconf-cxxobjs := qconf.o
  505. In the example above the executable is composed of the C++ file
  506. qconf.cc - identified by $(qconf-cxxobjs).
  507. If qconf is composed of a mixture of .c and .cc files, then an
  508. additional line can be used to identify this.
  509. Example:
  510. #scripts/kconfig/Makefile
  511. hostprogs-y := qconf
  512. qconf-cxxobjs := qconf.o
  513. qconf-objs := check.o
  514. --- 4.4 Controlling compiler options for host programs
  515. When compiling host programs, it is possible to set specific flags.
  516. The programs will always be compiled utilising $(HOSTCC) passed
  517. the options specified in $(HOSTCFLAGS).
  518. To set flags that will take effect for all host programs created
  519. in that Makefile, use the variable HOST_EXTRACFLAGS.
  520. Example:
  521. #scripts/lxdialog/Makefile
  522. HOST_EXTRACFLAGS += -I/usr/include/ncurses
  523. To set specific flags for a single file the following construction
  524. is used:
  525. Example:
  526. #arch/ppc64/boot/Makefile
  527. HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE)
  528. It is also possible to specify additional options to the linker.
  529. Example:
  530. #scripts/kconfig/Makefile
  531. HOSTLOADLIBES_qconf := -L$(QTDIR)/lib
  532. When linking qconf, it will be passed the extra option
  533. "-L$(QTDIR)/lib".
  534. --- 4.5 When host programs are actually built
  535. Kbuild will only build host-programs when they are referenced
  536. as a prerequisite.
  537. This is possible in two ways:
  538. (1) List the prerequisite explicitly in a special rule.
  539. Example:
  540. #drivers/pci/Makefile
  541. hostprogs-y := gen-devlist
  542. $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
  543. ( cd $(obj); ./gen-devlist ) < $<
  544. The target $(obj)/devlist.h will not be built before
  545. $(obj)/gen-devlist is updated. Note that references to
  546. the host programs in special rules must be prefixed with $(obj).
  547. (2) Use $(always)
  548. When there is no suitable special rule, and the host program
  549. shall be built when a makefile is entered, the $(always)
  550. variable shall be used.
  551. Example:
  552. #scripts/lxdialog/Makefile
  553. hostprogs-y := lxdialog
  554. always := $(hostprogs-y)
  555. This will tell kbuild to build lxdialog even if not referenced in
  556. any rule.
  557. --- 4.6 Using hostprogs-$(CONFIG_FOO)
  558. A typical pattern in a Kbuild file looks like this:
  559. Example:
  560. #scripts/Makefile
  561. hostprogs-$(CONFIG_KALLSYMS) += kallsyms
  562. Kbuild knows about both 'y' for built-in and 'm' for module.
  563. So if a config symbol evaluates to 'm', kbuild will still build
  564. the binary. In other words, Kbuild handles hostprogs-m exactly
  565. like hostprogs-y. But only hostprogs-y is recommended to be used
  566. when no CONFIG symbols are involved.
  567. === 5 Kbuild clean infrastructure
  568. "make clean" deletes most generated files in the obj tree where the kernel
  569. is compiled. This includes generated files such as host programs.
  570. Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always),
  571. $(extra-y) and $(targets). They are all deleted during "make clean".
  572. Files matching the patterns "*.[oas]", "*.ko", plus some additional files
  573. generated by kbuild are deleted all over the kernel src tree when
  574. "make clean" is executed.
  575. Additional files can be specified in kbuild makefiles by use of $(clean-files).
  576. Example:
  577. #lib/Makefile
  578. clean-files := crc32table.h
  579. When executing "make clean", the file "crc32table.h" will be deleted.
  580. Kbuild will assume files to be in the same relative directory as the
  581. Makefile, except if prefixed with $(objtree).
  582. To delete a directory hierarchy use:
  583. Example:
  584. #scripts/package/Makefile
  585. clean-dirs := $(objtree)/debian/
  586. This will delete the directory debian in the toplevel directory, including all
  587. subdirectories.
  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 build 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) Updating all other prerequisites to the target prepare:
  627. - Additional prerequisites are specified in arch/$(ARCH)/Makefile
  628. 4) Recursively descend down in all directories listed in
  629. init-* core* drivers-* net-* libs-* and build all targets.
  630. - The values of the above variables are expanded in arch/$(ARCH)/Makefile.
  631. 5) All object files are then linked and the resulting file vmlinux is
  632. located at the root of the obj tree.
  633. The very first objects linked are listed in head-y, assigned by
  634. arch/$(ARCH)/Makefile.
  635. 6) Finally, the architecture-specific part does any required post processing
  636. and builds the final bootimage.
  637. - This includes building boot records
  638. - Preparing initrd images and the like
  639. --- 6.1 Set variables to tweak the build to the architecture
  640. LDFLAGS Generic $(LD) options
  641. Flags used for all invocations of the linker.
  642. Often specifying the emulation is sufficient.
  643. Example:
  644. #arch/s390/Makefile
  645. LDFLAGS := -m elf_s390
  646. Note: ldflags-y can be used to further customise
  647. the flags used. See chapter 3.7.
  648. LDFLAGS_MODULE Options for $(LD) when linking modules
  649. LDFLAGS_MODULE is used to set specific flags for $(LD) when
  650. linking the .ko files used for modules.
  651. Default is "-r", for relocatable output.
  652. LDFLAGS_vmlinux Options for $(LD) when linking vmlinux
  653. LDFLAGS_vmlinux is used to specify additional flags to pass to
  654. the linker when linking the final vmlinux image.
  655. LDFLAGS_vmlinux uses the LDFLAGS_$@ support.
  656. Example:
  657. #arch/x86/Makefile
  658. LDFLAGS_vmlinux := -e stext
  659. OBJCOPYFLAGS objcopy flags
  660. When $(call if_changed,objcopy) is used to translate a .o file,
  661. the flags specified in OBJCOPYFLAGS will be used.
  662. $(call if_changed,objcopy) is often used to generate raw binaries on
  663. vmlinux.
  664. Example:
  665. #arch/s390/Makefile
  666. OBJCOPYFLAGS := -O binary
  667. #arch/s390/boot/Makefile
  668. $(obj)/image: vmlinux FORCE
  669. $(call if_changed,objcopy)
  670. In this example, the binary $(obj)/image is a binary version of
  671. vmlinux. The usage of $(call if_changed,xxx) will be described later.
  672. KBUILD_AFLAGS $(AS) assembler flags
  673. Default value - see top level Makefile
  674. Append or modify as required per architecture.
  675. Example:
  676. #arch/sparc64/Makefile
  677. KBUILD_AFLAGS += -m64 -mcpu=ultrasparc
  678. KBUILD_CFLAGS $(CC) compiler flags
  679. Default value - see top level Makefile
  680. Append or modify as required per architecture.
  681. Often, the KBUILD_CFLAGS variable depends on the configuration.
  682. Example:
  683. #arch/x86/boot/compressed/Makefile
  684. cflags-$(CONFIG_X86_32) := -march=i386
  685. cflags-$(CONFIG_X86_64) := -mcmodel=small
  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. ARCH_CPPFLAGS, ARCH_AFLAGS, ARCH_CFLAGS Overrides the kbuild defaults
  721. These variables are appended to the KBUILD_CPPFLAGS,
  722. KBUILD_AFLAGS, and KBUILD_CFLAGS, respectively, after the
  723. top-level Makefile has set any other flags. This provides a
  724. means for an architecture to override the defaults.
  725. --- 6.2 Add prerequisites to archheaders:
  726. The archheaders: rule is used to generate header files that
  727. may be installed into user space by "make header_install" or
  728. "make headers_install_all". In order to support
  729. "make headers_install_all", this target has to be able to run
  730. on an unconfigured tree, or a tree configured for another
  731. architecture.
  732. It is run before "make archprepare" when run on the
  733. architecture itself.
  734. --- 6.3 Add prerequisites to archprepare:
  735. The archprepare: rule is used to list prerequisites that need to be
  736. built before starting to descend down in the subdirectories.
  737. This is usually used for header files containing assembler constants.
  738. Example:
  739. #arch/arm/Makefile
  740. archprepare: maketools
  741. In this example, the file target maketools will be processed
  742. before descending down in the subdirectories.
  743. See also chapter XXX-TODO that describe how kbuild supports
  744. generating offset header files.
  745. --- 6.4 List directories to visit when descending
  746. An arch Makefile cooperates with the top Makefile to define variables
  747. which specify how to build the vmlinux file. Note that there is no
  748. corresponding arch-specific section for modules; the module-building
  749. machinery is all architecture-independent.
  750. head-y, init-y, core-y, libs-y, drivers-y, net-y
  751. $(head-y) lists objects to be linked first in vmlinux.
  752. $(libs-y) lists directories where a lib.a archive can be located.
  753. The rest list directories where a built-in.o object file can be
  754. located.
  755. $(init-y) objects will be located after $(head-y).
  756. Then the rest follows in this order:
  757. $(core-y), $(libs-y), $(drivers-y) and $(net-y).
  758. The top level Makefile defines values for all generic directories,
  759. and arch/$(ARCH)/Makefile only adds architecture-specific directories.
  760. Example:
  761. #arch/sparc64/Makefile
  762. core-y += arch/sparc64/kernel/
  763. libs-y += arch/sparc64/prom/ arch/sparc64/lib/
  764. drivers-$(CONFIG_OPROFILE) += arch/sparc64/oprofile/
  765. --- 6.5 Architecture-specific boot images
  766. An arch Makefile specifies goals that take the vmlinux file, compress
  767. it, wrap it in bootstrapping code, and copy the resulting files
  768. somewhere. This includes various kinds of installation commands.
  769. The actual goals are not standardized across architectures.
  770. It is common to locate any additional processing in a boot/
  771. directory below arch/$(ARCH)/.
  772. Kbuild does not provide any smart way to support building a
  773. target specified in boot/. Therefore arch/$(ARCH)/Makefile shall
  774. call make manually to build a target in boot/.
  775. The recommended approach is to include shortcuts in
  776. arch/$(ARCH)/Makefile, and use the full path when calling down
  777. into the arch/$(ARCH)/boot/Makefile.
  778. Example:
  779. #arch/x86/Makefile
  780. boot := arch/x86/boot
  781. bzImage: vmlinux
  782. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  783. "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke
  784. make in a subdirectory.
  785. There are no rules for naming architecture-specific targets,
  786. but executing "make help" will list all relevant targets.
  787. To support this, $(archhelp) must be defined.
  788. Example:
  789. #arch/x86/Makefile
  790. define archhelp
  791. echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)'
  792. endif
  793. When make is executed without arguments, the first goal encountered
  794. will be built. In the top level Makefile the first goal present
  795. is all:.
  796. An architecture shall always, per default, build a bootable image.
  797. In "make help", the default goal is highlighted with a '*'.
  798. Add a new prerequisite to all: to select a default goal different
  799. from vmlinux.
  800. Example:
  801. #arch/x86/Makefile
  802. all: bzImage
  803. When "make" is executed without arguments, bzImage will be built.
  804. --- 6.6 Building non-kbuild targets
  805. extra-y
  806. extra-y specifies additional targets created in the current
  807. directory, in addition to any targets specified by obj-*.
  808. Listing all targets in extra-y is required for two purposes:
  809. 1) Enable kbuild to check changes in command lines
  810. - When $(call if_changed,xxx) is used
  811. 2) kbuild knows what files to delete during "make clean"
  812. Example:
  813. #arch/x86/kernel/Makefile
  814. extra-y := head.o init_task.o
  815. In this example, extra-y is used to list object files that
  816. shall be built, but shall not be linked as part of built-in.o.
  817. --- 6.7 Commands useful for building a boot image
  818. Kbuild provides a few macros that are useful when building a
  819. boot image.
  820. if_changed
  821. if_changed is the infrastructure used for the following commands.
  822. Usage:
  823. target: source(s) FORCE
  824. $(call if_changed,ld/objcopy/gzip/...)
  825. When the rule is evaluated, it is checked to see if any files
  826. need an update, or the command line has changed since the last
  827. invocation. The latter will force a rebuild if any options
  828. to the executable have changed.
  829. Any target that utilises if_changed must be listed in $(targets),
  830. otherwise the command line check will fail, and the target will
  831. always be built.
  832. Assignments to $(targets) are without $(obj)/ prefix.
  833. if_changed may be used in conjunction with custom commands as
  834. defined in 6.8 "Custom kbuild commands".
  835. Note: It is a typical mistake to forget the FORCE prerequisite.
  836. Another common pitfall is that whitespace is sometimes
  837. significant; for instance, the below will fail (note the extra space
  838. after the comma):
  839. target: source(s) FORCE
  840. #WRONG!# $(call if_changed, ld/objcopy/gzip/...)
  841. ld
  842. Link target. Often, LDFLAGS_$@ is used to set specific options to ld.
  843. objcopy
  844. Copy binary. Uses OBJCOPYFLAGS usually specified in
  845. arch/$(ARCH)/Makefile.
  846. OBJCOPYFLAGS_$@ may be used to set additional options.
  847. gzip
  848. Compress target. Use maximum compression to compress target.
  849. Example:
  850. #arch/x86/boot/Makefile
  851. LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary
  852. LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext
  853. targets += setup setup.o bootsect bootsect.o
  854. $(obj)/setup $(obj)/bootsect: %: %.o FORCE
  855. $(call if_changed,ld)
  856. In this example, there are two possible targets, requiring different
  857. options to the linker. The linker options are specified using the
  858. LDFLAGS_$@ syntax - one for each potential target.
  859. $(targets) are assigned all potential targets, by which kbuild knows
  860. the targets and will:
  861. 1) check for commandline changes
  862. 2) delete target during make clean
  863. The ": %: %.o" part of the prerequisite is a shorthand that
  864. frees us from listing the setup.o and bootsect.o files.
  865. Note: It is a common mistake to forget the "targets :=" assignment,
  866. resulting in the target file being recompiled for no
  867. obvious reason.
  868. dtc
  869. Create flattened device tree blob object suitable for linking
  870. into vmlinux. Device tree blobs linked into vmlinux are placed
  871. in an init section in the image. Platform code *must* copy the
  872. blob to non-init memory prior to calling unflatten_device_tree().
  873. To use this command, simply add *.dtb into obj-y or targets, or make
  874. some other target depend on %.dtb
  875. A central rule exists to create $(obj)/%.dtb from $(src)/%.dts;
  876. architecture Makefiles do no need to explicitly write out that rule.
  877. Example:
  878. targets += $(dtb-y)
  879. clean-files += *.dtb
  880. DTC_FLAGS ?= -p 1024
  881. --- 6.8 Custom kbuild commands
  882. When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
  883. of a command is normally displayed.
  884. To enable this behaviour for custom commands kbuild requires
  885. two variables to be set:
  886. quiet_cmd_<command> - what shall be echoed
  887. cmd_<command> - the command to execute
  888. Example:
  889. #
  890. quiet_cmd_image = BUILD $@
  891. cmd_image = $(obj)/tools/build $(BUILDFLAGS) \
  892. $(obj)/vmlinux.bin > $@
  893. targets += bzImage
  894. $(obj)/bzImage: $(obj)/vmlinux.bin $(obj)/tools/build FORCE
  895. $(call if_changed,image)
  896. @echo 'Kernel: $@ is ready'
  897. When updating the $(obj)/bzImage target, the line
  898. BUILD arch/x86/boot/bzImage
  899. will be displayed with "make KBUILD_VERBOSE=0".
  900. --- 6.9 Preprocessing linker scripts
  901. When the vmlinux image is built, the linker script
  902. arch/$(ARCH)/kernel/vmlinux.lds is used.
  903. The script is a preprocessed variant of the file vmlinux.lds.S
  904. located in the same directory.
  905. kbuild knows .lds files and includes a rule *lds.S -> *lds.
  906. Example:
  907. #arch/x86/kernel/Makefile
  908. always := vmlinux.lds
  909. #Makefile
  910. export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
  911. The assignment to $(always) is used to tell kbuild to build the
  912. target vmlinux.lds.
  913. The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the
  914. specified options when building the target vmlinux.lds.
  915. When building the *.lds target, kbuild uses the variables:
  916. KBUILD_CPPFLAGS : Set in top-level Makefile
  917. cppflags-y : May be set in the kbuild makefile
  918. CPPFLAGS_$(@F) : Target-specific flags.
  919. Note that the full filename is used in this
  920. assignment.
  921. The kbuild infrastructure for *lds files is used in several
  922. architecture-specific files.
  923. --- 6.10 Generic header files
  924. The directory include/asm-generic contains the header files
  925. that may be shared between individual architectures.
  926. The recommended approach how to use a generic header file is
  927. to list the file in the Kbuild file.
  928. See "7.4 generic-y" for further info on syntax etc.
  929. === 7 Kbuild syntax for exported headers
  930. The kernel includes a set of headers that is exported to userspace.
  931. Many headers can be exported as-is but other headers require a
  932. minimal pre-processing before they are ready for user-space.
  933. The pre-processing does:
  934. - drop kernel-specific annotations
  935. - drop include of compiler.h
  936. - drop all sections that are kernel internal (guarded by ifdef __KERNEL__)
  937. Each relevant directory contains a file name "Kbuild" which specifies the
  938. headers to be exported.
  939. See subsequent chapter for the syntax of the Kbuild file.
  940. --- 7.1 header-y
  941. header-y specifies header files to be exported.
  942. Example:
  943. #include/linux/Kbuild
  944. header-y += usb/
  945. header-y += aio_abi.h
  946. The convention is to list one file per line and
  947. preferably in alphabetic order.
  948. header-y also specifies which subdirectories to visit.
  949. A subdirectory is identified by a trailing '/' which
  950. can be seen in the example above for the usb subdirectory.
  951. Subdirectories are visited before their parent directories.
  952. --- 7.2 genhdr-y
  953. genhdr-y specifies generated files to be exported.
  954. Generated files are special as they need to be looked
  955. up in another directory when doing 'make O=...' builds.
  956. Example:
  957. #include/linux/Kbuild
  958. genhdr-y += version.h
  959. --- 7.3 destination-y
  960. When an architecture has a set of exported headers that needs to be
  961. exported to a different directory destination-y is used.
  962. destination-y specifies the destination directory for all exported
  963. headers in the file where it is present.
  964. Example:
  965. #arch/xtensa/platforms/s6105/include/platform/Kbuild
  966. destination-y := include/linux
  967. In the example above all exported headers in the Kbuild file
  968. will be located in the directory "include/linux" when exported.
  969. --- 7.4 generic-y
  970. If an architecture uses a verbatim copy of a header from
  971. include/asm-generic then this is listed in the file
  972. arch/$(ARCH)/include/asm/Kbuild like this:
  973. Example:
  974. #arch/x86/include/asm/Kbuild
  975. generic-y += termios.h
  976. generic-y += rtc.h
  977. During the prepare phase of the build a wrapper include
  978. file is generated in the directory:
  979. arch/$(ARCH)/include/generated/asm
  980. When a header is exported where the architecture uses
  981. the generic header a similar wrapper is generated as part
  982. of the set of exported headers in the directory:
  983. usr/include/asm
  984. The generated wrapper will in both cases look like the following:
  985. Example: termios.h
  986. #include <asm-generic/termios.h>
  987. === 8 Kbuild Variables
  988. The top Makefile exports the following variables:
  989. VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
  990. These variables define the current kernel version. A few arch
  991. Makefiles actually use these values directly; they should use
  992. $(KERNELRELEASE) instead.
  993. $(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic
  994. three-part version number, such as "2", "4", and "0". These three
  995. values are always numeric.
  996. $(EXTRAVERSION) defines an even tinier sublevel for pre-patches
  997. or additional patches. It is usually some non-numeric string
  998. such as "-pre4", and is often blank.
  999. KERNELRELEASE
  1000. $(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable
  1001. for constructing installation directory names or showing in
  1002. version strings. Some arch Makefiles use it for this purpose.
  1003. ARCH
  1004. This variable defines the target architecture, such as "i386",
  1005. "arm", or "sparc". Some kbuild Makefiles test $(ARCH) to
  1006. determine which files to compile.
  1007. By default, the top Makefile sets $(ARCH) to be the same as the
  1008. host system architecture. For a cross build, a user may
  1009. override the value of $(ARCH) on the command line:
  1010. make ARCH=m68k ...
  1011. INSTALL_PATH
  1012. This variable defines a place for the arch Makefiles to install
  1013. the resident kernel image and System.map file.
  1014. Use this for architecture-specific install targets.
  1015. INSTALL_MOD_PATH, MODLIB
  1016. $(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module
  1017. installation. This variable is not defined in the Makefile but
  1018. may be passed in by the user if desired.
  1019. $(MODLIB) specifies the directory for module installation.
  1020. The top Makefile defines $(MODLIB) to
  1021. $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may
  1022. override this value on the command line if desired.
  1023. INSTALL_MOD_STRIP
  1024. If this variable is specified, it will cause modules to be stripped
  1025. after they are installed. If INSTALL_MOD_STRIP is '1', then the
  1026. default option --strip-debug will be used. Otherwise, the
  1027. INSTALL_MOD_STRIP value will be used as the option(s) to the strip
  1028. command.
  1029. === 9 Makefile language
  1030. The kernel Makefiles are designed to be run with GNU Make. The Makefiles
  1031. use only the documented features of GNU Make, but they do use many
  1032. GNU extensions.
  1033. GNU Make supports elementary list-processing functions. The kernel
  1034. Makefiles use a novel style of list building and manipulation with few
  1035. "if" statements.
  1036. GNU Make has two assignment operators, ":=" and "=". ":=" performs
  1037. immediate evaluation of the right-hand side and stores an actual string
  1038. into the left-hand side. "=" is like a formula definition; it stores the
  1039. right-hand side in an unevaluated form and then evaluates this form each
  1040. time the left-hand side is used.
  1041. There are some cases where "=" is appropriate. Usually, though, ":="
  1042. is the right choice.
  1043. === 10 Credits
  1044. Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
  1045. Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
  1046. Updates by Sam Ravnborg <sam@ravnborg.org>
  1047. Language QA by Jan Engelhardt <jengelh@gmx.de>
  1048. === 11 TODO
  1049. - Describe how kbuild supports shipped files with _shipped.
  1050. - Generating offset header files.
  1051. - Add more variables to section 7?