Helmholtz42
Helmholtz42

Reputation: 195

Makefile variable expansion/evaluation

Currently I am facing an issue with my Makefile caused by evaluation of a make variable. I have reduced the complexity, only the essential elements remain that produce the issue.

Any ideas how to solve or work around this issue?


Makefile:

LIST=$(wildcard src/*.txt)

all: step1 step2

step1:
    @echo "---------- step1 ----------"
    @echo $(LIST)
    rm src/q1.txt
    ls src

step2:
    @echo "---------- step2 ----------"
    @echo $(LIST)
    cp $(LIST) ./dst

Execution logging:

$ make
---------- step1 ----------
src/q1.txt src/q2.txt
rm src/q1.txt
ls src
q2.txt
---------- step2 ----------
src/q1.txt src/q2.txt
cp src/q1.txt src/q2.txt ./dst
cp: cannot stat `src/q1.txt': No such file or directory
make: *** [step2] Error 1

Upvotes: 6

Views: 5027

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754900

Don't use the wildcard function.

LIST = src/*.txt

all: step1 step2

step1:
    @echo "---------- step1 ----------"
    @echo $(LIST)
    rm src/q1.txt
    ls src

step2:
    @echo "---------- step2 ----------"
    @echo $(LIST)
    cp $(LIST) ./dst

Upvotes: 8

Related Questions