linux 頂層Makefile執行的流程!!!(三)

來源:互聯網
上載者:User

###############真正執行動作!!!!!!####################
PHONY += $(vmlinux-dirs)  #偽目標
$(vmlinux-dirs): prepare scripts
$(Q)$(MAKE) $(build)=$@
#(1)build=-f scripts/Makefile.build obj=<dir> 進行實際的編
#等價於make -f scripts/Makefile.build obj=$@
#在Makefile.build中第一個真正的依賴規則是__build 大概在93行進入這裡我們
#__build又依賴於各個目錄下的build-in.o或者lib.a等
#$@表示vmlinux-dirs變數中的各個目標用於傳給obj
#vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) /
#       $(core-y) $(core-m) $(drivers-y) $(drivers-m) /
#       $(net-y) $(net-m) $(libs-y) $(libs-m)))

#(2)這裡的依賴目標有兩個prepare:和scripts
# L1180  prepare: prepare0
# L646   PHONY += scripts
# scripts: scripts_basic include/config/auto.conf

# Build the kernel release string
#
# The KERNELRELEASE value built here is stored in the file
# include/config/kernel.release, and is used when executing several
# make targets, such as "make install" or "make modules_install."
#
# The eventual kernel release string consists of the following fields,
# shown in a hierarchical format to show how smaller parts are concatenated
# to form the larger and final value, with values coming from places like
# the Makefile, kernel config options, make command line options and/or
# SCM tag information.
#
# $(KERNELVERSION)
#   $(VERSION)   eg, 2
#   $(PATCHLEVEL)   eg, 6
#   $(SUBLEVEL)   eg, 18
#   $(EXTRAVERSION)  eg, -rc6
# $(localver-full)
#   $(localver)
#     localversion*  (files without backups, containing '~')
#     $(CONFIG_LOCALVERSION) (from kernel config setting)
#   $(localver-auto)  (only if CONFIG_LOCALVERSION_AUTO is set)
#     ./scripts/setlocalversion (SCM tag, if one exists)
#     $(LOCALVERSION)  (from make command line if provided)
#
#  Note how the final $(localver-auto) string is included *only* if the
# kernel config option CONFIG_LOCALVERSION_AUTO is selected.  Also, at the
# moment, only git is supported but other SCMs can edit the script
# scripts/setlocalversion and add the appropriate checks as needed.

pattern = ".*/localversion[^~]*"
string  = $(shell cat /dev/null /
    `find $(objtree) $(srctree) -maxdepth 1 -regex $(pattern) | sort -u`)

localver = $(subst $(space),, $(string) /
         $(patsubst "%",%,$(CONFIG_LOCALVERSION)))

# If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called
# and if the SCM is know a tag from the SCM is appended.
# The appended tag is determined by the SCM used.
#
# Currently, only git is supported.
# Other SCMs can edit scripts/setlocalversion and add the appropriate
# checks as needed.
ifdef CONFIG_LOCALVERSION_AUTO
_localver-auto = $(shell $(CONFIG_SHELL) /
                   $(srctree)/scripts/setlocalversion $(srctree))
localver-auto  = $(LOCALVERSION)$(_localver-auto)
endif

localver-full = $(localver)$(localver-auto)

# Store (new) KERNELRELASE string in include/config/kernel.release
kernelrelease = $(KERNELVERSION)$(localver-full)
include/config/kernel.release: include/config/auto.conf FORCE
$(Q)rm -f $@
$(Q)echo $(kernelrelease) > $@

# Things we need to do before we recursively start building the kernel
# or the modules are listed in "prepare".
# A multi level approach is used. prepareN is processed before prepareN-1.
# archprepare is used in arch Makefiles and when processed asm symlink,
# version.h and scripts_basic is processed / created.

