erikfas
erikfas

Reputation: 4587

Unix Make: script that creates multiple files

I just started trying to use make for my data analyses pipelines, but I've run into a snag. Most of my scripts have one input file and one output file, which makes it very easy to create rules. Some, however, creates several output files, which creates problems with how far I've come in knowing how make works. For example...

all:    results/list.txt \
        results/stats.txt \
        results/image.png

.PHONY: all

results/list.txt results/stats.txt results/image.png: analysis.R data.txt
        $^ results/ -c blue,red -p 

... where analysis.R takes a directory and outputs the three files named. While the above recepe works fine and does output the three files, the script is run three times, rather than just one. I think make sees that the it needs to build all three files, and then calls the scripts three times because it thinks it needs a separate call for each.

What am I doing wrong, and how can I get it to run only once? Is there some clever way to create rules for scripts that have more than one output?

Upvotes: 1

Views: 38

Answers (1)

Perhaps add some other phony target:

 .PHONY: all doresults

with a rule running the test:

 doresults: analysis.R data.txt
     $^ results/ -c blue,red -p 

and

 all: doresults

or consider using some timestamp file....

Upvotes: 1

Related Questions