uboot笔记-Makefile文件分析
这里使用九鼎X210开发板的uboot来做分析。uboot版本号u-boot 1.3.4
VERSION = 1
PATCHLEVEL = 3
SUBLEVEL = 4
EXTRAVERSION =
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
VERSION_FILE = $(obj)include/version_autogenerated.h
- 这里定义uboot的版本号和配置uboot时,存储版本号的头文件路径
HOSTARCH := $(shell uname -m | \
sed -e s/i.86/i386/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ \
-e s/sa110/arm/ \
-e s/powerpc/ppc/ \
-e s/ppc64/ppc/ \
-e s/macppc/ppc/)
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
sed -e 's/\(cygwin\).*/cygwin/')
export HOSTARCH HOSTOS
#Deal with colliding definitions from tcsh etc.
VENDOR=
HOSTARCH
-这里定义主机系统架构和操作系统,使用ubuntu和intel的电脑的情况下一般是i386和i686,这里sed指令后面的i.86
中的.
是通配符,这里满足所有i.86
的宿主机都改为i386
。- 这里中间的
|
是管道符,表示将前面的参数传递给后面使用。 HOSTOS
-定义宿主机的操作系统,使用ubuntu系统的话,这里的操作系统是Linux,然后后面将所有字符转换为大写,然后再转换为小写,最后宿主机操作系统名称为linuxexport
将宿主机型号和操作系统声明为全局变量,供其他文件使用VENDOR
设置厂商,这里设置为空
#Allow for silent builds
ifeq (,$(findstring s,$(MAKEFLAGS)))
XECHO = echo
else
XECHO = :
endif
- 这里是检测是否需要静默编译,如果需要静默编译,在make后面加上-s,默认不加-s则会在编译时打印编译信息。这里
MAKEFLAGS
表示在执行makefile的时候,在make后面添加的标志,如果没有找到s,则定义XECHO为echo,否则定义XECHO为空(这里:
在bash中表示空命令,只起到占位符的作用)
#########################################################################
#
#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.
#
ifdef O
ifeq ("$(origin O)", "command line")
BUILD_DIR := $(O)
endif
endif
ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)
#Attempt to create a output directory.
$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})
#Verify if it was successful.
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)
OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE := $(CURDIR)
TOPDIR := $(SRCTREE)
LNDIR := $(OBJTREE)
export TOPDIR SRCTREE OBJTREE
MKCONFIG := $(SRCTREE)/mkconfig
export MKCONFIG
ifneq ($(OBJTREE),$(SRCTREE))
REMOTE_BUILD := 1
export REMOTE_BUILD
endif
#$(obj) and (src) are defined in config.mk but here in main Makefile
#we also need them before config.mk is included which is the case for
#some targets like unconfig, clean, clobber, distclean, etc.
ifneq ($(OBJTREE),$(SRCTREE))
obj := $(OBJTREE)/
src := $(SRCTREE)/
else
obj :=
src :=
endif
export obj src
#Make sure CDPATH settings don't interfere
unexport CDPATH
#########################################################################
- 这里主要是确定源程序文件夹路径和生成的目标文件存放的路径。正常情况下,生成的目标文件和源文件存放在同一个文件夹下,但是我们可以指定obj文件存放的路径。使用方法是
make O=/tmp/build all
- 这里主要关注src和obj这两个变量,src存储源文件路径,obj存储目标文件的路径,在没有设置obj的情况下,obj和src目录相同。
#load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk
export ARCH CPU BOARD VENDOR SOC
-
这里包含了一个config.mk文件,这个文件在uboot源码里面找不到,是我们在配置uboot时生成的(从obj这个变量也可以看出是在编译的时候生成的)具体在配置的哪个阶段生成的?还需要看配置过程(具体参考mkconfig脚本文件)。
-
config.mk具体内容如下
ARCH = arm
CPU = s5pc11x
BOARD = x210
VENDOR = samsung
SOC = s5pc110
-
这里包含了config.mk文