[clug] Playing funny with make..
Daniel Pittman
daniel at rimspace.net
Sun Sep 13 21:20:40 MDT 2009
Andrew Janke <a.janke at gmail.com> writes:
>> Probably. Do you need to keep the intermediate files?
>
> Definitely.
>
>> Think about that,
>> because by default the chained rules don't, but you can instruct make to.
>
> you mean via: .SECONDARY: ...
I don't honestly remember. There is some mechanism, perhaps a command line
switch, or a setting in the Makefile, that tells make not to delete
intermediate stuff. (...and I am too lazy to read the info page for you. ;)
>> Anyway, the better way is almost certainly to use the "chained rules" stuff
>> that can string together groups of transformations.
>
> This is what I _thought_ I was doing... :)
[...]
> Although in my case I would have to expand "whatever.doc" to 1000+
> files. Thus my question about at what point should I expect make to break
> down with such games?
I don't honestly know. I only ever do very, very small batch processing
things in make. FWIW, I would probably use a patsubst, or shell, callout to
do the 1000 item dependency list dynamically rather than statically. :)
>> ...then, once you have generic rules to produce your output from the input
>> you can use one single "source to target" transformation and let make
>> figure out the bits in the middle.
>
> Hrm, perhaps I am doing it wrong in other ways then. Currently the rough
> overview of dependencies is this: (main.html is a summary output file, and
> this is simplified in which there are only three processing stages).
>
> all: main.html
>
> main.html: 01-aaa.chk 02-bbb.chk 03-ccc.chk ...
> [dostuff]
>
>
> all.01-aaa: $(addsuffix .01-aaa.chk, $(files))
> touch $@
%-aaa.chk: %
>
> all.02-bbb: $(addsuffix .01-aaa.chk, $(files))
> touch $@
>
> all.03-ccc: $(addsuffix .02-bbb.chk, $(files))
> touch $@
>
>
> %.01-aaa.chk: %.native.chk
> [dostuff]
>
> %.02-bbb.chk: %.01-aaa.chk
> [dostuff]
>
> %.03-ccc.chk: %.02-bbb.chk
> [dostuff]
>
>
>
> And the chaining is not happening. Is this then because main.html should
> instead only depend on the last stage? ie:
>
> main.html: 03-ccc.chk ...
> [dostuff]
>
> and I should ignore the all.02-bbb and 03-ccc rules?
Yes, that is the mechanism. You specify *pattern* rules for each stage, using
the '%' wildcard to replace the individual filename, and let make string that
together.
So, the pattern rule '%.o: %.c' can stand in for *any* 'whatever.o:
whatever.c' rule.
So, for a three stage process (with my own names, because I am not certain of
the names of yours, I fear):
results: a.stage3 b.stage3 ... z.stage3
# whatever you have to do here...
%.stage3: %.stage2
make-stage3 > $< < $@ # or is that back to front?
%.stage2: stage1-processed-%.data
make-stage2 ...
stage1-processed-%.data: %.raw
# turn a.raw into stage1-processed-a.data
Then run 'make results' and you get:
results => a.stage3 # supplied by you
a.stage3 => a.stage2 # make infers this
a.stage2 => stage1-processed-a.data
stage1-processed-a.data => a.raw
b.stage3 => b.stage2
# ...etc
You have to tell make *somewhere* what results you want, but it can calculate
the intermediate path for you automatically.
FWIW, the system includes a whole bunch of rules of that sort, such as:
%.o: %.c
cc -c -o $@ $<
'make -p' will dump the internal database, including implicit variables and
implicit rules, to give you a solid example of what the defaults are.
Regards,
Daniel
--
✣ Daniel Pittman ✉ daniel at rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
Looking for work? Love Perl? In Melbourne, Australia? We are hiring.
More information about the linux
mailing list