user1781186
user1781186

Reputation:

Include target file with wildcards in makefile all directive

I thought this would be a no-brainer, but I can't seem to figure it out. Let's say I want to unzip all zip files in a directory and place the results in another directory. All files follow the pattern region_*.zip, where * is some id.

raster/region_%.tif: zip/region_%.zip
    unzip -d raster $<

My problem: How do I include this operation in my all directive?

# Does not work
all: raster_region_%.tif

Upvotes: 0

Views: 1129

Answers (1)

MadScientist
MadScientist

Reputation: 100836

Make always works backward from the target you want to create, back to the source files (in this case zip files).

Make has to be told, somehow, what the target you want to create is. It can't just intuit that out of thin air.

In this case, if you want to build a .tif file for each zip file you need to first get a list of all the zip files then convert them into the target files:

ZIPFILES := $(wildcard zip/region_*.zip)
TARGETS := $(patsubst zip/region_%.zip,raster/region_%.tif,$(ZIPFILES))

all: $(TARGETS)

Upvotes: 1

Related Questions