uboot学习之二----主Makefile学习

原博主发布的时候将Makefile分成了四章,为了读取方便,将其转载汇总为一章,并分别以一、二、三、四分隔。

转载地址:https://www.cnblogs.com/yr-linux/p/5361887.html

转载地址:https://www.cnblogs.com/yr-linux/p/5361886.html

转载地址:https://www.cnblogs.com/yr-linux/p/5361885.html

转载地址:https://www.cnblogs.com/yr-linux/p/5361822.html

一、版本号 u_boot_version(U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL).$(EXTRAVERSION)) (24-29行)

BSP支持包(https://yunpan.cn/cqB5i8LCAMzhM  访问密码 c425,解压后/uboot目录下的Makefile)


VERSION = 1      //主版本号
PATCHLEVEL = 3    //修补版本号
SUBLEVEL = 4     //次版本号
EXTRAVERSION =    //附加信息,一般默认为空,我们可以自己设置
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL).$(EXTRAVERSION)
//uboot版本 1.3.4 ,之间用.隔开

VERSION_FILE = $(obj)include/version_autogenerated.h
//版本号文件,是根据主makefile中的第365行的规则创建的

编译过后, version_autogenerated.h 文件的路径是:根目录下面include/version_autogenerated.h。这个文件中引用了变量U_BOOT_VERSION的值; version_autogenerated.h这个文件是在编译时自动生成的,通过vi可以看到里面的 内容是一个宏:#define U_BOOT_VERSION "U-Boot 1.3.4"

二、环境变量之:主机的操作系统和主机架构(HOSTOS、HOSTARCH)(31-43行)

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  //导出CPU的架构和CPU操作系统这两个环境变量,下面备用。

Makefile中的shell函数的用法(《跟我一起学makefile_陈皓》第53页 ):
contents := $(shell cat foo)
files := $(shell echo *.c)
(1)shell函数和反引号" ` "是相同的功能。在shell中执行 uname -m可以打印出主机的硬件架构名称
(2)shell中的| 叫做管道,管道:将管道前面的运算式的输出作为后面一个的输入再去处理。最终输出才是我们整个式子的输出。
(3)HOSTARCH

cpu架构 ARCH就是architecture,架构的意思。

 三、静默编译

第45-54行:

45 # Deal with colliding definitions from tcsh etc.
46 VENDOR=
47
48 #########################################################################
49 # Allow for silent builds
50 ifeq (,$(findstring s,$(MAKEFLAGS))) //判断findstring函数是否为空

51 XECHO = echo //如果有就echo
52 else
53 XECHO = : //如果没有就为空,即不打印
54 endif
55


这一段 主要是关于静默编译的内容


uboot允许静默编译,开启静默编译主要是通过判断ifeq (,$(findstring s,$(MAKEFLAGS))) 。

使用方法:在编译时,使用make -s -会作为MAKEFLAGS传给Makefile.

关于makefile知识点:

条件判断:主makefile50行 :ifeq (,$(findstring s,$(MAKEFLAGS)))

《跟我一起学Makefile》第42页:

条件表达式的语法为:

<conditional-directive>

<text-if-true>

endif

以及

<conditional-directiv>

<text-if-ture>

else

<text-if-false>

endif

其中<conditional-directiv>表示条件关键字,如“ifeq”。

第一个关键字ifeq:

ifeq(<arg1>, <arg2>)

ifeq 'arg1' 'arg2'
ifeq “arg1” 'arg2'

ifeq 'arg1' ”arg2”

ifeq ”arg1” “arg2”

比较参数“arg1” 和“arg2”的值是否相同。相同为真。

第二个关键字ifneq:

ifneq (<arg1>, <arg2>)

ifneq 'arg1' 'arg2'

ifneq “arg1” 'arg2'

ifneq 'arg1' ”arg2”

ifneq ”arg1” “arg2”

比较参数“arg1” 和“arg2”的值是否相同。不同为真。

第三个关键字ifdef:

ifdef <variable-name>

如果变量的值非空,那么表达式为真,否则为假。

findstring函数

函数调用语法:

$(<funciton> <arguments>)

或者

${<function> <arguments>}

$(findstring <find>, <in>)

功能:在字串<in>中查找<find>字串。

返回:如果找到,那么返回<find>,否则返回空字符串。

