Programming Utilities Guide

Library Members and Dependency Checking

make recognizes a target or dependency of the form:

lib.a(member . . . )

as a reference to a library member, or a space-separated list of members.


Note -

Earlier versions of make recognize this notation. However, only the first item in a parenthesized list of members is processed.


In this version of make, all members in a parenthesized list are processed. For example, the following target entry indicates that the library named librpn.a is built from members named stacks.o and fifos.o. The pattern-matching rule indicates that each member depends on a corresponding object file, and that object file is built from its corresponding source file using an implicit rule.

librpn.a:			librpn.a (stacks.o fifos.o)
           		ar rv $@ $?

             $@
librpn.a (%.o): %.o
             @true

When used with library-member notation, the dynamic macro $? contains the list of files that are newer than their corresponding members:

$ make 
cc -c stacks.c 
cc -c fifos.c 
ar rv librpn.a stacks.o fifos.o 
a - stacks.o 
a - fifos.o

Libraries and the $% Dynamic Macro

The $% dynamic macro is provided specifically for use with libraries. When a library member is the target, the member name is assigned to the $% macro. For instance, given the target libx.a(demo.o) the value of $% would be demo.o.

.PRECIOUS: Preserving Libraries Against Removal due to Interrupts

Normally, if you interrupt make in the middle of a target, the target file is removed. For individual files this is a good thing, otherwise incomplete files with brand new modification times might be left in the directory. For libraries that consist of several members, the story is different. It is often better to leave the library intact, even if one of the members is still out-of-date. This is especially true for large libraries, especially since a subsequent make run picks up where the previous one left off--by processing the object file or member whose processing was interrupted.

.PRECIOUS is a special target that is used to indicate which files should be preserved against removal on interrupts; make does not remove targets that are listed as its dependencies. If you add the line:

.PRECIOUS:  librpn.a

to the makefile shown above, run make, and interrupt the processing of librpn.a, the library is preserved.