############## Truly execute actions !!!!!! ####################
PHONY + = $ (vmlinux-dirs) # pseudo target
$ (Vmlinux-dirs): prepare scripts
$ (Q) $ (MAKE) $ (build) =$ @
# (1) build =-f scripts/Makefile. build obj = <dir> for actual compilation
# It is equivalent to make-f scripts/Makefile. build obj =$ @
# In Makefile. build, the first true dependency rule is _ build. In line 93, we enter here.
#__ Build depends on the build-in.o or lib. a under each directory.
# $ @ Indicates that each target in the vmlinux-dirs variable is used to pass to 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) the dependency targets here have two prepare: and 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, ining '~ ')
# $ (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 supported ded * only * If
# Kernel config option config_localversion_auto is selected. Also, at
# 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
# Defining multiple pseudo targets
# Prepare3 is used to check if we are building in a separate output directory,
# Step 3: Check whether the output directory is customized.
# And if so do:
#1) Check that make has not been executed in the kernel src $ (srctree)
#2) Create the role de2 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-syscils
# 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 is to set a shell state, that is, if the exit code of any command it executes is non-zero
# Terminate immediately
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/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/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
# 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'