makefiles.txt 44 KB

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