[net.followup] my Makefile query

mike (06/08/82)

Thanks to all who responded to my query about a makefile problem.
The problem was, we wanted to write a general rule for updating
commands, but we didn't have a way to specify that a command
depended on its own object file.  Here is one of many responses:

   From alice!npois!harpo!fortune!stein Tue Jun  8 07:21:35 1982*
   Subject: makefile trick

   Your problem is solved by a new dependency parameter included in
   the system-III version of make.  $$@ is defined to refer to the current
   `thing' to the left of the colon (which is $@).  Your makefile becomes:

      COMMANDS = X Y Z
      OBJECTS  = a.o b.o c.o
      LIBRARIES= lib1 lib2

      $(COMMANDS) : $$@.o $(OBJECTS) $(LIBRARIES)
		cc -o $@ $@.o $(OBJECTS) $(LIBRARIES)

   The dependencies implicitly defined above are:
      X : X.o $(OBJECTS) $(LIBRARIES)
      Y : Y.o $(OBJECTS) $(LIBRARIES)
      Z : Z.o $(OBJECTS) $(LIBRARIES)

   The built-in rules .x.o should take care of the .o dependencies.

   If you don't have access to the system-III make, your best bet is
   probably the following:

      COMMANDS = X Y Z
      OBJECTS  = a.o b.o c.o
      LIBRARIES= lib1 lib2

      $(COMMANDS) : $(OBJECTS) $(LIBRARIES)
		cc -o $@ $@.o $(OBJECTS) $(LIBRARIES)

      X : X.o
      Y : Y.o
      Z : Z.o


   A little bulkier, but it will work.

   Hope this helps.

	Mark Stein
	harpo!fortune!stein

(M. J. Hawley  rabbit!mike)