make's primary function is to execute the steps required to produce a new version of a specific (target) program. make operates using the following information sources:
1 menu : x.o y.o z.o assmb.o abc.a 2 cc x.o y.o z.o assmb.o /usr/fred/lib/abc.a -o menu 3 x.o : x.c defs.h 4 cc -c x.c 5 y.o : y.c defs.h 6 cc -c y.c 7 z.o : z.c 8 cc -c z.c 9 assmb.o : assmb.s 10 as -o assmb.o assmb.sThe description file contains four entries. Each entry contains a line with a colon (the dependency line), and one or more command lines beginning with a tab. To the left of the colon, on the dependency line, are one or more targets; to the right of the colon are the files (components) on which the targets depend. The tab-indents lines illustrate how targets are made from their components.
For example, line 1 states that the program depends on files x.o, y.o, z.o, the assmb.o assembly object file and the library abc.a. Line 2 specifies the linker and compiler commands used in creating the program from its components. make executes this command if menu does not exist or if any of the component files was modified after the `last-modified' (timestamp) date of menu.
make uses the remainder of the information contained in the description file to ensure that each component is up-to-date before executing the cc(CP) command (line 2). Line 3 indicates that x.o depends on x.c and defs.h. If either of these has been modified, then x.c is recompiled, as directed by the command line (line 4). y.o has similar dependencies, as described in line 5. Line 7 shows that z.o has only one dependency. After all the subordinate dependencies have been brought up-to-date, make executes the command (cc) shown in line 2.
If none of the source or object files have changed since the last time menu was created, and all of the files are current, the make command announces this fact and stops.
These entries can take advantage of make's ability to generate files and substitute macros. See ``Macro definitions'' For information about macros. For example, an entry `save' might be included to copy a certain set of files, or an entry `clean' might be used to throw away unneeded intermediate files. For example:
clean: rm *.oIf the following command is issued, all object files are deleted.
If a file exists after such commands are executed, the file's time of last modification is used in further decisions. If the file does not exist after the commands are executed, the current time is used in making further decisions.
Maintaining a zero-length file to keep track of the time at which certain actions were performed is useful for updating remote archives and listings.
The above description file can be simplified even further by using the existing naming and compiling conventions, provided in the UNIX system environment. C language sources always have a .c suffix; a convention imposed by the cc compiler. Similarly, assembly language sources have a .s suffix. These conventions allow make, acting upon a set of `suffix rules', to perform many tasks. For example:
menu : x.o y.o z.o assmb.o /usr/fred/lib/abc.a cc -o menu x.o y.o z.o assmb.o /usr/fred/lib/abc.aIn building menu, make first checks whether x.o is up-to-date. It checks any file in the current directory that, according to the standard suffix rules, could be used to make x.o. If it locates a file, x.c, and if that file has been changed since x.o was last made, make applies one of its own rules by invoking the C compiler on x.c. Similarly, this occurs with the assembler files, which have a .s suffix.
By knowing and using the default suffix rules, or by creating new ones, the complexity of the description files can be reduced. See ``Suffixes and transformation rules'' for more information on suffixes.