当前位置:[首页 > 韩语学习 > 语法 > Makefile 语法分析]

Makefile 语法分析

发布: 2017-12-31 00:22 | 来源:www.jptranslate.com | 查 看:

Makefile 语法分析 第一部分

VERSION = 2
# 给变量VERSION赋值

PATCHLEVEL = 6
# 给变量PATCHLEVEL赋值

SUBLEVEL = 22
# 给变量SUBLEVEL赋值

EXTRAVERSION = .6
# 给变量EXTRAVERSION赋值

NAME = Holy Dancing Manatees, Batman!
# 给变量NAME赋值

# *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 use make's built-in rules and variables
#    (this increases performance and avoid hard-to-debug behavour);
# o print "Entering directory ...";
MAKEFLAGS += -rR --no-print-directory
# 操作符“+=”的作用是给变量(“+=”前面的MAKEFLAGS)追加值。
# 如果变量(“+=”前面的MAKEFLAGS)之前没有定义过,那么,“+=”会自动变成“=”;
# 如果前面有变量(“+=”前面的MAKEFLAGS)定义,那么“+=”会继承于前次操作的赋值符;
# 如果前一次的是“:=”,那么“+=”会以“:=”作为其赋值符
# 在执行make时的命令行选项参数被通过变量 “MAKEFLAGS”传递给子目录下的make程序。
# 对于这个变量除非使用指示符“unexport”对它们进行声明,它们在整个make的执行过程中始终被自动的传递给所有的子make。
# 还有个特殊变量SHELL与MAKEFLAGS一样,默认情况(没有用“unexport”声明)下在整个make的执行过程中被自动的传递给所有的子make。
#
# -rR --no-print-directory
# -r disable the built-in impilict rules.
# -R disable the built-in variable setttings.
# --no-print-directory。


# 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 finally
# 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
ifeq ("$(origin V)", "command line")
KBUILD_VERBOSE = $(V)
endif
endif
ifndef KBUILD_VERBOSE
KBUILD_VERBOSE = 0
endif
# “ifdef”是条件关键字。语法是ifdef ;; else ; endif
# ifdef只检验一个变量是否被赋值,它并不会去推导这个变量,并不会把变量扩展到当前位置。
# “ifeq”与“ifdef”类似。
# “ifeq”语法是ifeq (;, ;),功能是比较参数“arg1”和“arg2”的值是否相同。
#
# 函数origin并不操作变量的值,只是告诉你你的这个变量是哪里来的。
# 语法是: $(origin ;)
# origin函数的返回值有:
# “undefined”从来没有定义过、“default”是一个默认的定义、“environment”是一个环境变量、
# “file”这个变量被定义在Makefile中、“command line”这个变量是被命令行定义的、
# “override”是被override指示符重新定义的、“automatic”是一个命令运行中的自动化变量
#
# 应用变量的语法是:$(变量名)。如KBUILD_VERBOSE = $(V)中的$(V)。
#
# KBUILD_VERBOSE的值根据在命令行中是否定义了变量V,
# 当没有定义时,默认为V=O,输出为short version;可以用make V=1 来输出全部的命令。
#
# ifndef与ifdef语法类似,但功能恰好相反。ifndef是判断变量是不是没有被赋值。


# Call a source code checker (by default, "sparse") as part of the
# C compilation.
#
# 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
ifeq ("$(origin C)", "command line")
KBUILD_CHECKSRC = $(C)
endif
endif
ifndef KBUILD_CHECKSRC
KBUILD_CHECKSRC = 0
endif
# ifdef是Makefile的条件关键字,其语法是:ifdef ;
# 如果变量;的值非空,那到表达式为真。否则,表达式为假。
# ifndef也是Makefile的条将关键字,功能与ifdef相反,语法相似。

# 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
ifdef SUBDIRS
KBUILD_EXTMOD ?= $(SUBDIRS)
endif
ifdef M
ifeq ("$(origin M)", "command line")
KBUILD_EXTMOD := $(M)
endif
endif
# ifdef是Makefile的条件关键字,其语法是:ifdef ;
# 如果变量;的值非空,那到表达式为真。否则,表达式为假。
#
# ifeq是Makefile的条件关键字,其语法是:ifeq (;, ;),比较参数“arg1”和“arg2”的值是否相同。
#
# 操作符“:=”与操作符“+=”的功能相同,只是操作符“:=”后面的用来定义变量(KBUILD_EXTMOD)的变量M只能是前面定义好的,
# 如果操作符“?=”前面的变量KBUILD_EXTMOD没有定义过,那么就将SUBDIRS赋给KBUILD_EXTMOD;
# 如果定义过,则语句KBUILD_EXTMOD ?= $(SUBDIRS)什么也不做。