Reputation: 1652
I have a Makefile where I use the Rscript
command to make a variety of different targets using R scripts.
object.rds: script1.R
Rscript $<
target.csv: script2.R
Rscript $<
another.rds: script3.R target.csv object.rds
Rscript $<
Is there a way to define a universal rule such that any recipe with a file matching the %.R
pattern as the first prerequisite always runs Rscript $<
? For instance, something like:
**: %.R **
Rscript $<
I guess the thing I'm looking for is the inverse of a last resort rule -- i.e. a recipe with an arbitrary target but a specific prerequisite (or, at least, one based on a pattern).
(Note that this is not specific to R -- I could ask the exact same question with python, ruby, bash, etc.)
Upvotes: 1
Views: 111
Reputation: 21040
Pattern rules need to match a pattern, if your target filenames have no connection to the Rscript filename you might as well just provide a single recipe for the three targets and specify the dependencies separately
object.rds: script1.R
target.csv: script2.R
another.rds: script3.R target.csv object.rds
object.rds target.csv another.rds:
Rscript $<
Upvotes: 1
Reputation: 6387
You could create an intermediate target:
%.R_run: %.R
Rscript $<
object.rds: script1.R_run
target.csv: script2.R_run
another.rds: script3.R_run target.csv object.rds
Such that object.rds
depends on script1.R
having been run.
Upvotes: 0