Linux内核顶层Makefile前期工作分析一

一.   Linux内核顶层Makefile

Linux 的顶层 Makefile 和 uboot 的顶层 Makefile 非常相似,因为 uboot 参考了 Linux。

二.  Linux内核-顶层Makefile前期工作

下面了解一下 Linux内核的 顶层 Makefile前期所做的工作。

1、版本号

顶层 Makefile 一开始就是 Linux 内核的版本号,如下所示:
1 VERSION = 4
2 PATCHLEVEL = 1
3 SUBLEVEL = 15
4 EXTRAVERSION =
可以看出, Linux 内核版本号为 4.1.15

2MAKEFLAGS 变量

MAKEFLAGS 变量设置如下所示:
16 MAKEFLAGS += -rR --include-dir=$(CURDIR)

3、命令输出

Linux 编译的时候也可以通过“ V=1 ”来输出完整的命令,这个和 uboot 一样,相关代码如下所示:
69 ifeq ("$(origin V)", "command line")
70 KBUILD_VERBOSE = $(V)
71 endif
72 ifndef KBUILD_VERBOSE
73 KBUILD_VERBOSE = 0
74 endif
75
76 ifeq ($(KBUILD_VERBOSE),1)
77 quiet =
78 Q =
79 else
80 quiet=quiet_
81 Q = @
82 endif

4、静默输出

Linux 编译的时候使用“make -s”就可实现静默编译,编译的时候就不会打印任何的信息, uboot 一样,相关代码如下:

87 ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
88 ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
89 quiet=silent_
90 endif
91 else # make-3.8x
92 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
93 quiet=silent_
94 endif
95 endif
96
97 export quiet Q KBUILD_VERBOSE

5、设置编译结果输出目录

Linux 编译的时候使用“ O=xxx ”即可将编译产生的过程文件输出到指定的目录中,相关代 码如下:
116 ifeq ($(KBUILD_SRC),)
117
118 # OK, Make called in directory where kernel src resides
119 # Do we want to locate output files in a separate directory?
120 ifeq ("$(origin O)", "command line")
121 KBUILD_OUTPUT := $(O)
122 endif

6、代码检查

Linux 也支持代码检查,使用命令“ make C=1 ”使能代码检查,检查那些需要重新编译的文件。“ make C=2 ” 用于检查所有的源码文件,顶层 Makefile 中的代码如下:
172 ifeq ("$(origin C)", "command line")
173 KBUILD_CHECKSRC = $(C)
174 endif
175 ifndef KBUILD_CHECKSRC
176 KBUILD_CHECKSRC = 0
177 endif

下一篇文章继续分析 Linux内核源码的 顶层Makefile所做的准备工作。

  Linux内核顶层Makefile前期工作

猜你喜欢

转载自blog.csdn.net/wojiaxiaohuang2014/article/details/133100349