1. Linux kernel top-level Makefile
The top-level Makefile of Linux is very similar to the top-level Makefile of uboot, because uboot refers to Linux.
2. Linux kernel-top-level Makefile preliminary work
Let's take a look at the preliminary work done by the top-level Makefile of the Linux kernel.
1. Version number
The top-level
Makefile
starts with the version number of
the Linux
kernel, as shown below:
1 VERSION = 4
2 PATCHLEVEL = 1
3 SUBLEVEL = 15
4 EXTRAVERSION =
It can be seen that
the Linux
kernel version number is
4.1.15
.
2. MAKEFLAGS variable _
The MAKEFLAGS
variable is set as follows:
16 MAKEFLAGS += -rR --include-dir=$(CURDIR)
3. Command output
When compiling
Linux, you can also use "
V=1
" to output the complete command. This is the same as
uboot
. The relevant code is as follows:
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. Silent output
When compiling Linux, use " make -s " to achieve silent compilation. No information will be printed during compilation. Just like uboot , the relevant code is as follows:
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. Set the compilation result output directory
When compiling
Linux, use "
O=xxx
" to output the process file generated by compilation to the specified directory. The relevant
code is as follows:
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. Code inspection
Linux
also supports code checking. Use the command "
make C=1
" to enable code checking and check those files that need to be recompiled. "
make C=2
" is used to check all source code files.
The code in the top-level
Makefile is as follows:
172 ifeq ("$(origin C)", "command line")
173 KBUILD_CHECKSRC = $(C)
174 endif
175 ifndef KBUILD_CHECKSRC
176 KBUILD_CHECKSRC = 0
177 endif
The next article continues to analyze the preparation work done by the top-level Makefile of the Linux kernel source code.