m

make(1)

make(1)

The most common use of the archive interface follows. Here, we assume the source ®les are all C type source:

lib: lib(file1.o) lib(file2.o) lib(file3.o) @echo lib is now up-to-date

.c.a:

$(CC) -c $(CFLAGS) $< ar rv $@ $*.o

rm -f $*.o

(See the section on Built-in Macros for an explanation of the <, @, and * symbols.) In fact, the .c.a rule listed above is built into make and is unnecessary in this example. This rule is applied to each dependent of lib in turn. The following example accomplishes this more ef®ciently:

lib: lib(file1.o) lib(file2.o) lib(file3.o) $(CC) -c $(CFLAGS) $(?:.o=.c)

ar rv lib $? rm $?

@echo lib is now up-to-date

.c.a:;

Here substitution in the macros is used. The $? list is de®ned to be the set of object ®le names (inside lib) whose C source ®les are out-of-date. The substitution sequence translates the .o to .c. (Unfor- tunately, one cannot as yet transform to .cÄ; however, this may become possible in the future.) Note also, the disabling of the .c.a rule, which would have created and archived each object ®le, one by one. This particular construct speeds up archive library maintenance considerably, but becomes very cumbersome if the archive library contains a mix of assembly programs and C programs.

Archive members containing the de®nition of a symbol are designated by double parentheses around the symbol name, lib((entry_name)), but are otherwise handled as described above.

Built-In Targets

make has knowledge about some special targets. These must be speci®ed in the make®le to take effect (with the exception of .SUFFIXES, which is automatically set by make but can be changed by the user).

.DEFAULT If a ®le must be made but there are no explicit commands or relevant built-in rules for it, the commands associated with the target name .DEFAULT are used if .DEFAULT has been de®ned in the make®le. .DEFAULT does not have any explicit dependents.

.PRECIOUS Dependents of this target are not removed when QUIT, INTERRUPT, TERMINATE, or HANGUP are received.

.SILENT Same effect as the -soption. No dependents or explicit commands need to be speci®ed.

.IGNORE Same effect as the -ioption. No dependents or explicit commands need to be speci®ed.

.SUFFIXES The explicit dependents of .SUFFIXES are added to the built-in list of known suf®xes and are used in conjunction with the inference rules. If .SUFFIXES does not have any dependents, the list of known suf®xes is cleared. There are no commands associated with .SUFFIXES.

.MUTEX Serialize the updating of speci®ed targets (See the Parallel Make Section).

Built-in Macros

There are ®ve internally maintained macros that are useful for writing rules for building targets. In order to clearly de®ne the meaning of these macros, some clari®cation of the terms target and dependent is necessary. When make updates a target, it may actually generate a series of targets to update. Before any rule (either explicit or implicit) is applied to the target to update it, recursion takes place on each dependent of the target. The dependent, upon recursion, becomes a target itself, and may have or generate its own dependents, which in turn are recursed upon until a target is found that has no dependents, at which point the recursion stops. Not all targets processed by make appear as explicit targets in the make®le; some of them are explicit dependents from the make®le while others are implicit dependents generated as make recursively updates the target. For instance, when the following make®le is executed:

pgm: a.o b.o

cc a.o b.o -o pgm

Section 1514

− 7 −

HP-UX Release 11i: December 2000