u-boot Makefile分析 -- (1)

[Author: Bo Shen <[email protected]>]

[u-boot: 2014.01-rc1, e03c76c30342797a25ef9350e51c8daa0b56f1df]

下面进行u-boot Makefile分析

1. u-boot的固定版本信息,与编译时生成的时间与动态版本信息。

  1 #
  2 # (C) Copyright 2000-2013
  3 # Wolfgang Denk, DENX Software Engineering, [email protected].
  4 #
  5 # SPDX-License-Identifier:      GPL-2.0+
  6 #
  7 
  8 VERSION = 2014
  9 PATCHLEVEL = 01
 10 SUBLEVEL =
 11 EXTRAVERSION = -rc1
 12 ifneq "$(SUBLEVEL)" ""
 13 U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 14 else
 15 U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL)$(EXTRAVERSION)
 16 endif
 17 TIMESTAMP_FILE = $(obj)include/generated/timestamp_autogenerated.h
 18 VERSION_FILE = $(obj)include/generated/version_autogenerated.h
 19 
1~6: Header (license information)

8~11: u-boot版本的基本信息

12~6: 判断SUBLEVEL是否为空来决定U_BOOT_VERSION

17~ 8: 编译时生成的时间信息,版本信息,后续详解。


2. 编译u-boot的主机信息

 20 HOSTARCH := $(shell uname -m | \
 21         sed -e s/i.86/x86/ \
 22             -e s/sun4u/sparc64/ \
 23             -e s/arm.*/arm/ \
 24             -e s/sa110/arm/ \
 25             -e s/ppc64/powerpc/ \
 26             -e s/ppc/powerpc/ \
 27             -e s/macppc/powerpc/\
 28             -e s/sh.*/sh/)
 29 
 30 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
 31             sed -e 's/\(cygwin\).*/cygwin/')
 32 
 33 export  HOSTARCH HOSTOS
20~28: 通过执行一个shell命令去获取主机的架构,然后做一些替换动作(如:将sa110换成arm)。具体关于uname的命令,请自行查阅。
30~31: 通过执行一个shell命令去获取主机操作系统,然后将大写字转换成小写字母。

33: export主机的架构与操作系统。


3. 将VENDOR赋空值

 35 # Deal with colliding definitions from tcsh etc.
 36 VENDOR=
 37 

4. 判断是否需要安静的编译。

 38 #########################################################################
 39 # Allow for silent builds
 40 ifeq (,$(findstring s,$(MAKEFLAGS)))
 41 XECHO = echo
 42 else
 43 XECHO = :
 44 endif
判断make的flag是否带有s, 如果有,则是静态编译。如执行make -s, 你将不会看到作何编译信息输出。

5. 判断是否编译生成的object文件放到单独的文件夹中。具体看注释就明白了。

 46 #########################################################################
 47 #
 48 # U-boot build supports generating object files in a separate external
 49 # directory. Two use cases are supported:
 50 #
 51 # 1) Add O= to the make command line
 52 # 'make O=/tmp/build all'
 53 #
 54 # 2) Set environment variable BUILD_DIR to point to the desired location
 55 # 'export BUILD_DIR=/tmp/build'
 56 # 'make'
 57 #
 58 # The second approach can also be used with a MAKEALL script
 59 # 'export BUILD_DIR=/tmp/build'
 60 # './MAKEALL'
 61 #
 62 # Command line 'O=' setting overrides BUILD_DIR environment variable.
 63 #
 64 # When none of the above methods is used the local build is performed and
 65 # the object files are placed in the source directory.
 66 #
 67 
 68 ifeq ("$(origin O)", "command line")
 69 BUILD_DIR := $(O)
 70 endif

6. 检查是否需要进行源代码检查,具体看注释也就明白了。如果需要检查源代码,需要sparse命令的支持。

 72 # Call a source code checker (by default, "sparse") as part of the
 73 # C compilation.
 74 #
 75 # Use 'make C=1' to enable checking of re-compiled files.
 76 #
 77 # See the linux kernel file "Documentation/sparse.txt" for more details,
 78 # including where to get the "sparse" utility.
 79 
 80 ifdef C
 81 ifeq ("$(origin C)", "command line")
 82 CHECKSRC := $(C)
 83 endif
 84 endif
 85 ifndef CHECKSRC
 86   CHECKSRC = 0
 87 endif
 88 export CHECKSRC

7. 判断第五步中的BUILD_DIR是否为空,如不为空

 90 ifneq ($(BUILD_DIR),)
 91 saved-output := $(BUILD_DIR)
 92 
 93 # Attempt to create a output directory.
 94 $(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})
 95 
 96 # Verify if it was successful.
 97 BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
 98 $(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
 99 endif # ifneq ($(BUILD_DIR),)
90: 如BUILD_DIR不为空,则进行后续动作。

93~94: 则判断BUILD_DIR是否存在,如不存在,创建这个文件夹,

97~99: 检查文件夹是否创建成功。不成功,输出错误信息。

你可能感兴趣的:(u-boot Makefile分析 -- (1))