是“全球"的makefile变量与特定于目标的变量不同吗? [英] Are "global" makefile variables distinct from target-specific variables?

查看:87
本文介绍了是“全球"的makefile变量与特定于目标的变量不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自文档:

出现在 在目标范围内评估变量分配: 因此,任何先前定义的特定于目标的变量值都将位于 影响.请注意,此变量实际上与任何全局"变量不同 值:两个变量不必具有相同的风格(递归 与简单).

All variables that appear within the VARIABLE-ASSIGNMENT are evaluated within the context of the target: thus, any previously-defined target-specific variable values will be in effect. Note that this variable is actually distinct from any "global" value: the two variables do not have to have the same flavor (recursive vs. simple).


因此,给了一个makefile:


So, given a makefile:

% : foo += 1

all : x;

x ::
    @echo '$(foo)'

foo := 2


正在运行,我得到:


And running, I get:

2 1 1


仔细看一下上面的引用:


Taking a closer look at the quote above:

出现在 在目标范围内评估变量分配.

All variables that appear within the VARIABLE-ASSIGNMENT are evaluated within the context of the target.

不可能解释 特定于目标的 定义,例如:% : foo += 1,最终会在其值中包含 include , 全局"值(即非目标值或特定于模式的值):2.

It is impossible to explain how a target-specific definition like: % : foo += 1, will end up to include in its value, the "global" (i.e. not target or pattern-specific) value: 2.

当我们稍后看时,在上面的引文中很难证明这一点:

Much harder to justify it, when we look later, in the quote above:

请注意,此变量实际上与任何全局"变量 不同 值:两个变量不必具有相同的风格(递归 与简单).

Note that this variable is actually distinct from any "global" value: the two variables do not have to have the same flavor (recursive vs. simple).

如果它们是不同的",那么Make最终会为目标all扩展,该值是取自全局"值以及特定于目标的值的沙拉"值定义?

If, they are that "distinct", how come Make ends up expanding for the target all, a value that is a "salad" of values taken from the "global", and as well from the target-specific definition?

使用什么方法来产生值2 1 1,因为显然,值1 产生了在上面的生成文件中的值2.

And what methodology did Make use to bring about the value 2 1 1, because clearly, the value 1 proceeds the value 2 in the makefile above.

推荐答案

我相信您只是误解了"distinct"的含义.它不是两个变量.通过以下片段两个变量不必具有相同的风格"来阐明其含义.这才是重点.全局变量foo和特定于目标的变量foo是两个不同的(但在扩展时组合).

I believe you are simply misunderstanding what the meaning of "distinct" meant there. It did not mean that they are two different variables. The meaning was clarified by the following fragment "the two variables do not have to have the same flavor". That's the point. The global variable foo and the target-specific variable foo are two different (but combined when expanded) variables.

请记住,您得到的输出正是您所期望的.

With that in mind the output you get is exactly what you'd expect.

分配给foo第一项是全局分配中的值2.

The first thing assigned to foo is the value 2 from the global assignment.

仅在目标处理期间之后(foo += 1分配已处理)(两次,一次对all,一次对x).

Only after that, during the target processing, is the foo += 1 assignment processed (twice, once for all and once for x).

完全符合您的情况2 1 1.

这篇关于是“全球"的makefile变量与特定于目标的变量不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