收藏 分享(赏)

linux内核的makefile(中文版+英文版).doc

上传人:kpmy5893 文档编号:7350342 上传时间:2019-05-15 格式:DOC 页数:27 大小:427.50KB
下载 相关 举报
linux内核的makefile(中文版+英文版).doc_第1页
第1页 / 共27页
linux内核的makefile(中文版+英文版).doc_第2页
第2页 / 共27页
linux内核的makefile(中文版+英文版).doc_第3页
第3页 / 共27页
linux内核的makefile(中文版+英文版).doc_第4页
第4页 / 共27页
linux内核的makefile(中文版+英文版).doc_第5页
第5页 / 共27页
点击查看更多>>
资源描述

1、Linux 内核的 Makefile1 2 3 本文档描述了 Linux 内核的 Makefile。=表的内容6 7 = 1 概述= 2,谁做什么9 = 3 的 kbuild 文件10 - 3.1 11 - 3.2 目标定义内置对象的目标- OBJ-Y12 - 3.3 可加载模块的目标 - obj 的 13 米- 3.4 对象导出符号14 - 3.5 库文件的目标 - LIB-Y15 - 3.6 目录中的 16 - 3.7 编译标志下17 - 3.8 命令行依赖18 - 3.9 依赖关系跟踪19 - 3.10 特殊规则20 - 3.11 $(CC )支持功能21 - - 3.12 $(LD)的

2、支持功能= 4 主机程序支持24 - 4.1 简单的主机程序25 - 4.2 复合主机程序26 - 4.3 定义共享库27 - 4.4 使用 C + +为 22 23 主机方案28 - 4.5 控制编译器选项为主机程序29 - 4.6 当宿主程序实际是建30 - 4.7 使用 hostprogs-$“(CONFIG_FOO)31 32 = 5 的 Kbuild 清洁的基础设施33 34 = 6 架构的 Makefile35 - 6.1 变量设置调整构建的架构36 - 6.2 先决条件 archheaders:37 - 6.3 先决条件到 archprepare:38 - 6.4 列出目录访问时

3、降39 - - 6.5 体系结构特有的引导映像40 - 6.6 建筑非 kbuild 的目标41 - 6.7 命令可用于建设的引导映像42 - 6.8 自定义 kbuild 的命令43 - 6.9 预处理连接器脚本44 - 6.10 的通用头文件45 46 = 7 的 kbuild 语法的出口头47 - 7.1 头-Y48 - 7.2 objhdr-Y49 - 7.3 目的地- Y50 - 7.4 的通用-Y51 52 = = 8 的 Kbuild 变量53 = 9 Makefile 中的语言54 = 10 积分55 = 56 57 11 TODO= 1 概述58 59 的 Makefile

4、有五个部分:60 61 Makefile 中最顶层的 Makefile。62 。配置最顶层的 Makefile 中读取内核配置文件。63 弓/ $(ARCH )/ Makefile 中拱的 Makefile。64 脚本/ Makefile 文件。共同的规则等,为所有 kbuild 的的 Makefile。65 kbuild 的 Makefiles 中大约有 500 个,这些66 67。配置文件,来从内核配置过程68 69 70 最顶层的 Makefile 是负责建设两个主要产品:vmlinux 的71(居民内核映像)和模块(任何模块文件)。72 建立这些目标通过递归下降到 73 内核源代码树。

5、74 访问的子目录列表的子目录取决于内核的75 配置。最顶层的 Makefile 文本上有一个拱形的名称拱/ $(ARCH)/ Makefile 中的 Makefile76。拱的 Makefile 提供77 架构相关的信息,最顶层的 Makefile78 79 每个子目录下有一个的 kbuild Makefile 文件执行的命令80 从上面传下来的。kbuild 的 Makefile 将使用的81。配置文件构建各种文件列出了使用 kbuild 的建立82 任何内置或模块化的目标。83 84 脚本/ Makefile 文件。* /包含了所有的定义规则等85 用于 kbuild 的 makefil

