Makefile inference rule

Conor P. Cahill cpcahil at virtech.uucp
Fri Jun 8 03:43:52 AEST 1990


In article <18769 at orstcs.CS.ORST.EDU> osbornk at cs.orst.edu (Kasey S. Osborn) writes:
>  .o:
>          cc -g $(OBJS) $< -o $@                # This is ignored!!!
>
>  box:    $(OBJS) box.o

First off, the NULL suffix is only used when you have a single source
for a single object.  In this case you do not meet that condition.

make is actually executing the commands that follow the line

	box:	$(OBJS) box.o

which happen to be nothing.

 
>The key here is the .o: inference rule.  It is completely ignored, yet

It is not ignored, it just doesn't apply.

>Ironically, if I remove the line:
>
>  box:    $(OBJS) box.o
>
>and invoke "make box", the .o: inference rule takes effect.  However,
>the additional dependencies (OBJS) are ignored.

That is because make then thinks that you have a single source file
makeing a program (box.o --> box) and the inference rule applies.

To make a program with more than one object file dependency you 
must have the commands for building that target following the
target/dependency line.  For  your example this would be:

	box:	$(OBJS) box.o
		$(CC) -g $(OBJS) box.o -o $@ 

If all you are trying to do is use the $OBJS to make more than one
program you could just define the following:

MAKE_PGM_FROM_OBJS = $(CC) -g $(OBJS) -o $@ 

And then your box make would be:

	box:	$(OBJS) box.o
		$(MAKE_PGM_FROM_OBJS) box.o

Hope this helps.
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.questions mailing list