所以这里ifeq (,$(findstring s,$(MAKEFLAGS)))

这里的意思就是如果findstring函数的返回值为空。如果为空,那么ifeq函数的两个参数相等,条件判断为真。执行<text-if-true>.

四、两种编译方法:原地编译和单独输出文件夹编译

第57-123行:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

57 #

 58 # U-boot build supports producing a object files to the separate external

 59 # directory. Two use cases are supported:

 60 #

 61 # 1) Add O= to the make command line

 62 # 'make O=/tmp/build all'

 63 #

 64 # 2) Set environement variable BUILD_DIR to point to the desired location

 65 # 'export BUILD_DIR=/tmp/build'

 66 # 'make'

 67 #

 68 # The second approach can also be used with a MAKEALL script

 69 # 'export BUILD_DIR=/tmp/build'

 70 # './MAKEALL'

 71 #

 72 # Command line 'O=' setting overrides BUILD_DIR environent variable.

 73 #

 74 # When none of the above methods is used the local build is performed and

 75 # the object files are placed in the source directory.

 76 #

 77 

 78 ifdef O

 79 ifeq ("$(origin O)", "command line")

 80 BUILD_DIR := $(O)

 81 endif

 82 endif

83 

 84 ifneq ($(BUILD_DIR),)

 85 saved-output := $(BUILD_DIR)

 86 

 87 # Attempt to create a output directory.

 88 $(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})

 89 

 90 # Verify if it was successful.

 91 BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)

 92 $(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))

 93 endif # ifneq ($(BUILD_DIR),)

 94 

 95 OBJTREE         := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))

 96 SRCTREE         := $(CURDIR)

 97 TOPDIR          := $(SRCTREE)

 98 LNDIR           := $(OBJTREE)

 99 export  TOPDIR SRCTREE OBJTREE

100 

101 MKCONFIG        := $(SRCTREE)/mkconfig

102 export MKCONFIG

103 

104 ifneq ($(OBJTREE),$(SRCTREE))

105 REMOTE_BUILD    := 1

106 export REMOTE_BUILD

107 endif

108

109 # $(obj) and (src) are defined in config.mk but here in main Makefile

110 # we also need them before config.mk is included which is the case for

111 # some targets like unconfig, clean, clobber, distclean, etc.

112 fneq ($(OBJTREE),$(SRCTREE))

113 obj := $(OBJTREE)/

114 src := $(SRCTREE)/

115 else

116 obj :=

117 src :=

118 endif

119 export obj src

120 

121 # Make sure CDPATH settings don't interfere

122 unexport CDPATH

123

编译复杂项目:makefile提供两种编译管理方法,默认情况是原地编译。

原地编译的缺点:

第一:污染源文件目录。第二:一套源代码只能按照一种配置和编译方法进行处理,无法同时维护超过两个或两个以上的配置编译方法。

输出文件夹编译:

为了解决以上缺陷,采用单独输出文件夹的方式编译,Linux kernel支持这样的方法,具体实现思路是:将所有编译生成的.o文件或者

其他文件全部输出到指定好的目录。uboot也学习了这样的方法。

具体做法:

见57行---76行的注释:

  ①在命令行编译时制定make O=输出目录(注意配置时也要加O=输出目录)

 make O=/tmp/build all

1

比如我们在root@ubuntu:/usr/local/arm/qt_x210v3/uboot这里面创建一个output文件夹来作为输出目录:三步: make O=output/ distclean    make O=output/ x210_sd_config   这一步出错:解决方法:进入output文件夹后手工创建这个文件:

root@ubuntu:/usr/local/arm/qt_x210v3/uboot/output# mkdir board/samsung/x210 -p

然后重新配置。

     make O=output/ all 

最后发现还是有问题。应该是整个uboot移植时还是不行的。我们以后使用三星版本的uboot进行移植再来研究。

  ②设置环境变量BUILD_DIR指出期望的输出目录。

1

2

'export BUILD_DIR=/tmp/build'

 'make'

      第二种方法也可以通过MAKEALL脚本实现。

1

2

3

       'export BUILD_DIR=/tmp/build'

       './MAKEALL' <br>

make o=输出目录会覆盖BUILD_DIR<br><br><br>很多bsp开发都使用这样的方式,所以有利于后面学习。

两种编译方法的makefile代码实现在78---123行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值