6、e 文件的基础上构建内核。91 92 86 87 88 = 289 90 人有四种不同的关系,与内核的 Makefile。*用户*是编译内核的人。这些人的命令,如93 “make menuconfig 命令” 或 “使”。他们通常不读或编辑94 任何内核的 Makefile 中(或任何其他的源文件)。95 96 *普通开发人员 97 设备驱动程序,文件系统和网络协议的功能,如工作的人。这些人要保持 98 kbuild 的 Makefile 中的子系统,它们是99 上工作。为了有效地做到这一点,他们需要一些整体的内核的 Makefile 的知识,再加上 102 103 101 公共接口 kbui

7、ld 的详细了解。拱门开发工作的整个架构,SPARC 和 IA64 等 104 人。拱门开发人员需要了解拱的 Makefile105 以及 kbuild 的 Makefiles 的。kbuild 的开发内核构建系统本身工作的人。108 这些人都需要了解内核的 Makefile 中的各个方面。109 110 106 107 文件的目的是向正常发展和拱开发商。111 112 113 = 3 kbuild 的文件在内核中是 114 115 的 Makefile kbuild 的生成文件,使用116 的 kbuild 基础设施。本章介绍 kbuild 的 makefile 文件 117 所使用的语法。

8、118 的首选 kbuild 的文件名 是 的 Makefile,但的 Kbuild“119,如果一个Makefile和的 Kbuild“文件存在,那么” kbuild 的“120 文件将被使用。121 122 第 3.1 节“目标定义” 是一个快速的介绍,进一步章节提供123 更多细节,用真实的例子。124 125 - 3.1 目标定义126 127 目标定义的主要组成部分(心 kbuild 的 Makefile 文件)。128 行定义了文件,将建成 129 选项,任何特殊的编译和任何子目录递归可输入130 131 最简单的 kbuild Makefile 文件包含一个热线:132 133

9、例:134 OBJ-Y + =文件 foo.o135 136 告诉 kbuild 的目的之一是在该目录中,命名为137 foo.o. 文件 foo.o 将建成从 foo.c 或 foo.S.138 的 139 如果 foo.o 中应建立为一个模块,变量 obj-M。140 因此经常使用下面的模式:141 142 例:143 的 obj-$( CONFIG_FOO)+ = foo.o 中的144 145 美元(CONFIG_FOO)的计算结果为 y(内置)或 M(模块)。146, 如果 CONFIG_FOO 既不是 y 也没有米,那么该文件将不会被编译147 也不是联系在一起的。148 149

10、- 150 151 3.2 内置对象目标 - OBJ-Y的 kbuild Makefile 中指定的目标文件 vmlinux 的152 $(OBJ-Y )的列表。这些列表依赖于内核的153 配置,编译所有的 154 155 的 kbuild $(OBJ-Y )的文件。然后,它调用157 内置 in.o 后来被链接到 vmlinux 的父的 Makefile。158 159 文件的顺序( 156 “$(LD)-r”的这些文件合并到一个 built-in.o 文件。的 obj-y)是显着的。重复160 允许列表的第一个实例将被链接到161 内置 in.o 和成功的实例将被忽略。162 163 链接

11、的顺序是显着的,因为某些功能将被称为 164(module_init()/ _ initcall 的)在在 165 它们出现的顺序启动。所以记住的链接 166 为了改变,例如改变您的 SCSI 167 控制器检测到的顺序,从而 168 169 例:drivers/isdn/i4l/Makefile 170171 Makefile 中的内核的磁盘都被重新编号。ISDN 子系统和设备驱动程序。172 每一个配置选项使文件列表。173 的 obj-$( CONFIG_ISDN_I4L)+ = isdn.o 的174 的 obj-$( CONFIG_ISDN_PPP_BSDCOMP)+ = isdn_

