Managing file interactions with make

Dynamic dependency parameters

A dynamic dependency parameter has meaning only on the dependency line in a makefile. The $$@ refers to the current ``thing'' to the left of the : symbol (which is $@). Also the form $$(@F) exists, which allows access to the file part of $@. Thus, in the following:

   cat:    $$@.c
the dependency is translated at execution time to the string cat.c. This is useful for building a large number of executable files, each of which has only one source file. For instance, the UNIX system software command directory could have a makefile like:
   CMDS = cat dd echo date cmp comm chown

$(CMDS): $$@.c $(CC) $(CFLAGS) $? -o $@

Obviously, this is a subset of all the single file programs. For multiple file programs, a directory is usually allocated and a separate makefile is made. For any particular file that has a peculiar compilation procedure, a specific entry must be made in the makefile.

The second useful form of the dependency parameter is $$(@F). It represents the file name part of $$@. Again, it is evaluated at execution time. Its usefulness becomes evident when trying to maintain the /usr/include directory from
makefile in the /usr/src/head directory. Thus, the /usr/src/head/makefile would look like

   INCDIR = /usr/include

INCLUDES = \ $(INCDIR)/stdio.h \ $(INCDIR)/pwd.h \ $(INCDIR)/dir.h \ $(INCDIR)/a.out.h

$(INCLUDES): $$(@F) cp $? $@ chmod 0444 $@

This would completely maintain the /usr/include directory whenever one of the above files in /usr/src/head was updated.
Next topic: The make command
Previous topic: SCCS makefiles

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004