What's wrong with this picture (makefile bug?)
Greg Noel
greg at ncr-tp.UUCP
Tue Mar 19 15:49:47 AEST 1985
In article <177 at osiris.UUCP> eric at osiris.UUCP (Eric Bergan) writes:
>......................................... Has anyone gotten user defined
>suffixes to work correctly?
Er, I don't know how to break this to you, but make is working exactly
as advertised; it is your makefile that is not correct. The thing you
need to understand is that make will take no leaps of faith in finding
the files it needs -- in other words, it won't chain rules together.
In particular, the fragment:
> mtest: mtest.o
> cc -o mtest mtest.o
says that mtest depends upon mtest.o -- a reasonable thing. Since mtest.o
does not exist, make now tries to find a way to make it. It does this by
searching for a rule of the form ".XXX.o" for which mtest.XXX \already/
\exists/. It can't find it, hence it says "don't know how to make mtest.o".
> However if I do "make mtest.c" and then "make mtest" it works fine.
Yep -- it knows how to convert mtest.qc into mtest.c using the rule you
have given and it knows how to convert mtest.c into mtest.o using the
built-in rule, but it won't chain the rules. If you think about it, this
is a reasonable restriction: suppose you have the rules .y.c, .y.s, .c.o,
and .s.o and you want to convert xx.y into xx.o -- there are two possible
paths (.y => .c => .o and .y => .s => .o) and it couldn't chose between
them.
> If I change the makefile to:
>
> [ same as before ]
>
> mtest.o: mtest.c
>
>and the only file is "mtest.qc", and I do a "make mtest", it works fine.
Again true -- this time you have given make an explicit dependancy so that
make knows that it must create mtest.c, so it searchs to find a rule
.XXX.c for which a file mtest.XXX already exists; it finds the rule .qc.c
and the file mtest.qc. It then applies the rule, making mtest.c, and then
tries to make mtest.o again. Since you didn't give any specific actions
for making mtest.o, it applies the search rules again, looking for a rule
.XXX.o and a file mtest.XXX; this time it finds .c.o and mtest.c. (Just
because you said you needed it doesn't mean that make will use it -- if you
had a mtest.s in the directory (and the .SUFFIXES were in a slightly
different order), this makefile would make mtest.c as you told it, but
then it would make mtest.o by assembling mtest.s. It can be confusing
at times......)
To cause make to combine the rules in the way you want, you must explicitly
tell it how. I.e., you must have a rule that goes from your special suffix
all the way to the desired object:
.SUFFIXES: .qc
.qc.o:
cat $< >$*.c
$(CC) $(CFLAGS) -c $*.c
rm -f $*.c
Hope this helps.
--
-- Greg Noel, NCR Torrey Pines Greg at ncr-tp.UUCP or Greg at nosc.ARPA
More information about the Comp.unix.wizards
mailing list