12、bsdcomp.o 的175 176 - 3.3 可加载模块的目标 - OBJ-M177 180 181 178 $(OBJ-M)指定对象的内置的文件,这些文件可装载179 个 内核模块一个模块可以构建一个源文件或多个源182 文件。在一个源文件的情况下, 只是增加了 183 kbuild 的 makefile 文件的文件$(OBJ-M)的184 185 例:186 drivers/isdn/i4l/Makefile187 的 obj-$( CONFIG_ISDN_PPP_BSDCOMP)+ = isdn_bsdcomp.o188 189 注:在这个例子中(CONFIG_ISDN_PPP_BS

13、DCOMP)的计算结果为“M”190 191, 如果一个内核模块是建立从多个源文件,你指定192 要构建一个模块在上述同样的方式,但193 kbuild 的需求知道你要建立你的 194 模块的对象文件,所以你必须告诉它通过设置一个$(-Y)196 197 195 变量。例:198 drivers/isdn/i4l/Makefile199 OBJ (CONFIG_ISDN_I4L)+ = isdn.o200 ISDN-Y:= isdn_net_lib.o isdn_v110.o isdn_common.o201 202 在这个例子中,模块的名字将出现在 isdn.o. kbuild 的203 编

14、译对象在$(ISDN-Y )的上市,然后再运行204 “$(LD)-r”的名单上的这些文件的,产生 isdn.o.205 206 kbuild 的认识( - y)的复合对象,207 你可以使用 CONFIG_符号的价值,可以选择 作为一个复合对象的一部分,包括一个208 的目标文件。209 210 例:211 fs/ext2/Makefile212 的 obj-$( CONFIG_EXT2_FS)+ = ext2.o213 EXT2-Y:= balloc.o dir.o file.o 的 ialloc.o inode.o ioctl.o 214 namei.o super.o symlink.

15、o215 的 ext2-$(CONFIG_EXT2_FS_XATTR)+ = xattr.o 在这个例子中xattr_user.o 217 218 216 xattr_trusted.o,xattr.o,xattr_user.o 和 xattr_trusted.o,只有219 的一部分,复合对象 ext2.o 的,如果$(CONFIG_EXT2_FS_XATTR)220 计算结果为“y”。221 222 注意:当然,当你构建到内核中的对象,223 上面的语法也将正常工作。所以,如果你有 CONFIG_EXT2_FS,Y,224 kbuild 的建立一个 ext2.o 的文件,你的个人225 ,

16、然后连接到内置 in.o,正如你所期望的。226 227 - 3.4 物体导出符号228 229 无特殊符号需要在 Makefile 中的230 模块的导出符号。231 232 - 3.5 库文件的目标- LIB-Y233 234 上市与 obj-*用于模块或 235 组合在一个内置的对象lib.a. 238 -in.o 特定的目录。236 也有可能列出对象,将一个库中包含 237,用 lib-Y 列出的所有对象结合在一个单一的239 该目录库。240 中列出的对象在 OBJ-Y 和另外列出的241 的 lib-Y 将不会被包含在库中,因为他们将242 无论如何是可访问的。243 为了保持一致

17、性,在 lib-M 中列出的对象将被纳入党人244 245 注的 kbuild makefile 文件列出的文件被内置在246 库的一部分。因此,在同一目录247 可以同时包含一个内置的 in.o 和党人文件。248 249 例:250 251 LIB-Y arch/x86/lib/Makefile:252 = delay.o:253 这将创建一个库党人根据 delay.o。 目录 255 到 254 的 kbuild真正认识到,有一个 lib.a 正在兴建,应在 libs-Y 上市。256 另请参见“6.4 列出目录访问时降” 。通常只限于 257 258 使用的 lib-Y 到 lib /

18、和 arch / * / lib 目录下。259 260 - 3.6 下的目录中的261 262 的 Makefile 只负责建设自己的 263 目录中的对象。子目录中的文件应该被照顾的264 在这些子目录中的 Makefile。生成系统将自动265 子目录中的递归调用 make,只要你让它知道他们266 267 268 要做到这一点,使用的 obj-y 和 obj-M269 EXT2 生活在一个单独的目录中,和 Makefile 目前在 FS /270 告诉 kbuild 的下降,使用下面的赋值。271 272 例:273 fs / Makefile 文件中274 的 obj-$( CONF

19、IG_EXT2_FS)+ = EXT2 /275 276, 如果 CONFIG_EXT2_FS 设置为Y(内置)或“M” (模块化)277 相应的 obj-变量设置, kbuild 的将下降278 ext2 的目录中。279 的 Kbuild 只使用这些信息来决定,它需要访问280 的目录,它是 Makefile 中 281 指定的模块是什么,什么是内置的。282 283 这是很好的做法,使用 CONFIG_变量指定目录时,284 名,子目录。这使得 kbuild 的目录,如果完全跳过285 对应的的 CONFIG_选项既不是“Y也不是M。286 287 - 3.7 编译标志288 289 C

