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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With