Subject: Re: make seems to find the wrong source file
To: Greywolf <firstname.lastname@example.org>
From: Frederick Bruckman <email@example.com>
Date: 01/11/2004 14:27:41
On Sun, 11 Jan 2004, Greywolf wrote:
> Thus spake David Laight ("DL> ") sometime Today...
> DL> With the following makefile:
> DL> .SUFFIXES:
> DL> .SUFFIXES: .a .b
> DL> all: .PHONY x.b
> DL> .a.b:
> DL> echo $<
> DL> x.b: dir/x.a
> 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> 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;
I understood that "dir/x.a" is supposed to exist. Try making that line
x.b: dir/x.a x.a
and "mkdir dir; touch dir/x.a x.a; make". Now try switching "x.a" with
"dir/x.a", or leaving off the dependencies altogether. David's beef is
that the implied source is calculated differently when there are
explicit dependencies, evidently being always the first source in that
case, which is not intuitive.
> Or did I miss completely what you were trying to say?
> 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.
The obvious workaround is to say what you mean, changing "$<" to "$*.a".