I have some trouble with my Makefile:
# Manage rendering of images
.PHONY: explode
all: explode anime.apng
out.ppm: file.code
./pgm -f $<
explode: out.ppm
split -d -a 3 --lines=$(N) --additional-suffix=.ppm $< frame
# Convert to multiple png
%.png: %.ppm
convert $< $@
optipng $@
# Assemble in one animated png
anime.apng: %.png
apngasm $@ frame000.png
My problem is: I don’t know how many intermediate files I will have to produce my final target, so I can’t specify them in advance. Schematically:
1 file.code -> 1 out.ppm |> LOADS of .ppm |> LOADS of .png -> 1 anime.apng
+> … +> …
+> … +> …
For that I use an implicit rule %.png: %.ppm. But then I cannot specify a prerequisite for my last merge step! Any ideas? With another tool than make? Anything elegant?
I think a simple and rather clean approach would be to have a variable record the list of those ‘LOADS’ of ppm, in my example it’s variable STEP2.
Surely you can use the program that gets you from ‘1 out.ppm’ to ‘LOADS of .ppm’ to list the .ppm files that you will obtain.
With a very trivial exemple where out.ppm would be a text file listing the names of the .ppm to produce, you would write something like :
Then you’ll need to write a rule to get all the files listed in STEP2 from the file $(STEP1). This is done file by file as if it was an implicit rule with a % pattern, assuming your program is called ‘extractor’ :
This rule will be applied once for each file listed in STEP2. This assumes that your program only wants the names of the source and output files. Should you prefer to pass the stem of the output file, you can still use a plain ol’ implicit rule :
(The $(STEP2): at the begining is to prevent make from using this rule to generate out.ppm)
Then, everything is as usual when it comes to compilation and you can adapt rules for compiling and linking any C projet. The %.ppm -> %.png step is like compiling %.c to %.o :
To group everything at the end (equivalent of linking several %.o into only one binary) :
I’m assuming here that apngasm can take the list of everything to put together as arguments à la tar.
Hope it’s clear and helpful enough.