1、make menuconfig
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 26
EXTRAVERSION =
NAME = Rotary Wombat
# *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 avoids hard-to-debug behaviour);
# o print "Entering directory ...";
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 #v=1
ifeq ("$(origin V)", "command line")
KBUILD_VERBOSE = $(V) #把V的值作為KBUILD_VERBOSE的值
endif
endif
ifndef KBUILD_VERBOSE #即預設我們是不回顯的
#回顯即在命令執行前顯示要執行的命令
KBUILD_VERBOSE = 0
endif
# 函數origin並不操作變數的值,只是告訴你你的這個變數是哪裡來的。
# 文法是: $(origin <variable>;)# 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
ifeq ("$(origin C)", "command line")
KBUILD_CHECKSRC = $(C)
endif
endif
ifndef KBUILD_CHECKSRC
KBUILD_CHECKSRC = 0
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時表示編譯一個外部模組
ifdef SUBDIRS
KBUILD_EXTMOD ?= $(SUBDIRS) #?=為條件賦值操作符僅僅在變數還
#還沒有定義的情況下有效
endif
ifdef M
ifeq ("$(origin M)", "command line")
KBUILD_EXTMOD := $(M)
endif
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沒有定義則進入下面一層即首次進入
#時一般都需要兩次進入頂層Makefile
#若定義了則不為空白直接跳入下一步
# OK, Make called in directory where kernel src resides
# Do we want to locate output files in a separate directory?
ifdef O #把輸出檔案放在不同的檔案夾內
ifeq ("$(origin O)", "command line")
KBUILD_OUTPUT := $(O) #用於指定我們的輸出檔案的輸出目錄
endif
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: ;#remake 操作查看目前的目錄Makefile是否為最新
#CURDIR值為當前的核心源碼目錄current dir
#為GNU make使用的變數,CURDIR設定當前工作目錄的路徑名
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)#這裡是測試此目錄是否
#存在,若存在則賦給K BUILD_OUTPUT
$(if $(KBUILD_OUTPUT),, /#這裡的<then-part>為空白即表示輸出目錄不存在
$(error output directory "$(saved-output)" does not exist))#使用了error函數
#這裡的if函數文法為:if<condition>,<then-part>
#或者是if<condition>,<then part>,<else-part>
#make的環境變數叫MAKECMDGOALS 這個變數中會存放你所指定的
#終極目標的列表,如果在命令列上,你沒有指定目標,
#那麼,這個變數是空值。
PHONY += $(MAKECMDGOALS) sub-make
#將任何在命令列中給出的目標放入變數MAKECMDGOALS
#這裡filter-out是返回$(MAKECMDGOALS)中除了Makefile _all sub-make以外的
#其他檔案;
$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
$(Q)@:#這裡僅僅只是取消回顯沒有別的意思
#$(KBUILD_VERBOSE:1=)為變數替換,如果為1就替換為空白
#if KBUILD_VERBOSE = 1 or KBUILD_VERBOSE is NULL
#then
#$(MAKE) -C $(KBUILD_OUTPUT) //回顯
#else
#@ $(MAKE) -C $(KBUILD_OUTPUT)//即不回顯
#endif
sub-make: FORCE
$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) /#KBUILD_OUTPUT==dir前面測試了
KBUILD_SRC=$(CURDIR) /
KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile /#
$(filter-out _all sub-make,$(MAKECMDGOALS))#這裡是表示要產生的目標
#make -C dir KBUILD_SRC=`pwd` KBUILD_EXTMOD="" -f `pwd`/Makefile [Targets]
#這裡表示再次執行Makefile 但此時我們的KBUILD
#此時再次執行完make後skip-makefile := 1從而
# Leave processing to above invocation of make結束子make返回根目錄的make
skip-makefile := 1
endif # ifneq ($(KBUILD_OUTPUT),)這裡是ifneq
endif # ifeq ($(KBUILD_SRC),)#這裡是ifeq的結束處
####################################################
####################################################
ifeq ($(skip-makefile),)#如果為空白則開始分類執行!!!!!!
#endif # skip-makefile在1813行處結束最大的ifeq結構
# If building an external module we do not care about the all: rule
# but instead _all depend on modules
PHONY += all #聲明一個偽目標all
ifeq ($(KBUILD_EXTMOD),) #如果外部模組定義為空白則_all依賴於all
_all: all
else
_all: modules #否則依賴於modules
endif
srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))#看KBUILD_SRC是否為空白, #設定源碼目錄
TOPDIR := $(srctree) #頂層目錄
# FIXME - TOPDIR is obsolete, use srctree/objtree
objtree := $(CURDIR) #CURDIR為make的預設環境變數
src := $(srctree) #源檔案的目錄也設定為目前的目錄
obj := $(objtree)#目標檔案的輸出目錄設定目前的目錄
VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
#這裡是說目前的目錄找不到源檔案時的搜尋目錄
export srctree objtree VPATH TOPDIR
#export用於要將指定變數輸出給子make,
# SUBARCH tells the usermode build what the underlying arch is. That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below. If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.
#這裡是擷取cpu的具體型號存在變數SUBARCH中
#sed -e s表示替換,這裡表示出現i.86的用i386替換
#出現sun4u的用sparc64替換
#一般寫成sed -e 's/i.86/i386' 用''括起來
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ /
-e s/arm.*/arm/ -e s/sa110/arm/ /
-e s/s390x/s390/ -e s/parisc64/parisc/ /
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ /
-e s/sh.*/sh/ )
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.
# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
export KBUILD_BUILDHOST := $(SUBARCH) #這裡是把宿主機的cpu結構匯出到
#KBUILD_BUILDHOST變數,並傳入子make
ARCH ?= $(SUBARCH)
# 設定變數 ARCH 的方法有兩種,
# 一:在命令列中 如: make ARCH=ia64 ;
# 二:設定環境變數,在環境變數中預設
#的 ARCH 的值是執行 make 的 cpu 架構
# "?="表示為ARCH 條件賦值 如果ARCH前面沒有賦值則這裡賦值
#成功,否則不重新賦值
CROSS_COMPILE ?= #交叉編譯工具的設定在嵌入式系統
#經常要修改此處設定交叉編譯器的路徑
# Architecture as present in compile.h
UTS_MACHINE := $(ARCH)
SRCARCH := $(ARCH)
# Additional ARCH settings for x86
ifeq ($(ARCH),i386)
SRCARCH := x86
endif
ifeq ($(ARCH),x86_64)
SRCARCH := x86
endif
KCONFIG_CONFIG ?= .config #這裡是產生的設定檔
# SHELL used by kbuild 這裡shel中的if [ -x file ]測試file是否可執行
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; /
else if [ -x /bin/bash ]; then echo /bin/bash; /
else echo sh; fi ; fi)
HOSTCC = gcc
HOSTCXX = g++
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2
# Decide whether to build built-in, modular, or both.
# Normally, just do built-in.
KBUILD_MODULES :=
KBUILD_BUILTIN := 1
# If we have only "make modules", don't compile built-in objects.編譯內建對象
# When we're building modules with modversions, we need to consider
# the built-in objects during the descend as well, in order to
# make sure the checksums are up to date before we record them.
#如果執行”make modules”則這裡在這裡重新處理KBUILD_BUILTIN :=1
ifeq ($(MAKECMDGOALS),modules)
KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
endif
# If we have "make <whatever> modules", compile modules
# in addition to whatever we do anyway.
# Just "make" or "make all" shall build modules as well
#如果執行"make all","make _all","make modules","make"中任一個命令
#則在這裡重新處理KBUILD_MODULES
ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)#filter過濾出指定的字串
#這裡表示如果不為空白則編譯模組
KBUILD_MODULES := 1
endif