What makefile lazy evaluation rule governs this behavior?

放肆的年华 提交于 2021-02-05 07:00:31

问题


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

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


回答1:


You need to also delete a:

$ rm -rf ./subdir a && make

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

all: a
        @echo $(A_FILE)

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



来源:https://stackoverflow.com/questions/64084461/what-makefile-lazy-evaluation-rule-governs-this-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!