JZ2440开发板移植u-boot 2015.01----第二篇,分析Makefile
make jz2440_defconfig分析:
>>>>>>>>>查看Makefile中的匹配规则:
%config: scripts_basic outputmakefile FORCE
+$(Q)$(CONFIG_SHELL) $(srctree)/scripts/multiconfig.sh [email protected]
1. scripts_basic:
PHONY += scripts_basic
scripts_basic:
$(Q)$(MAKE) $(build)=scripts/basic
$(Q)rm -f .tmp_quiet_recordmcount
1.1 首先.PHONY: $(PHONY),PHONY的作用就是将scripts_basic定义为伪目标,关于伪目标的作用参考Makefile手册:
1.2 $(Q)的定义如下:
ifeq ("$(origin V)", "command line")
KBUILD_VERBOSE = $(V)
endif
ifndef KBUILD_VERBOSE
KBUILD_VERBOSE = 0
endif
ifeq ($(KBUILD_VERBOSE),1)
quiet =
Q =
else
quiet=quiet_
Q = @
endif
1.2.1 @的作用参考Makefile手册:
1.2.2 origin函数功能:
所以$(Q)的作用就是当make命令行中没有定义V变量或者V变量的值不为1的话,则不会回显Makefile中的命令,如果定义了变量V且V=1的话则回显Makefile中的命令
1.3 $(MAKE)的定义如下:
1.3 $(build)的定义:
build变量在当前的Makefile中并没有定义,所以我们需要到包含的文件中去找,在scripts_basic规则之前有包含如下头文件:
include $(srctree)/scripts/Kbuild.include
1.3.1 $(srctree)在当前Makefile中定义如下:
ifeq ($(KBUILD_SRC),)
srctree := .
else
ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
srctree := ..
else
srctree := $(KBUILD_SRC)
endif
endif
在当前Makefile及包含文件中并没有KBUILD_SRC的定义,所以srctree表示当前文件夹
在./scripts/Kbuild.include的文件中build的定义如下:
build := -f $(srctree)/scripts/Makefile.build obj
所以$(build)的值为: -f ./scripts/Makefile.build obj
所以scripts_basic的构建规则为:
scripts_basic:
make -f ./scripts/Makefile.build obj=scripts/basic
rm -f .tmp_quiet_recordmcount
可以看出scripts_basic的作用就是执行make -f ./scripts/Makefile.build obj=scripts/basic同时删除.tmp_quiet_recordmcount
关于make -f ./scripts/Makefile.build obj=scripts/basic的作用我们后面单独讲
2. outputmakefile的定义:
outputmakefile:
ifneq ($(KBUILD_SRC),)
$(Q)ln -fsn $(srctree) source //建立链接source指向当前文件夹
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
$(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
endif
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)
CONFIG_SHELL就是找出当前系统所使用的shell,我的系统中定义为 /bin/bash
这里的$$BASH让我比较难理解,在bash手册中$$解释如下:
Expands to the process id of the shell.
我在系统下测试$$BASH为14609BASH,和bash手册一致,所以if [ -x "$$BASH" ]不成立
outputmakefile的作用就是在用户指定的输出文件夹中生成Makefile,由于我们没有定义KBUILD_SRC,故什么也不执行
3. FORCE的定义
FORCE为强制目标,在Makefile手册中定义如下:
这里的FORCE和伪目标的作用一致,即每次都认为FORCE被更新过,这样命令总会被执行
故当我们输入make jz2440_defconfig时,或者当我们输入make ×××config时,Makefile解释如下:
使用依赖执行make -f ./scripts/Makefile.build obj=scripts/basic同时删除.tmp_quiet_recordmcount,执行/bin/bash ./scripts/multiconfig.sh jz2440_defconfig
关于/bin/bash ./scripts/multiconfig.sh jz2440_defconfig的详细内容我们后面分析