I'm having trouble understanding how Makefile deals with variable expansion when a rule creates a file that should modify the behaviour of a wildcard expansion.
For instance, I have the following Makefile:
TEXT_FILES = $(wildcard *.txt)
all: create test
create:
@touch hello.txt
test:
@printf "The files are $(TEXT_FILES)\n"
What I expected to get when running make
is
The files are hello.txt
because TEXT_FILES
should be evaluated when it is called, not when defined. However, I actually get (running make twice)
The files are (variable is empty when executing for the first time)
The files are hello.txt (found next time)
How can I get the desired behavior?