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

问题描述

文档:


因此,给了一个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:

无法解释针对特定目标的定义如:% : foo += 1,最终会变成在其值中包括,即全局"(即非目标或特定于模式的值): 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:

如果,它们是不同的",为什么 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 在上面的makefile中.

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 first 是来自全局分配的值 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 .

Which gets you 2 1 1 exactly as shown.

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

05-27 17:40
查看更多