什么makefile惰性评估规则控制此行为? [英] What makefile lazy evaluation rule governs this behavior?

查看:47
本文介绍了什么makefile惰性评估规则控制此行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试通过食谱更新目录 后,我试图为该目录的内容提供一个makefile变量.

I'm trying to have a makefile variable for the content of a directory after that directory has been updated by a recipe.

为什么这不起作用:

A_FILE = $(wildcard subdir/*)

all: a
        @echo $(A_FILE)

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

$ rm -rf ./subdir && make

$

...这样做:

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
$

?

我认为惰性评估意味着该变量要等到实际使用后才能进行评估.在这两个版本中, $(A_FILE)用于相同的配方中,并且在评估了先决条件之后.实际上,除了表述之外,我会尽力阐明这两个规则之间的有意义的区别:第一个规则是两个规则/前提条件的链,第二个是三个规则/条件的链.

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. 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.

推荐答案

您还需要删除 a :

$ rm -rf ./subdir a && make

由于您删除了 subdir 但未删除 a ,因此不会触发 a:规则.仅运行此规则:

Since you've deleted subdir but not a, the a: rule isn't triggered. Only this rule runs:

all: a
        @echo $(A_FILE)

由于未创建 subdir ,因此 $(通配符subdir/*)扩展为空.

And since subdir wasn't created, the $(wildcard subdir/*) expansion is empty.

这篇关于什么makefile惰性评估规则控制此行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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