Makefile中的变量扩展问题

make执行的两个阶段:

In the first phase, make reads the makefile and any included makefiles. At this time, variables and rules are loaded into make’s internal database and the dependency graph is created. In the second phase, make analyzes the dependency graph and determines the targets that need to be updated, then executes command scripts to perform the required updates.

 

关于makefile中的变量何时被扩展的总结:

To summarize, here are the rules for when elements of a makefile are expanded:
• For variable assignments, the lefthand side of the assignment is always expanded immediately when make reads the line during its first phase.
• The righthand side of = and ?= are deferred until they are used in the second phase.
• The righthand side of := is expanded immediately.
• The righthand side of += is expanded immediately if the lefthand side was originally defined as a simple variable. Otherwise, its evaluation is deferred.
• For macro definitions (those using define), the macro variable name is immediately expanded and the body of the macro is deferred until used.
• For rules, the targets and prerequisites are always immediately expanded while the commands are always deferred.

 

DefinitionExpansion of aExpansion of b
a = bImmediate Deferred
a ?= bImmediateDeferred
a := bImmediateImmediate
a += bImmediateDeferred or immediate
define a
  b...
  b...
  b...
endef
ImmediateDeferred

转载于:https://www.cnblogs.com/whos/archive/2010/09/22/1833207.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值