|
|
The make program has an interface to archive libraries. A user can name a member of a library, as in these examples:
projlib(object.o)The second method actually refers to an entry point of an object file within the library. (The make program looks through the library, locates the entry point, and translates it to the correct object-filename.)projlib((entrypt))
To use this procedure to maintain an archive library, the following type of makefile is required for each object:
projlib:: projlib(pfile1.o) $(CC) -c -O pfile1.c $(AR) $(ARFLAGS) projlib pfile1.o rm pfile1.o projlib:: projlib(pfile2.o) $(CC) -c -O pfile2.c $(AR) $(ARFLAGS) projlib pfile2.o rm pfile2.oThis is tedious and error-prone. In most cases, the command sequences for adding a C language file to a library are the same for each invocation; the file name being the only difference each time.
The make command also gives the user access to a rule for building libraries. The handle for the rule is the .a suffix. A .c.a rule is the rule for compiling a C language source file, adding it to the library, and removing the .o file. Similarly, the .y.a, the .s.a, and the .l.a rules rebuild yacc, assembler, and lex files, respectively. The archive rules defined internally are .c.a, .c~.a, .f.a, .f~.a, .s.a, .s~.a, .C.a, and .C~.a. (The tilde (~) syntax will be described shortly.)
The user may define other needed rules in the makefile.
The two-member library mentioned earlier is then maintained with the following shorter makefile:
projlib: projlib(pfile1.o) projlib(pfile2.o) @echo projlib up-to-dateThe internal rules are already defined to complete the preceding library maintenance. The actual .c.a rule is as follows:
.c.a: $(CC) -c $(CFLAGS) $< $(AR) $(ARFLAGS) $@ $.o rm -f $.oIn this example, the $@ macro is the .a target (projlib); the $< and $ macros are set to the out-of-date C language file, and the filename minus the suffix, respectively (pfile1.c and pfile1). The $< macro (in the preceding rule) could have been changed to $.c.
This is what make does when it sees the construction:
projlib: projlib(pfile1.o) @echo projlib up-to-dateAssume the object in the library is out-of-date with respect to pfile1.c. Also, there is no pfile1.o file.
@echo projlib up-to-date
projlib(pfile1.o): $(INCDIR)/stdio.h pfile1.cThere is also a macro for referencing the archive member name when this form is used. The $% macro is evaluated each time $@ is evaluated. If there is no current archive member, $% is null. If an archive member exists, then $% evaluates to the expression between the parentheses.