0

I have a makefile with a bunch of .R scripts that create .csv files as output. These files are then used in a python simulation.

all: $(FILES)
  python simulation.py

$(FILES): %.csv: %.R 
  Rscript $<

This is straightforward. My wrinkle is that one (and only one) of the .R scripts has its own dependency, say sourcedata. It seems that placing this dependency in the pattern would be annoying

all: $(FILES)
  python simulation.py

$(FILES): %.csv: %.R sourcedata
  Rscript $<

sourcedata:
  wget "sourcedata.zip"

But doing it like all: sourcedata $(FILES) and relying on order-of-operations would be less effective. I guess that I could also give that R file its own phony rule

problem_script.R: sourcedata
  @echo R script read

but I haven't been able to test if that will work. Is there an established way to do this?

Community
  • 1
  • 1
gregmacfarlane
  • 2,121
  • 3
  • 24
  • 53

1 Answers1

3

Unless I'm misunderstanding, you need to specify that the particular CSV file needs to be rebuilt whenever either the R file or the sourcedata file changes, right?

If so, just add this:

problem_script.csv: sourcedata

(no recipe needed). This declares an extra prerequisite for that particular CSV file, so whenever it's out of date with respect to sourcedata it will be rebuilt.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Yeah, I think you had it. I guess I didn't know that a single target could have two different recipes; would this work if the second recipe were non-empty? I can't think of what that would mean... – gregmacfarlane Jun 09 '15 at 00:17
  • 1
    A target cannot have more than one recipe. You'll get an error (except for double-colon rules). However, you didn't declare a recipe, you just declared more prerequisites. You can declare as many sets of prerequisites as you like for the same target: they're just appended together. – MadScientist Jun 09 '15 at 04:47