20、CFLAGS asflags-Y,Y 和 LDFLAGS-Y290 这三个标志申请的 kbuild makefile 来291 分配。它们被用于所有正常的 CC,和 以前命名的 LD292 调用发生在一个递归的构建。293 注:具有相同行为的标志:的294 EXTRA_CFLAGS,EXTRA_AFLAGS 和 EXTRA_LDFLAGS。295 他们仍然支持,但是它们的使用已过时。296 297 CCFLAGS-Y 指定的选项进行编译$(CC)298 299 例:300 驱动器/ ACPI / Makefile 文件301 CCFLAGS-Y =-O 的302 CCFLAGS 美元(CONF

21、IG_ACPI_DEBUG)+ =-DACPI_DEBUG_OUTPUT303 304 这个变量是必要的,因为顶层 Makefile 拥有305 变量$(KBUILD_CFLAGS),并用它的 306 整个树的编译选项。307 308 asflags-Y 指定用于装配$(AS)。309 310 例:311 建筑/ SPARC / 312 asflags-Y =-ANSI313 314 LDFLAGS-Y 核心/ Makefile 中指定的选项$(LD)链接。315 316 例:317 建筑/ CRIS 的/ boot /压缩/ Makefile 中318 LDFLAGS-Y + =-T $ (

22、srctree)/ $(SRC )/ decompress_ $(ARCH-Y)。 子目录 CCFLAGS-Y LDS319 320,子目录,asflags321 以上列出的这两个标志类似 CCFLAGS-Y 和 asflags 的-Y。322 “不同的是 ,它们的存在和所有子目录的子目录的的变种有效果的 kbuild 的323 文件324 使用子目录选项指定*前 325 添加到命令行指定的选项使用的非子目录的变种。326 327 示例:328 子目录 CCFLAGS-Y =-Werror329 330 CFLAGS_ $ ,AFLAGS_ $ 331 332 CFLAGS_ $ 和 AFLA

23、GS_ $ 只适用于当前 333 的 kbuild Makefile 文件中的命令。334 335 元(CFLAGS_ $ )指定每个文件选项$(CC)。$ 336 部分有指定的文件,它是一个文本值。337 338 例:339 驱动器/ SCSI / Makefile 文件340 CFLAGS_aha152x.o =-DAHA152X_STAT DAUTOCONF341 CFLAGS_gdth.o =DDEBUG_GDTH = 2 D_SERIAL_ D_COM2_ 342 -DGDTH_STATISTICS 的343 344 这两个行指定的编译选项 aha152x.o 和 gdth.o.34

24、5 346 美元(AFLAGS_ $ )是一个类似功能的源文件汇编347 种语言。348 349 例:350 拱/ ARM /内核/ Makefile 文件351 AFLAGS_head.o:= DTEXT_OFFSET = $(TEXT_OFFSET )352 AFLAGS_crunch bits.o:= 华,MCPU = EP9312353 AFLAGS_iwmmxt.o:华-MCPU = iwmmxt354 355 356 - 3.9 依赖跟踪357 358 kbuild 的轨迹依赖于以下:359 1)所有必备文件(两个*。c 和* H)360 2)CONFIG_选项中使用的所有必备文件

