Carl Carl - 1 month ago 6
R Question

makefiles with multiple targets

I have a simple makefile that runs an R program that generates 3 csv files. I used this SO answer:http://stackoverflow.com/a/3077254/4564432

But I don't feel this is working quite right.

.PHONY: all one clean

all: one

clean:
-rm *.csv

one: csv1.csv csv2.csv csv3.csv

csv1%csv csv2%csv csv3%csv: myProgram.R
R CMD BATCH $<


When I run
make
initially it works fine, runs my program, and generates my output. My understanding is that if I rerun make, without changing
myProgram.R
it should know not to run anything, but I find that with the above makefile that it reruns everything anytime I run
make
regardless of the time-stamp.

Any help would be appreciated.

edit:
using GNU MAKE 3.79.1

Answer:



I realize that my output, the csvs, were going into a different folder so I needed to do
one: myFolder/csv1.csv myFolder/csv2.csv etc.

Answer

I've changed your makefile to not require R but to simply perform the operations that I'm assuming R is performing, and I've tried it with GNU make 3.79.1 and the latest version, and it works as expected:

.PHONY: all one clean
all: one
clean: ; -rm *.csv
one: csv1.csv csv2.csv csv3.csv
csv1%csv csv2%csv csv3%csv: myProgram.R ; touch csv1$*csv csv2$*csv csv3$*csv

When I run this it works fine:

$ make-3.79.1
touch csv1.csv csv2.csv csv3.csv

$ make-3.79.1
make: Nothing to be done for `all'.

$ touch myProgram.R

$ make-3.79.1
touch csv1.csv csv2.csv csv3.csv

$ make-3.79.1
make: Nothing to be done for `all'.

This means that something is not right about either your environment (as rveerd suggests maybe your myProgram.R has a timestamp from the future) or else the "R" command is not creating all of those output files, or it's not updating the timestamps on those output files correctly.

After you run make you should use ls -al *.R *.csv and verify that all the files are created and that they have the expected timestamps.