Dynamic dependency parameters

A dependency line consists of a target to the left of the colon, and a dependent (components) to the right of the colon. A target may be a large number of executable files, having one source file each. Each of the executable files must be compiled separately using its own source file. This creates a long and tedious makefile. make can create a list of executables under one name. For example:

   CMDS = cat dd echo date cc cmp comm ar ld chown
When a $@ macro is used to the right of the colon in a makefile, replace the dependent (components) with the target name (which contains the list of executables requiring compilation). This is the dynamic dependency parameter. It is dynamic because each of the components contained in CMDS is used. For example, the following compiles all the components previously defined in the target (CMDS) with a two-line entry in the makefile:
   $(CMDS) : $$@.c
   	$(CC) $? -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 filename part of $$@. Again, it is evaluated at execution time. Its usefulness becomes evident when trying to maintain the /usr/include directory from a makefile in the /usr/src/head directory. Therefore, the /usr/src/head/makefile looks like this:

   INCDIR = /usr/include

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

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

This completely maintains the /usr/include directory whenever one of the above files in /usr/src/head is updated.

Next topic: Environment variables
Previous topic: include files

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003