25、361 3)使用命令行编译目标362 363, 因此,如果您更改选项$(CC)所有受影响的文件将364 重新编译。- 3.10 特殊规则365 366 367 368 特殊规则时所使用的 kbuild 基础设施369 不提供必要的支持。一个典型的例子是370 头文件在编译过程中产生的。371 另一个例子是特定于体系结构的 Makefile372 需要特殊的规则来准备启动图像 被写入正常的规则等373 374 的特殊规则。375 kbuild 的不执行目录中的 Makefile 是位于 376,因此所有的特殊规则应提供一个相对377 路的必备文件和目标文件。378 379 两个变量定义特殊规则时

26、,使用:380 381 $(SRC)382 $(SRC)是一个相对路径,它指向 的 Makefile 所在的目录383。请务必使用$(SRC),384 指位于 src 目录树中的文件。385 386 $(obj)以387 $(OBJ)是一个相对路径,它指向 的目标是保存到目录388。请务必使用$(obj)的389 指的是生成的文件。390 391 例:392 驱动器/ SCSI / Makefile 文件393 $(OBJ )/ 53c8xx_d.h:$(SRC)/ 53c7,8xx.scr $(SRC)/ script_asm PL394 $(CPP)DCHIP = 810 - = 3.0

27、改变的类型选项用于指定491 对齐功能,循环等。$(CC-选项对齐),当使用492 作为前缀到“ 对齐”选项“,选择正确的前缀:493 GCC = 3.00496 CC-选项对齐 = falign497 498 例:499 KBUILD_CFLAGS + = $(CC-选项对齐)函数= 4500 501, 另外,在上述的例子中,选项-falign 函数= 4 的是,用于502 = 3.00。为海湾合作委员会-objs) variable.Example: #drivers/isdn/i4l/Makefileobj-$(CONFIG_ISDN) += isdn.oisdn-objs := isd

28、n_net_lib.o isdn_v110.o isdn_common.oIn this example, the module name will be isdn.o. Kbuild willcompile the objects listed in $(isdn-objs) and then run“$(LD) -r“ on the list of these files to generate isdn.o.Kbuild recognises objects used for composite objects by the suffix-objs, and the suffix -y.

29、 This allows the Makefiles to usethe value of a CONFIG_ symbol to determine if an object is partof a composite object.Example: #fs/ext2/Makefile obj-$(CONFIG_EXT2_FS) += ext2.o ext2-y := balloc.o bitmap.o ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.oIn this example, xattr.o is only part of the composite o

30、bjectext2.o if $(CONFIG_EXT2_FS_XATTR) evaluates to y.Note: Of course, when you are building objects into the kernel,the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, kbuild will build an ext2.o file for you out of the individualparts and then link this into built-in.o, as you would

31、 expect.- 3.4 Objects which export symbolsNo special notation is required in the makefiles formodules exporting symbols.- 3.5 Library file goals - lib-yObjects listed with obj-* are used for modules, orcombined in a built-in.o for that specific directory.There is also the possibility to list objects

32、 that willbe included in a library, lib.a.All objects listed with lib-y are combined in a singlelibrary for that directory.Objects that are listed in obj-y and additionally listed inlib-y will not be included in the library, since they willbe accessible anyway.For consistency, objects listed in lib-

33、m will be included in lib.a.Note that the same kbuild makefile may list files to be built-inand to be part of a library. Therefore the same directorymay contain both a built-in.o and a lib.a file.Example: #arch/i386/lib/Makefilelib-y := checksum.o delay.oThis will create a library lib.a based on che

