I'm using make to grab a set of files that are updated daily on a Web site. What I'd like to do is place the files into a folder named with the date, and then use make to do other processing on the file. I tried this:

FILES = file1.csv file2.csv file3.csv
BASE_DIR = some/dir
DATE = $(shell date +"%Y%m%d")
SOURCE_FILES = $(patsubst %,$(BASE_DIR)/$(DATE)/%,$(FILES))
ACTIVE_FILES = $(patsubst %,$(BASE_DIR)/%,$(FILES))


$(BASE_DIR)/%.csv: $(BASE_DIR)/$(DATE)/%.csv
    rm -f $@
    ln $(BASE_DIR)/$(DATE)/%

    mkdir $@

    cd $(BASE_DIR)/$(DATE); wget http://example.com/data/%.csv

The problem is the last line. I don't know how to pass the filename to wget, since "%.csv" isn't valid in this context. How do I accomplish what I'm after?


I believe you want to use automatic variable $*. From GNU make's documentation:


The stem with which an implicit rule matches. If the target is dir/a.foo.b and the target pattern is a.%.b then the stem is dir/foo. The stem is useful for constructing names of related files. In a static pattern rule, the stem is part of the file name that matched the % in the target pattern.

In your specific case, the wget rule could be rewritten as:

    cd $(BASE_DIR)/$(DATE); wget http://example.com/data/$*.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.