博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
makefile的三個特殊符號(= := ?=)
阅读量:4284 次
发布时间:2019-05-27

本文共 2640 字,大约阅读时间需要 8 分钟。

轉載自

1.

There is another assignment operator for variables, ‘?=’. This is called a conditional variable assignment operator, because it only has an effect if the variable is not yet defined. This statement:

FOO ?= bar

is exactly equivalent to this (see ):

ifeq ($(origin FOO), undefined)  FOO = barendif

Note that a variable set to an empty value is still defined, so ‘?=’ will not set that variable.

 

2.

The first flavor of variable is a recursively expanded variable. Variables of this sort are defined by lines using ‘=’ (see ) or by the define directive (see ). The value you specify is installed verbatim; if it contains references to other variables, these references are expanded whenever this variable is substituted (in the course of expanding some other string). When this happens, it is called recursive expansion.

For example,

foo = $(bar)bar = $(ugh)ugh = Huh?all:;echo $(foo)

will echo ‘Huh?’: ‘$(foo)’ expands to ‘$(bar)’ which expands to ‘$(ugh)’ which finally expands to ‘Huh?’.

This flavor of variable is the only sort supported by most other versions of make. It has its advantages and its disadvantages. An advantage (most would say) is that:

CFLAGS = $(include_dirs) -Oinclude_dirs = -Ifoo -Ibar

will do what was intended: when ‘CFLAGS’ is expanded in a recipe, it will expand to ‘-Ifoo -Ibar -O’. A major disadvantage is that you cannot append something on the end of a variable, as in

CFLAGS = $(CFLAGS) -O

because it will cause an infinite loop in the variable expansion. (Actually make detects the infinite loop and reports an error.)

Another disadvantage is that any functions (see ) referenced in the definition will be executed every time the variable is expanded. This makes make run slower; worse, it causes the wildcard and shell functions to give unpredictable results because you cannot easily control when they are called, or even how many times.

 

3.

Simply expanded variables are defined by lines using ‘:=’ or ‘::=’ (see ). Both forms are equivalent in GNU make; however only the ‘::=’ form is described by the POSIX standard (support for ‘::=’ was added to the POSIX standard in 2012, so older versions of make won’t accept this form either).

The value of a simply expanded variable is scanned once and for all, expanding any references to other variables and functions, when the variable is defined. The actual value of the simply expanded variable is the result of expanding the text that you write. It does not contain any references to other variables; it contains their values as of the time this variable was defined. Therefore,

x := fooy := $(x) barx := later

is equivalent to

y := foo barx := later

转载地址:http://wesgi.baihongyu.com/

你可能感兴趣的文章
nohup命令
查看>>
make 操作技巧指南--gcc版本设置
查看>>
sort和sortrows对矩阵排序
查看>>
matlab专区--------------matlab里面如何保留小数特定位数
查看>>
Matlab 绘图坐标轴刻度设置小数位数
查看>>
Matlab 条形图绘制 以及 添加误差棒 改变条形图形状
查看>>
cmake基本用法
查看>>
matlab 增加或减少图例 legend 线的长度
查看>>
matlab:把cell中的某个元素删去
查看>>
matlab 集合运算 交集 并集 差集
查看>>
C++ 给vector去重的三种方法
查看>>
map的详细用法
查看>>
C++初始化函数列表
查看>>
STL各种排序
查看>>
#include<map>
查看>>
z字形扫描
查看>>
相邻数对
查看>>
C++ string 字符串匹配
查看>>
C语言字符串函数大全
查看>>
轮盘赌选择,原理及C++实现
查看>>