linux2.6.30.4 顶层Makefile文件分析(二)

# External module support.

# When building external modules the kernel used as basis is considered read-only, and no consistency checks are made #and the make system is not used on the basis kernel. If updates are required in the basis kernel ordinary make commands #(without M=...) must be used.

/*当编译外部模块的时候,内核作为基础使用被认为是直读的,没有一致性检查,在基础内核上不会构建系统。如果在基础内核上有更新要求,必须使用通常的make命令(不带M=...)*/

# The following are the only valid targets when building external modules.

# make M=dir clean     Delete all automatically generated files

# make M=dir modules   Make all modules in specified dir

# make M=dir        Same as 'make M=dir modules'

# make M=dir modules_install

#   Install the modules built in the module directory  Assumes install directory is already created

# We are always building modules

KBUILD_MODULES := 1

PHONY += crmodverdir

crmodverdir:

$(cmd_crmodverdir)

 

PHONY += $(objtree)/Module.symvers

$(objtree)/Module.symvers:

@test -e $(objtree)/Module.symvers || ( \   /*测试是否存在文件Module.symvers*/

echo; \

echo "  WARNING: Symbol version dump $(objtree)/Module.symvers"; \

echo "           is missing; modules will have no dependencies and modversions."; \

echo )

 

module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))

PHONY += $(module-dirs) modules

$(module-dirs): crmodverdir $(objtree)/Module.symvers

$(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)

modules: $(module-dirs)

@$(kecho) '  Building modules, stage 2.';

$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost

 

PHONY += modules_install

modules_install: _emodinst_ _emodinst_post /*使用隐含规则来处理*/

 

install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)

PHONY += _emodinst_

_emodinst_:

$(Q)mkdir -p $(MODLIB)/$(install-dir)

$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst

 

PHONY += _emodinst_post

_emodinst_post: _emodinst_

$(call cmd,depmod)

 

clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))

 

PHONY += $(clean-dirs) clean

$(clean-dirs):

$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)

 

clean: rm-dirs := $(MODVERDIR)

clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers \

                   $(KBUILD_EXTMOD)/Module.markers \

                   $(KBUILD_EXTMOD)/modules.order

clean: $(clean-dirs)

$(call cmd,rmdirs)

$(call cmd,rmfiles)

@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \

\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \

-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \

-type f -print | xargs rm -f

help:

@echo  '  Building external modules.'

@echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'

@echo  ''

@echo  '  modules         - default target, build the module(s)'

@echo  '  modules_install - install the module'

@echo  '  clean           - remove generated files in module directory only'

@echo  ''

# Dummies...

PHONY += prepare scripts

prepare: ; /*使用空命令行来禁止隐含规则*/

scripts: ;

endif # KBUILD_EXTMOD

 

# Generate tags for editors

quiet_cmd_tags = GEN     $@

      cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@

tags TAGS cscope: FORCE

$(call cmd,tags)

# Scripts to check various things for consistency

includecheck:

find * $(RCS_FIND_IGNORE) \

-name '*.[hcS]' -type f -print | sort \

| xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl

versioncheck:

find * $(RCS_FIND_IGNORE) \

-name '*.[hcS]' -type f -print | sort \

| xargs $(PERL) -w $(srctree)/scripts/checkversion.pl

namespacecheck:

$(PERL) $(srctree)/scripts/namespace.pl

export_report:

$(PERL) $(srctree)/scripts/export_report.pl

endif #ifeq ($(config-targets),1)

endif #ifeq ($(mixed-targets),1)

 

PHONY += checkstack kernelrelease kernelversion

# UML needs a little special treatment here.  It wants to use the host toolchain, so needs $(SUBARCH) passed to #checkstack.pl.  Everyone else wants $(ARCH), including people doing cross-builds, which means that $(SUBARCH) #doesn't work here.

ifeq ($(ARCH), um)

CHECKSTACK_ARCH := $(SUBARCH)

else

CHECKSTACK_ARCH := $(ARCH)

endif

checkstack:

$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \

$(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH)

kernelrelease:

$(if $(wildcard include/config/kernel.release), $(Q)echo $(KERNELRELEASE), \

$(error kernelrelease not valid - run 'make prepare' to update it))

kernelversion:

@echo $(KERNELVERSION)

 

# Single targets

# Single targets are compatible with:

# - build with mixed source and output

# - build with separate output dir 'make O=...'

# - external modules

#  target-dir => where to store outputfile

#  build-dir  => directory in kernel source tree to use

ifeq ($(KBUILD_EXTMOD),)

        build-dir  = $(patsubst %/,%,$(dir $@))

        target-dir = $(dir $@)

else

        zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))

        build-dir  = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))

        target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))

endif

%.s: %.c prepare scripts FORCE  /*模式规则的使用,所有的.s文件依赖于对应的.c文件*/

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

%.i: %.c prepare scripts FORCE

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

%.o: %.c prepare scripts FORCE

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

%.lst: %.c prepare scripts FORCE

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

%.s: %.S prepare scripts FORCE

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

%.o: %.S prepare scripts FORCE

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

%.symtypes: %.c prepare scripts FORCE

$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)

# Modules

/: prepare scripts FORCE

$(cmd_crmodverdir)

$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \

$(build)=$(build-dir)

%/: prepare scripts FORCE

$(cmd_crmodverdir)

$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \

$(build)=$(build-dir)

%.ko: prepare scripts FORCE

$(cmd_crmodverdir)

$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1)   \

$(build)=$(build-dir) $(@:.ko=.o)

$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost

 

# FIXME Should go into a make.lib or something 

# ===========================================================================

quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))

      cmd_rmdirs = rm -rf $(rm-dirs)

 

quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))

      cmd_rmfiles = rm -f $(rm-files)

 

# Run depmod only if we have System.map and depmod is executable

quiet_cmd_depmod = DEPMOD  $(KERNELRELEASE)

      cmd_depmod = \

if [ -r System.map -a -x $(DEPMOD) ]; then        \ /*测试文件可读而且可以执行*/

$(DEPMOD) -ae -F System.map                                     \

$(if $(strip $(INSTALL_MOD_PATH)), -b $(INSTALL_MOD_PATH) )     \

$(KERNELRELEASE);                                               \

fi

 

# Create temporary dir for module support files

# clean it up only when building all modules

cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \

                  $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)

 

a_flags = -Wp,-MD,$(depfile) $(KBUILD_AFLAGS) $(AFLAGS_KERNEL) \

  $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(KBUILD_CPPFLAGS) \

  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)

 

quiet_cmd_as_o_S = AS      $@

cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<

 

# read all saved command lines

 

targets := $(wildcard $(sort $(targets)))

cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

 

ifneq ($(cmd_files),)

  $(cmd_files): ; # Do not try to update included dependency files

  include $(cmd_files)

endif

 

# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir

# Usage:

# $(Q)$(MAKE) $(clean)=dir

clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj

 

endif # skip-makefile

 

PHONY += FORCE

FORCE:

 

# Declare the contents of the .PHONY variable as phony.  We keep that

# information in a variable so we can use it in if_changed and friends.

.PHONY: $(PHONY)  /*将PHONY变量中的目标声明为伪目标*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值