[英]What makefile lazy evaluation rule governs this behavior?
I'm trying to have a makefile variable for the content of a directory after that directory has been updated by a recipe.在目录被配方更新后,我试图为目录的内容创建一个 makefile 变量。
Why does this not work :为什么这不起作用:
A_FILE = $(wildcard subdir/*)
all: a
@echo $(A_FILE)
a:
@mkdir ./subdir
@touch subdir/b
@touch a
$ rm -rf ./subdir && make
$
...whereas this does: ...而这样做:
A_FILE = $(wildcard subdir/*)
all: a
@echo $(A_FILE)
a: subdir/b
@touch a
subdir/b:
@mkdir ./subdir
@touch subdir/b
$ rm -rf ./subdir && make
subdir/b
$
? ?
I thought lazy-evaluation meant the variable was not evaluated until actually used.我认为惰性求值意味着在实际使用之前不会对变量进行求值。 In both versions,
$(A_FILE)
is used in the same recipe, and after a prereq has been evaluated.在这两个版本中,
$(A_FILE)
用于同一个配方中,并且在评估 prereq 之后。 In fact, I'd struggle to articulate a meaningful difference between the two rules, other than the superficial: the first is a chain of two rules/prereqs, and the second is a chain of three.事实上,我很难阐明两个规则之间的有意义的区别,而不是表面上的:第一个是两个规则/先决条件的链,第二个是三个规则的链。
You need to also delete a
:您还需要删除
a
:
$ rm -rf ./subdir a && make
Since you've deleted subdir
but not a
, the a:
rule isn't triggered.由于您已删除
subdir
而不是a
,因此不会触发a:
规则。 Only this rule runs:仅此规则运行:
all: a @echo $(A_FILE)
And since subdir
wasn't created, the $(wildcard subdir/*)
expansion is empty.由于
subdir
没有被创建, $(wildcard subdir/*)
扩展是空的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.