uboot之makefile底层文件

 1.HOSTARCH 和HOSTOS

HOSTARCH := $(<span style="background-color: rgb(255, 215, 0);">shell</span> 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/macppc/ppc/)

HOSTOS := $(<span style="background-color: rgb(255, 215, 0);">shell</span> uname -s | tr '[:upper:]' '[:lower:]' | \
	    sed -e 's/\(cygwin\).*/cygwin/')

 

在此使用了 shell 命令 sed ,此命令会把主机架构名“i686”替换为“i386”,把主机操作系统“Linux”替换为“linux”,目的是尽量统一主机的架构名和操作系统类型。

 

2.指定编译链接时目标文件的输出目录

 

ifdef O
ifeq ("$(origin O)", "command line")#if 命令行传递过来了变量O
BUILD_DIR := $(O)
endif
endif

ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)

# Attempt to create a output directory.
$(<span style="background-color: rgb(255, 215, 0);">shell</span> [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})#if 存在了BUILD_DIR就跳过||右边的语句,否则要执行右边的语句)

# Verify if it was successful.
BUILD_DIR := $(<span style="background-color: rgb(255, 215, 0);">shell</span> cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))#if BUILD_DIR为空则显示报警信息 
endif # ifneq ($(BUILD_DIR),)

有两种方式指定输出文件的目录:

 

(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'

 

3.makefile的if语句

定义编译选项变量

cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
                > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)

引用编译选项变量cc-option

PLATFORM_CPPFLAGS += $(call cc-option,-marm,)

解析:call调用函数(指变量cc-option),传递的第一个参数赋给$(1),第二个参数给$(2)

变量cc-option的值是函数$(shell ....)返回的结果,也就是if函数的返回结果(shell只负责对if函数的返回结果处理)

if函数格式为(要注意的是if函数和makefile里的$(if..,. ,..)的差别):

if 语句1;then 语句2;else 语句3;fi;   

表示如果语句1能够执行,则执行语句2,如果不能执行(比如有错等),则执行语句3


 对于函数$(call cc-option,-marm,):

如果交叉编译工具$(CC)支持call函数的参数一表示的选项(也就是指-marm),那么call函数的返回就是该选项(指-marm),否则返回的是call函数的参数二表示的选项.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值