linux顶层Makefile(不错)
来源:互联网 发布:sql分组累计求和 编辑:程序博客网 时间:2024/05/15 14:52
1、make menuconfig
# *DOCUMENTATION*
# To see a list of typical targets execute "make help"
# More info can be located in ./README
# Comments in this file are targeted only to the developer, do not
# expect to learn how to build the kernel reading this file.
# Do not:
# o
#
# o
MAKEFLAGS += -rR --no-print-directory
#-r禁止使用build-in规则
#--no-print-directory是:不要再屏幕上打印"Entering directory.."
#记住变量SHELL,MAKEFLAGS在整个make的执行过程中
#始终被自动的传递给 所有的 子make
# We are using a recursive build, so we need to do a little thinking
# to get the ordering right.
#
# Most importantly: sub-Makefiles should only ever modify files in
# their own directory. If in some directory we have a dependency on
# a file in another dir (which doesn't happen often, but it's often
# unavoidable when linking the built-in.o targets which finy
# turn into vmlinux), we will call a sub make in that other dir, and
# after that we are sure that everything which is in that other dir
# is now up to date.
#
# The only cases where we need to modify files which have global
# effects are thus separated out and done before the recursive
# descending is started. They are now explicitly listed as the
# prepare rule.
# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands
ifdef V
endif
ifndef KBUILD_VERBOSE
endif
# 函数origin并不操作变量的值,只是告诉你‘你的这个变量’是哪里来的。
# 语法是: $(origin ;)# origin函数的返回值有:
#"undefined"从来没有定义过、“default”是一个默认的定义、“
#"environment"是一个环境变量、
#"file"这个变量被定义在Makefile中
#"command line"这个变量是被命令行定义的
#"override"是被override指示符重新定义的
#"automatic"是一个命令运行中的自动化变量
# Call a source code checker (by default, "sparse") as part of the
# C compilation.调用一个静态分析工具作为c编译器的
#部分
# Use 'make C=1' to enable checking of only re-compiled files.
# Use 'make C=2' to enable checking of *all* source files, regardless
# of whether they are re-compiled or not.
#
# See the file "Documentation/sparse.txt" for more details, including
# where to get the "sparse" utility.
ifdef C
endif
ifndef KBUILD_CHECKSRC
endif
#用M来指定外部模块的目录
# Use make M=dir to specify directory of external module to build
# Old syntax make ... SUBDIRS=$PWD is still supported
# Setting the environment variable KBUILD_EXTMOD take precedence
#识别这里是定义一个外部模块吗??
#当我们定义了M变量或者SUBDIRS时表示编译一个外部模块
# “?=”操作符
#条件赋值的赋值操作符。被称为条件赋值是因为:只有此变量在之前没有赋值的情况下才会对这个变量进行赋值。例如:
#其等价于:
#含义是:如果变量“FOO”在没有定义过,就给它赋值“bar”。否则不改变它的值。
ifdef SUBDIRS
endif
ifdef M
在使用“:=”
定义变量时,变量值中对另外变量的引用或者函数的引用在定义时被展开(对变量进行替换)
而=是在使用时才进行替换
举例:
CFLAGS = $(include_dirs) -O
include_dirs = -Ifoo -Ibar
“CFLAGS”会在命令中被展开为“-Ifoo -Ibar -O”
CFLAGS := $(include_dirs) -O
include_dirs := -Ifoo -Ibar
由于在变量“include_dirs”的定义出现在“CFLAGS”定义之后。因此在“CFLAGS”的定义中,
“include_dirs”的值为空。“CFLAGS”的值为“-O”而不是“-Ifoo -Ibar -O”。
endif
# kbuild supports saving output files in a separate directory.
# To locate output files in a separate directory two syntaxes are supported.
# In both cases the working directory must be the root of the kernel src.
# 1) O=
# Use "make O=dir/to/store/output/files/"
#
# 2) Set KBUILD_OUTPUT
# Set the environment variable KBUILD_OUTPUT to point to the directory
# where the output files shall be placed.
# export KBUILD_OUTPUT=dir/to/store/output/files/
# make
#
# The O= assignment takes precedence over the KBUILD_OUTPUT environment
# variable.
# KBUILD_SRC is set on invocation of make in OBJ directory
# KBUILD_SRC is not intended to be used by the regular user (for now)
###################make 的最开始###################
####################################################
ifeq ($(KBUILD_SRC),)#如果KBUILD_SRC没有定义则进入下面一层即首次进入
# OK, Make called in directory where kernel src resides
# Do we want to locate output files in a separate directory?
ifdef O
endif
# That's our default target when none is given on the command line
PHONY := _all
_all:
# Cancel implicit rules on top Makefile取消隐式推倒规则
$(CURDIR)/Makefile Makefile: ;
ifneq ($(KBUILD_OUTPUT),)
# Invoke a second make in the output directory, passing relevant variables
# check that the output directory actually exists
saved-output := $(KBUILD_OUTPUT)
KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
$(if $(KBUILD_OUTPUT),, /