# Listed in dependency order
PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
#定義多個偽目標
# prepare3 is used to check if we are building in a separate output directory,
#第三步主要檢查我們是否為自訂了輸出目錄
# and if so do:
# 1) Check that make has not been executed in the kernel src $(srctree)
# 2) Create the include2 directory, used for the second asm symlink
prepare3: include/config/kernel.release
ifneq ($(KBUILD_SRC),)
@echo '  Using $(srctree) as source for kernel'
$(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then /
  echo "  $(srctree) is not clean, please run 'make mrproper'";/
  echo "  in the '$(srctree)' directory.";/
  /bin/false; /
fi;
$(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
$(Q)ln -fsn $(srctree)/include/asm-$(SRCARCH) include2/asm
endif

# prepare2 creates a makefile if using a separate output directory
prepare2: prepare3 outputmakefile

prepare1: prepare2 include/linux/version.h include/linux/utsrelease.h /
                   include/asm include/config/auto.conf
$(cmd_crmodverdir)

archprepare: prepare1 scripts_basic

prepare0: archprepare FORCE
$(Q)$(MAKE) $(build)=.
$(Q)$(MAKE) $(build)=. missing-syscalls

# All the preparing..
prepare: prepare0

# Leave this as default for preprocessing vmlinux.lds.S, which is now
# done in arch/$(ARCH)/kernel/Makefile

export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)

# The asm symlink changes when $(ARCH) changes.
# Detect this and ask user to run make mrproper
#set -e 是設定一種shell狀態即如果它執行的任何一條命令的退出碼非零
#都立刻終止

include/asm: FORCE
$(Q)set -e; asmlink=`readlink include/asm | cut -d '-' -f 2`;   /
if [ -L include/asm ]; then                                     /
  if [ "$$asmlink" != "$(SRCARCH)" ]; then                /
   echo "ERROR: the symlink $@ points to asm-$$asmlink but asm-$(SRCARCH) was expected"; /
   echo "       set ARCH or save .config and run 'make mrproper' to fix it";             /
   exit 1;                                         /
  fi;                                                     /
else                                                            /
  echo '  SYMLINK $@ -> include/asm-$(SRCARCH)';          /
  if [ ! -d include ]; then                               /
   mkdir -p include;                               /
  fi;                                                     /
  ln -fsn asm-$(SRCARCH) $@;                              /
fi

# Generate some files
# ---------------------------------------------------------------------------

# KERNELRELEASE can change from a few different places, meaning version.h
# needs to be updated, so this check is forced on all builds

uts_len := 64
define filechk_utsrelease.h
if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then /
   echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2;    /
   exit 1;                                                         /
fi;                                                               /
(echo /#define UTS_RELEASE /"$(KERNELRELEASE)/";)
endef

define filechk_version.h
(echo /#define LINUX_VERSION_CODE $(shell                             /
expr $(VERSION) /* 65536 + $(PATCHLEVEL) /* 256 + $(SUBLEVEL));     /
echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
endef

include/linux/version.h: $(srctree)/Makefile FORCE
$(call filechk,version.h)

include/linux/utsrelease.h: include/config/kernel.release FORCE
$(call filechk,utsrelease.h)

# ---------------------------------------------------------------------------

PHONY += depend dep
depend dep:
@echo '*** Warning: make $@ is unnecessary now.'

# ---------------------------------------------------------------------------
# Kernel headers
INSTALL_HDR_PATH=$(objtree)/usr
export INSTALL_HDR_PATH

HDRFILTER=generic i386 x86_64
HDRARCHES=$(filter-out $(HDRFILTER),$(patsubst $(srctree)/include/asm-%/Kbuild,%,$(wildcard $(srctree)/include/asm-*/Kbuild)))

PHONY += headers_install_all
headers_install_all: include/linux/version.h scripts_basic FORCE
$(Q)$(MAKE) $(build)=scripts scripts/unifdef
$(Q)for arch in $(HDRARCHES); do /
  $(MAKE) ARCH=$$arch -f $(srctree)/scripts/Makefile.headersinst obj=include BIASMDIR=-bi-$$arch ;/
  done

PHONY += headers_install
headers_install: include/linux/version.h scripts_basic FORCE
@if [ ! -r $(srctree)/include/asm-$(SRCARCH)/Kbuild ]; then /
   echo '*** Error: Headers not exportable for this architecture ($(SRCARCH))'; /
   exit 1 ; fi
$(Q)$(MAKE) $(build)=scripts scripts/unifdef
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst ARCH=$(SRCARCH) obj=include

PHONY += headers_check_all
headers_check_all: headers_install_all
$(Q)for arch in $(HDRARCHES); do /
  $(MAKE) ARCH=$$arch -f $(srctree)/scripts/Makefile.headersinst obj=include BIASMDIR=-bi-$$arch HDRCHECK=1 ;/
  done

PHONY += headers_check
headers_check: headers_install
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst ARCH=$(SRCARCH) obj=include HDRCHECK=1

# ---------------------------------------------------------------------------
# Modules

ifdef CONFIG_MODULES

# By default, build modules as well

all: modules

# Build modules
#
# A module can be listed more than once in obj-m resulting in
# duplicate lines in modules.order files.  Those are removed
# using awk while concatenating to the final file.

PHONY += modules
modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
$(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
@echo '  Building modules, stage 2.';
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost

# Target to prepare building external modules
PHONY += modules_prepare
modules_prepare: prepare scripts

# Target to install modules
PHONY += modules_install
modules_install: _modinst_ _modinst_post

PHONY += _modinst_
_modinst_:
@if [ -z "`$(DEPMOD) -V 2>/dev/null | grep module-init-tools`" ]; then /
  echo "Warning: you may need to install module-init-tools"; /
  echo "See
  sleep 1; /
fi
@rm -rf $(MODLIB)/kernel
@rm -f $(MODLIB)/source
@mkdir -p $(MODLIB)/kernel
@ln -s $(srctree) $(MODLIB)/source
@if [ ! $(objtree) -ef  $(MODLIB)/build ]; then /
  rm -f $(MODLIB)/build ; /
  ln -s $(objtree) $(MODLIB)/build ; /
fi
@cp -f $(objtree)/modules.order $(MODLIB)/
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst

# This depmod is only for convenience to give the initial
# boot a modules.dep even before / is mounted read-write.  However the
# boot script depmod is the master version.
PHONY += _modinst_post
_modinst_post: _modinst_
$(call cmd,depmod)

else # CONFIG_MODULES

# Modules not configured
# ---------------------------------------------------------------------------

modules modules_install: FORCE
@echo
@echo "The present kernel configuration has modules disabled."
@echo "Type 'make config' and enable loadable module support."
@echo "Then build a kernel with module support enabled."
@echo
@exit 1

endif # CONFIG_MODULES

###
# Cleaning is done on three levels.
# make clean     Delete most generated files
#                Leave enough to build external modules
# make mrproper  Delete the current configuration, and all generated files
# make distclean Remove editor backup files, patch leftover files and the like

# Directories & files removed with 'make clean'

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.