Reputation: 312
THIS_MAKE := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
MAKER := $(MAKE) -f $(THIS_MAKE)
FILE_LIST=tmp/file tmp/dir/file
all:
rm -rf tmp
$(MAKER) copy_files
copy_files: $(FILE_LIST)
tmp/file: | tmp
echo hello>$@
tmp/dir/file: | tmp/dir
echo world>$@
define dst_dir_rule
$(1):
-mkdir -p $$@
endef
$(foreach dir,$(dir $(FILE_LIST)), $(eval $(call dst_dir_rule,$(dir))))
#end of makefile
The makefile above should create the files in the FILE_LIST variable.
The problem is with the part that tries to automatically generate rules for the directories.
When I run it I get a "missing separator." error.
When I delete the space between the comma and the $(eval) it works.
I would really like to understand why.
Thanks,
Gur
Upvotes: 3
Views: 7066
Reputation: 136395
This is because you need to use tab symbol as command separator in your macro. As you don't have one it yields "missing separator" error.
Fix (using ; command separator on the same line):
define dst_dir_rule
$(1): ; -mkdir -p $$@ # as a one liner
You can also simplify:
THIS_MAKE := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
to:
THIS_MAKE := $(lastword $(MAKEFILE_LIST))
Upvotes: 3