Reputation: 8239
I'm trying to create a target which matches multiple directories, but no files. Is there any way to flag the target explicitly as being a directory?
For example:
output/%:
mkdir -p $@
matches files as well, which is definitely not something I want.
Basically, I have many variables which contain directory names which need to be created if they don't exist, and the best way to do that, as far as I've found is this:
all: directories other_stuff
directories: $(dir1) $(dir2) ...
$(dir1):
mkdir -p $@
$(dir2):
mkdir -p $@
...
So, I'm OK with repeating the directory variables as dependencies for the directories
target, but creating targets for each directory I add seems overkill and hard to maintain.
Upvotes: 1
Views: 180
Reputation: 272487
Here is one possibility:
DIR_LIST = $(dir1) $(dir2) $(dir3)
.PHONY: all
all: directories other_stuff
.PHONY: directories # Note: you should be marking this as phony
directories: $(DIR_LIST)
$(DIR_LIST):
mkdir -p $@
See http://www.gnu.org/software/make/manual/make.html#Multiple-Targets.
Upvotes: 1