34、cksum.o and delay.o.For kbuild to actually recognize that there is a lib.a being built,the directory shall be listed in libs-y.See also “6.3 List directories to visit when descending“.Use of lib-y is normally restricted to lib/ and arch/*/lib.- 3.6 Descending down in directoriesA Makefile is only re

35、sponsible for building objects in its own directory. Files in subdirectories should be taken care of byMakefiles in these subdirs. The build system will automaticallyinvoke make recursively in subdirectories, provided you let it know of them.To do so, obj-y and obj-m are used.ext2 lives in a separat

36、e directory, and the Makefile present in fs/ tells kbuild to descend down using the following assignment.Example: #fs/Makefileobj-$(CONFIG_EXT2_FS) += ext2/If CONFIG_EXT2_FS is set to either y (built-in) or m (modular)the corresponding obj- variable will be set, and kbuild will descend down in the e

37、xt2 directory.Kbuild only uses this information to decide that it needs to visitthe directory, it is the Makefile in the subdirectory thatspecifies what is modules and what is built-in.It is good practice to use a CONFIG_ variable when assigning directory names. This allows kbuild to totally skip th

38、e directory if the corresponding CONFIG_ option is neither y nor m.- 3.7 Compilation flagsccflags-y, asflags-y and ldflags-y The three flags listed above applies only to the kbuild makefilewhere they are assigned. They are used for all the normalcc, as and ld invocation happenign during a recursive

39、build.Note: Flags with the same behaviour were previously named:EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS.They are yet supported but their use are deprecated.ccflags-y specifies options for compiling C files with $(CC).Example: # drivers/sound/emu10k1/Makefileccflags-y += -I$(obj)ccflags-$(DEBUG)

40、 += -DEMU10K1_DEBUGThis variable is necessary because the top Makefile owns thevariable $(KBUILD_CFLAGS) and uses it for compilation flags for the entire tree.asflags-y is a similar string for per-directory optionswhen compiling assembly language source.Example: #arch/x86_64/kernel/Makefileasflags-y

41、 := -traditionalldflags-y is a string for per-directory options to $(LD).Example: #arch/m68k/fpsp040/Makefileldflags-y := -xCFLAGS_$, AFLAGS_$CFLAGS_$ and AFLAGS_$ only apply to commands in currentkbuild makefile.$(CFLAGS_$) specifies per-file options for $(CC). The $part has a literal value which s

42、pecifies the file that it is for.Example: # drivers/scsi/MakefileCFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONFCFLAGS_gdth.o = # -DDEBUG_GDTH=2 -D_SERIAL_ -D_COM2_ -DGDTH_STATISTICS CFLAGS_seagate.o = -DARBITRATE -DPARITY -DSEAGATE_USE_ASMThese three lines specify compilation flags for aha152x.o,gdth.

43、o, and seagate.o$(AFLAGS_$) is a similar feature for source files in assembly languages.Example: # arch/arm/kernel/MakefileAFLAGS_head-armv.o := -DTEXTADDR=$(TEXTADDR) -traditionalAFLAGS_head-armo.o := -DTEXTADDR=$(TEXTADDR) -traditional- 3.9 Dependency trackingKbuild tracks dependencies on the foll

44、owing: 1) All prerequisite files (both *.c and *.h) 2) CONFIG_ options used in all prerequisite files 3) Command-line used to compile targetThus, if you change an option to $(CC) all affected files willbe re-compiled.- 3.10 Special RulesSpecial rules are used when the kbuild infrastructure doesnot p

45、rovide the required support. A typical example isheader files generated during the build process.Another example are the architecture-specific Makefiles whichneed special rules to prepare boot images etc.Special rules are written as normal Make rules.Kbuild is not executing in the directory where th

46、e Makefile islocated, so all special rules shall provide a relativepath to prerequisite files and target files.Two variables are used when defining special rules:$(src) $(src) is a relative path which points to the directorywhere the Makefile is located. Always use $(src) whenreferring to files loca

47、ted in the src tree.$(obj) $(obj) is a relative path which points to the directorywhere the target is saved. Always use $(obj) whenreferring to generated files.Example: #drivers/scsi/Makefile$(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl $(CPP) -DCHIP=810 - = 3.0 changed the type of opt

48、ions used to specify alignment of functions, loops etc. $(cc-option-align), when usedas prefix to the align options, will select the right prefix:gcc = 3.00 cc-option-align = -falignExample: KBUILD_CFLAGS += $(cc-option-align)-functions=4In the above example, the option -falign-functions=4 is used f

49、orgcc = 3.00. For gcc where both are two digits. So for example gcc 3.41 would return 0341.cc-version is useful when a specific $(CC) version is faulty in one area, for example -mregparm=3 was broken in some gcc versionseven though the option was accepted by gcc.Example: #arch/i386/Makefilecflags-y += $(shell if $(call cc-version) -ge 0300

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报