Makefile help needed
nmeyers at javalinux.net
nmeyers at javalinux.net
Sat Jul 2 07:52:40 EDT 2005
On Sat, Jul 02, 2005 at 02:16:32AM -0400, David Kramer wrote:
> My makefile is *mostly* working...
I'm having a little trouble interpreting this part of your note:
> all: target1 target2 target3 ../otherdir/troubletarget.o
> I get "make: *** No rule to make target ../otherdir/troubletarget.o"
> which I can understand, because it doesn't know where the C file is.
>
> HOWEVER, if I do:
> all: target1 target2 target3 ../otherdir/troubletarget.o
> it simply does not try to build it at all.
... it seems to be describing two different responses to the same thing.
> If I change that to
> ../otherdir/troubletarget.o: troubletarget.c
> $(CC) $(CFLAGS) -c $< -o $@
> it works, but I don't see why I have to do that, since it already knows
> how to turn a .c into a .o, because earlier in the file I have
> .c.o:
> $(CC) $(CFLAGS) -c $< -o $@
> which should build it fine,
The Make manual says:
A double-suffix rule is defined by a pair of suffixes: the target
suffix and the source suffix. It matches any file whose name ends with
the target suffix. The corresponding implicit prerequisite is made by
replacing the target suffix with the source suffix in the file name.
A two-suffix rule whose target and source suffixes are `.o' and `.c'
is equivalent to the pattern rule `%.o : %.c'.
This suggests to me that it will fail for the same reason...
> Note that I can't use the newer style
> %.o : %.c ; command...
> because the stem is different on the .o and the .c since they're in
> different directories.
... that the pattern rule fails.
It looks like you've already found a solution to your problem - you just
don't like it :-).
Nathan
More information about the Discuss
mailing list