[clug] Playing funny with make..

Daniel Pittman daniel at rimspace.net
Sun Sep 13 19:37:01 MDT 2009


Andrew Janke <a.janke at gmail.com> writes:

> Now that I have found most of the answers to doing weird things in
> /bin/sh it's makes turn.

[...]

> Now of course if I run make, on the first run only everything in 01-res will
> be made as the % (in native/%.native.mnc ) will only expand for files that
> exist. On the second run of make then everything in 02-nrm will be made an
> so on.. so
>
> 1) Is there a better way?

Probably.  Do you need to keep the intermediate files?  Think about that,
because by default the chained rules don't, but you can instruct make to.

Anyway, the better way is almost certainly to use the "chained rules" stuff
that can string together groups of transformations.  For example, DOC from
MarkDown via OOo and pandoc:

# This tells me what the expected output is.
all: whatever.doc

# Build the Word DOC file
%.doc: %.rtf
	unoconv -v -d document -f doc $< || \
	unoconv -v -d document -f doc $< || \
	unoconv -v -d document -f doc $< || \
	unoconv -v -d document -f doc $<

%.rtf: %.mdwn style/header.rtf
	pandoc $(PANOPT) -C style/header.rtf -s -t rtf -o $@ $<

That gives me a generic rule for converting *any* mdwn file into RTF, and any
RTF into DOC, which means that make will map a path from whatever.mdwn to
whatever.doc to satisfy my requests.

> (there are about 1000 *.native.mnc files in native/ so expanding all the
> names would seem a bit daft). I could use a monster
> foreach/addsuffix/addprefix stanza but I am unsure at what stage make might
> start to break down with these sorts of games.

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

> 2) Is there are way to make call itself again or re-expand rules?

target:
        $(MAKE) whatever
        $(MAKE) else

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