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
The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.
8.9 The eval Function The eval function is very special: it allows you to define new makefile constructs that are not constant; which are the result of evaluating other variables and functions. The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax.
Check if variable is defined in a Makefilecheck_defined = \ $(strip $(foreach 1,$1, \ $(call __check_defined,$1,$(strip $(value 2))))) __check_defined = \ $(if $(value $1),, \ $(error Undefined $1$(if $2, ($2)))) install: $(call check_defined, var1) $(call check_defined, var2) # do stuff here..
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
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