Marijn van Vliet
Marijn van Vliet

Reputation: 5399

Rules with two % marks in GNU make

I'm trying to use GNU make to automate my analysis pipeline. I have a script that reads files with the pattern data/sub001/sub001_input.txt and writes to data/sub001/sub001_output.txt. How could I write a rule that matches this pattern for each subject? Here is my attempt so far:

# List of all the subjects
SUBJECTS ?= sub001 sub002 sub003

/data/%/%_output.txt : process.py data/%/%_input.txt
    python process.py $*

# for each $SUBJECT in $SUBJECTS
all : /data/$(SUBJECT)/$(SUBJECT)_output.txt
    @echo 'Data analysis complete!'

I would like the all target to call:

python process.py sub001
python process.py sub002
python process.py sub003

And I would like a single subject to be re-processed if the corresponding sub###_input.txt file changes, and I would like all subjects to be re-processed if the process.py file changes.

Upvotes: 0

Views: 33

Answers (1)

MadScientist
MadScientist

Reputation: 100836

You cannot use multiple pattern characters in pattern rules.

You can use a single pattern which will stand for the entire middle portion, then strip out the part you want like this:

/data/%_output.txt : process.py data/%_input.txt
        python process.py $(*F)

Upvotes: 2

Related Questions