I’m trying to use the linux utility make in order to
- Run a script to generate the data
- Take all of the output files (data1.txt to data79.txt) and run a script to plot them each
- Take all those images and make a movie from them
Yes, I realize that doing this in a shell/python script would be downright simple but I’m trying to learn how to use make in this context to do the work more intelligently.
My current make file looks something like this but is significantly flawed:
movie: data *.png
ffmpeg data_%d.png output.mp4
%.png: %.txt
python plot.py $< $@
data:
python make_data.py
You have several problems, so let’s take them in order. (Caveats: I use GNUMake, so I can’t promise my solution will work with other flavors, and I am not familiar with ffmpeg.)
You can test this rule by itself: “make data”.
This will work if the data files already exist (and you can test it after “make data”), but when we first run make, the data files don’t exist. There are several ways to address this; the simplest is to run Make a second time from within a rule, after the data files have been made:
$(MAKE) output.mp4Putting it all together, we get something like this:
.PHONY: movie movie: data @$(MAKE) -s output.mp4 # I added the "@" and "-s" to make it quieter. dfiles = $(wildcard *.txt) images = $(dfiles:txt=png) output.mp4: $(images) ffmpeg data_%d.png $@ %.png: %.txt python plot.py $< $@ .PHONY: data data: python make_data.py(Note that some people like to put all the PHONY declarations together: “.PHONY: movie data”. I prefer to do it as above.)