Subject: Re: make seems to find the wrong source file
To: <>
From: David Laight <>
List: tech-toolchain
Date: 01/11/2004 20:24:14
On Sun, Jan 11, 2004 at 11:58:03AM -0800, Greywolf wrote:
> Thus spake David Laight ("DL> ") sometime Today...
> DL> With the following makefile:
> DL>
> DL> .SUFFIXES: .a .b
> DL>
> DL> all: .PHONY x.b
> DL>
> DL> .a.b:
> DL>         echo $<
> DL>
> DL> x.b: dir/x.a
> DL>
> DL> make tries to generate x.b using the commands from the .a.b suffix rule,
> DL> but using the source file dir/x.a, rather that the source
> DL> file implied by the suffix rule.
> DL>
> DL> I'm not sure this is (ever) desirable.
> DL> Note that it requies the filename to match - so it will only ever
> DL> build x.a, never y.a using the commands from the suffix rule.
> It doesn't appear that it will ever build x.a at all unless you have
> an explicit rule for generating it; your ".a.b" rule says "This is how
> I translate .a files into .b files".

You have to create x.a yourself...
(and maybe dir/x.a, and possibly x.b for time comparisons)

What I expected is that x.b will be built from x.a and that it will be
built if x.a is newer than x.b or if dir/x.a is newer than x.b
(as happens if you replace the 'dir/x.a' with 'dir/y.a').

I've always assumed that the suffix rules are used whenever there are
no commands for a target.  The source file from the suffix rule being
used to generate the object file - regardless of what is contained in
any of the other dependency lines for the target.

> Did you, perhaps, mean that it
> would build x.b, not y.b, using the commands from the suffix rule?
> If so, I beg to differ:
> #Contents of makefile:
> .SUFFIXES: .a .b
> .a.b:
> 	echo default rule $< $> $? $* $@
> x.b:	./x.a
> y.b:	./y.a
> 	echo specific rule $< $> $? $* $@
> $ make x.b
> make: don't know how to make ./x.a(continuing)
> `x.b' not remade because of errors.
> $ make y.b
> make: don't know how to make ./y.a(continuing)
> `y.b' not remade because of errors.
> $ make z.b
> make: don't know how to make z.b(continuing)
> Stop.
> make: stopped in /tmp
> $ touch x.a y.a z.a
> $ make x.b
> echo default rule ./x.a ./x.a ./x.a x x.b
> default rule ./x.a ./x.a ./x.a x x.b
> $ make y.b
> echo specific rule ./y.a ./y.a ./y.a y y.b
> specific rule ./y.a ./y.a ./y.a y y.b
> $ make z.b
> echo default rule z.a z.a z.a z z.b
> default rule z.a z.a z.a z z.b
> $
> Or did I miss completely what you were trying to say?

Missed completely...
Your example is nice and simple and doesn't have anything in the 'wrong'

> DL> It causes particular problems when the 'x.b: dir/x.a' line comes
> DL> from the .depend file which also contains '.OPTIONAL: dir/x.a' and
> DL> the source files have all been moved to a different directory.
> I think that's a different problem altogether...

It is the one I needed to solve!


David Laight: