u-boot Makefile完全解读

编译u-boot的步骤:
 
#make XX_config    XX表示某个cpu体系
 
#make  生成我们需要的u-boot.bin
 
具体可参考u-boot文件中的README。
 

1.设置版本
 
VERSION = 2010
 
PATCHLEVEL = 06
 
SUBLEVEL =
 
EXTRAVERSION = -rc1
 
ifneq "$(SUBLEVEL)" ""
 
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
else
 
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL)$(EXTRAVERSION)
 
endif
 
TIMESTAMP_FILE = $(obj)include/timestamp_autogenerated.h
 
VERSION_FILE = $(obj)include/version_autogenerated.h
 
以上定义了版本的变量U_BOOT_VERSION。
 

 

2.获取主机类型和主机系统
 
HOSTARCH := $(shell uname -m | \        执行shell命令  uname -m 查看主机类型
 
sed -e s/i.86/i386/ \
 
    -e s/sun4u/sparc64/ \
 
    -e s/arm.*/arm/ \
 
    -e s/sa110/arm/ \
 
    -e s/ppc64/powerpc/ \
 
    -e s/ppc/powerpc/ \
 
    -e s/macppc/powerpc/)
 
sed -e命令进行替换,比如将i386替换成i.86,并将结果放入变量HOSTARCH 。
 

 

HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
 
    sed -e 's/\(cygwin\).*/cygwin/')
 
uname -s 查看主机操作系统,tr '[:upper:]' '[:lower:]'将所有大写变小写,然后假如有cygwin,替换成cygwin.*,并将结果放入变量HOSTOS
 

 

# Set shell to bash if possible, otherwise fall back to sh
 
SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
 
else if [ -x /bin/bash ]; then echo /bin/bash; \
 
else echo sh; fi; fi)
 
选择/bin/bash
 

 

export  HOSTARCH HOSTOS SHELL
 
导出变量HOSTARCH HOSTOS SHELL
 

 

LC_ALL=C
 
export  LC_ALL
 

 

# Deal with colliding definitions from tcsh etc.
 
VENDOR=
 
变量为空
 
#########################################################################
 
# Allow for silent builds
 
ifeq (,$(findstring s,$(MAKEFLAGS)))
 
XECHO = echo
 
else
 
XECHO = :
 
endif
 

 

#########################################################################
 
#
 
# U-boot build supports producing a object files to the separate external
 
# directory. Two use cases are supported:
 
#
 
# 1) Add O= to the make command line
 
# 'make O=/tmp/build all'
 
#
 
# 2) Set environement variable BUILD_DIR to point to the desired location
 
# 'export BUILD_DIR=/tmp/build'
 
# 'make'
 
#
 
# The second approach can also be used with a MAKEALL script
 
# 'export BUILD_DIR=/tmp/build'
 
# './MAKEALL'
 
#
 
# Command line 'O=' setting overrides BUILD_DIR environent variable.
 
#
 
# When none of the above methods is used the local build is performed and
 
# the object files are placed in the source directory.
 
#
 
U-boot 生成一个目标文件来分开外面的文件夹,支持两种方式:
 
 1)将 0= 加到make命令行如:
 
 make 0=/tmp/build all
 
 2) 通过设置全局环境变量BUILD_DIR如:
 
 export BUILD_DIR=/tmp/build 
 
 make
 
第二种方式也可以用MAKEFILE脚本
 
 export BUILD_DIR=/tmp/build
 
 ./MAKEALL
 
通过第一种方式会覆盖环境变量 BUILD_DIR
 
 如果没有显式指定使用哪种方式,编译脚本会自动进行本地编译,目标文件被存放在当前文件夹里

相关推荐