makefiles.txt 47 KB

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