首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“$?”的不一致扩展变量

“$?”的不一致扩展变量
EN

Stack Overflow用户
提问于 2015-08-21 03:14:52
回答 1查看 77关注 0票数 0

来自https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables

$? The names of all the prerequisites that are newer than the target, with spaces between them.

所以,给出一个makefile:

代码语言:javascript
复制
# Force make to search for 'foo' in the VPATH directory
$(shell rm -rf foo)
# If 'D' is a "regular" file, we remove it first.
$(shell rm -rf D)
$(shell mkdir D)
# Suggest a VPATH-file, for Make to "associate" with 'foo'.
$(shell touch D/foo)
$(shell sleep 1)
# Target 'all' is newer than prerequisite 'D/foo'
$(shell touch all)

VPATH = D

all : foo phony
    echo '$?'

foo ::
    touch '$@'

.PHONY: phony

.PRECIOUS : D/foo

和And,我得到:

代码语言:javascript
复制
$ make -r
touch 'D/foo'
echo 'D/foo phony'
D/foo phony

# Try again, but this time, with parallel-execution mode.
$ make -r -j
touch 'D/foo'
echo 'phony'
phony

在这里,我们有两个严重的问题:

  1. 考虑到简单和明确的“触摸”先决条件,使之明确执行--因此保证foo将比all“更新”-- Make not展开$?D/foo,至少在上面的第二种情况下(即并行执行(-j)模式)。为什么?
  2. 如果您想出了上述的解释,难道不应该解释一下,为什么在第一种情况下(非并行执行),$? -确实做了-被扩展到D/foo

我想,我有一个假设,即并行还是非并行,使will 总是在执行目标之前暂停,first检查所有先决条件的是否已经完成了各自的构建。

那么,对于这两种情况,$?变量不应该进行相同的扩展吗?

EN

回答 1

Stack Overflow用户

发布于 2015-08-21 04:08:36

我认为这里有两个问题。

第一种是双冒号规则看起来像假目标,因为它们强迫make将目标视为“更新”,而不考虑实际的修改时间。(这就是为什么非并行版本的行为方式。)从foo ::更改为foo :,在$?输出中根本没有foo。)

第二件事是,尽管如此,使用并行模式似乎迫使make重新考虑其先决条件的修改时间(因此避免了以前的行为)。

这是猜测,也不是确定的,因为我还没有深入研究代码,看看是否真的发生了这种情况,但它解释了这里的结果(它还解释了另一个几乎相同的这里问题的结果)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32131796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档