[clug] Playing funny with make..

Andrew Janke a.janke at gmail.com
Mon Sep 14 07:14:24 MDT 2009


> 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.
>
> 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

Thanks, It turns out that I was trying to do the right thing but
stuffed up when implementing it... bah!  I wrote a small test case:
(that works)

.SECONDARY:

.PHONY: all
all: main.html

main.html: c.all
	cat $? > main.html

in.%.txt:
	echo "# $(*F)" > $@

a.%.txt: in.%.txt
	cp in.$(*F).txt $@
	echo a >> $@

b.%.txt: a.%.txt
	cp a.$(*F).txt $@
	echo b >> $@
	
c.%.txt: b.%.txt
	cp b.$(*F).txt $@
	echo c >> $@

c.all: c.1.txt c.2.txt c.3.txt c.4.txt c.5.txt
	echo "c" > $@

clean:
	rm -f *.all in.*.txt a.*.txt b.*.txt c.*.txt main.html


And seems to do all that I want.  Now if only I could do something like this:

spencer:make-test$ make
[...]

$ ls
spencer:make-test$ l
a.1.txt  a.4.txt  b.2.txt  b.5.txt  c.3.txt  c.all    d.3.txt
in.1.txt  in.4.txt   Makefile
a.2.txt  a.5.txt  b.3.txt  c.1.txt  c.4.txt  d.1.txt  d.4.txt
in.2.txt  in.5.txt
a.3.txt  b.1.txt  b.4.txt  c.2.txt  c.5.txt  d.2.txt  d.5.txt
in.3.txt  main.html

spencer:make-test$ rm c.2.txt

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

And have it remake c.2.txt without having to write some enormous
long-winded rule that includes everything.  Anyone know if there is a
make incantation to "remake all intermediate files".


Thanks again.


a

PS: the other advantage of make is that you can just make -j8 to run
on a local machine only and suck up all the CPU's safe in the
knowledge that it will "do the right thing".


More information about the linux mailing list