为什么makefile惰性评估会在“父"目录中找到文件?食谱,但不是当前的食谱? [英] Why does makefile lazy evaluation find a file in a "parent" recipe but not the current one?

查看:47
本文介绍了为什么makefile惰性评估会在“父"目录中找到文件?食谱,但不是当前的食谱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是什么makefile惰性的后续措施评价规则支配着这种行为?.我仍在尝试弄清gnu make的懒惰评估的一些规则.

This question is a follow-up to What makefile lazy evaluation rule governs this behavior?. I'm still trying to grok some of the rules of gnu make's lazy evaluation.

在通过配方更新目录的目录之后,我想为该目录的内容添加一个make变量.

I want to have a make variable for the content of a directory after that directory has been updated by a recipe.

该Makefile演示了对 $(A_FILE)进行评估,以找到所创建的文件(位于父"目录中).实际创建文件的食谱:

This Makefile demonstrates that $(A_FILE) is evaluated to find the created file when it's in the "parent" of the recipe that actually creates the file:

A_FILE = $(wildcard subdir/*)

all: a
        @echo $(A_FILE)

a:
        @mkdir ./subdir
        @touch subdir/b

$ rm -rf ./subdir/ && make
subdir/b
$ 

但是下面的Makefile似乎有一个微不足道的变化: $(A_FILE)在其包含目录被更新的配方中被引用-但现在变量为空:

But the following Makefile has a seemingly trivial change: $(A_FILE) is referenced in the recipe where its containing directory is updated - but now the variable is empty:

A_FILE = $(wildcard subdir/*)

all: a
        @echo $(A_FILE)

a:
        @mkdir ./subdir
        @touch subdir/b
        @sleep 1
        @echo $(A_FILE)

$ rm -rf ./subdir/ && make


$ 

我添加了 sleep ,以排除更新目录后目录拖网速度过快的时间问题.提供了什么?为什么如果在较高层配方中引用了 $(A_FILE)的更新子目录内容,而实际在较低层配方中却没有引用,则为何对更新后的子目录内容进行评估更新了吗?

I added the sleep to rule out timing issues of the directory being trawled too quickly after it had been updated. What gives? Why does $(A_FILE) get evaluated against the updated subdir content if it's referenced in the higher-layer recipe but not in the lower-layer recipe where it's actually updated?

推荐答案

GNU make在开始运行配方中的 any 行之前,先评估配方中的 all 行.因此,当准备运行规则 a 的配方时,它将首先扩展所有行,包括最后一行中包含 $(A_FILE)的行.到那时,配方的任何部分都还没有运行,因此结果为空.

GNU make evaluates all lines in the recipe before it starts running any line in the recipe. So, when it is getting ready to run your recipe for the rule a it first expands all the lines, including the last line with $(A_FILE) in it. At that point no parts of the recipe have been run yet so the result is empty.

然后,在所有扩展之后,将调用外壳程序以运行配方中的行.

Then after all the expansion, the shell is invoked to run the lines in the recipe.

这篇关于为什么makefile惰性评估会在“父"目录中找到文件?食谱,但不是当前的食谱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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