MAKE(1)

NAME
make - maintain program groups

SYNOPSIS
make [ -f makefile ] [ option ] ... file ...

DESCRIPTION
Make executes commands in makefile to update one or more target names. Name is typically a program. If no -f option is present, `makefile' and `Makefile' are tried in order. If makefile is `-', the standard input is taken. More than one -f option may appear.

Make updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist.

Makefile contains a sequence of entries that specify dependencies. The first line of an entry is a blank-separated list of targets, then a colon, then a list of prerequisite files. Text following a semicolon, and all following lines that begin with a tab, are shell commands to be executed to update the target. If a name appears on the left of more than one `colon' line, then it depends on all of the names on the right of the colon on those lines, but only one command sequence may be specified for it. If a name appears on a line with a double colon :: then the command sequence following that line is performed only if the name is out of date with respect to the names to the right of the double colon, and is not affected by other double colon lines on which that name may appear.

Two special forms of a name are recognized. A name like a(b) means the file named b stored in the archive named a. A name like a((b)) means the file stored in archive a containing the entry point b.

Sharp and newline surround comments.

The following makefile says that `pgm' depends on two files `a.o' and `b.o', and that they in turn depend on `.c' files and a common file `incl'. pgm: a.o b.o cc a.o b.o -lm -o pgm

a.o: incl a.c cc -c a.c

b.o: incl b.c cc -c b.c Makefile entries of the form

    string1 = string2

are macro definitions. Subsequent appearances of $(string1) or ${string1} are replaced by string2. If string1 is a single character, the parentheses or braces are optional.

Make infers prerequisites for files for which makefile gives no construction commands. For example, a `.c' file may be inferred as prerequisite for a `.o' file and be compiled to produce the `.o' file. Thus the preceding example can be done more briefly: pgm: a.o b.o cc a.o b.o -lm -o pgm

a.o b.o: incl Prerequisites are inferred according to selected suffixes listed as the `prerequisites' for the special name `.SUFFIXES'; multiple lists accumulate; an empty list clears what came before. Order is significant; the first possible name for which both a file and a rule as described in the next paragraph exist is inferred. The default list is

    .SUFFIXES: .out .o .c .e .r .f .y .l .s .p

The rule to create a file with suffix s2 that depends on a similarly named file with suffix s1 is specified as an entry for the `target' s1s2. In such an entry, the special macro $* stands for the target name with suffix deleted, $@ for the full target name, $< for the complete list of prerequisites, and $? for the list of prerequisites that are out of date. For example, a rule for making optimized `.o' files from `.c' files is

    .c.o: ; cc -c -O -o $@ $*.c

Certain macros are used by the default inference rules to communicate optional arguments to any resulting compilations. In particular, `CFLAGS' is used for cc(1) options, `FFLAGS' for fortran(1) options, `PFLAGS' for pascal(1) options, and `LFLAGS' and `YFLAGS' for lex and yacc(1) options. In addition, the macro `MFLAGS' is filled in with the initial command line options supplied to make. This simplifies maintaining a hierarchy of makefiles as one may then invoke make on makefiles in subdirectories and pass along useful options such as -k.

Another special macro is `VPATH'. The `VPATH' macro should be set to a list of directories separated by colons. When make searches for a file as a result of a dependency relation, it will first search the current directory and then each of the directories on the `VPATH' list. If the file is found, the actual path to the file will be used, rather than just the filename. If `VPATH' is not defined, then only the current directory is searched.

One use for `VPATH' is when one has several programs that compile from the same source. The source can be kept in one directory and each set of object files (along with a separate makefile) would be in a separate subdirectory. The `VPATH' macro would point to the source directory in this case.

Command lines are executed one at a time, each by its own shell. A line is printed when it is executed unless the special target `.SILENT' is in makefile, or the first character of the command is `@'.

Commands returning nonzero status (see intro(1)) cause make to terminate unless the special target `.IGNORE' is in makefile or the command begins with <tab><hyphen>.

Interrupt and quit cause the target to be deleted unless the target is a directory or depends on the special name `.PRECIOUS'.

Other options:

-Pn Permit n command sequences to be done in parallel with `&'. See PARALLEL SUPPORT section below. If this option is present multiple times on the command line, the least value for n supercedes the others. If this option is missing, make looks for the environment variable PARALLEL and uses its numeric value for n. If this fails, n defaults to 3.

-i  Equivalent to the special entry `.IGNORE:'.

-k  When a command returns nonzero status, abandon work on the current entry, but continue on branches that do not depend on the current entry.

-n  Trace and print, but do not execute the commands needed to update the targets.

-t  Touch, i.e. update the modified date of targets, without executing any commands.

-r  Equivalent to an initial special entry `.SUFFIXES:' with no list.

-s  Equivalent to the special entry `.SILENT:'.

PARALLEL SUPPORT
Make includes a parallel processing ability. If the string separating a target from its prerequisites is `:&' or `::&', make can run the command sequences to make the prerequisites simultaneously. If two names are separated by an ampersand on the right side of a colon, those two may be created in parallel.

In this example Makefile, if the objects `a.o', `b.o', and `c.o' are out of date, they are built in parallel:
pgm: &    a.o b.o c.o
    cc -o pgm a.o b.o c.o
a.o:    a.c defs.h
b.o:    b.c defs.h
c.o:    c.c defs.h
In this example, only `a.o' and `b.o' are built in parallel, with `c.o' being started after the other two complete:
pgm:    a.o & b.o c.o
    cc -o pgm a.o b.o c.o
a.o:    a.c defs.h
b.o:    b.c defs.h
c.o:    c.c defs.h
Since the -P option is not compatible with other versions of make, you can avoid problems by creating a shell script called make, and placing it in /usr/local: #!/bin/sh if [ $# != 0 ] then
    exec /bin/make P='&' "$@" else
    exec /bin/make P='&' fi and changing your targets from their present construct: FILES : headers.o main.o to a portable form: FILES :$(P) headers.o main.o If you use this technique, make is portable between systems. The -P option controls the number of simultaneous command streams. Make invoked with an argument of -P1 selects no parallelism, and is useful when error messages from parallel command sequences are intermingled, obscuring the actual source of error. (A useful technique for searching the output for error messages is to look for lines that do not begin with a tab character.)

To execute command sequences in parallel, make forks off processes without waiting for them, and indicates they've been forked by appending an ampersand and the process ID while printing the command (similar to using the ampersand to indicate asynchronous jobs in the shell). If the forked-off command sequence returns a non-zero exit status, make precedes the error (or warning) message with the process ID, to help determine the source of the error.

Not all command sequences can be made parallel. Some command sequences generate filenames in the current directory that do not depend on the file being built. For example, operations involving two or more usages of yacc, lex, or xstr in the same directory cannot be made parallel.

While building the prerequisites in parallel, only the last (or only) command in a multiple command sequence is eligible to be forked for asynchronous execution. Other commands are executed sequentially. For example, in the following Makefile, only `lastcommand' is run in parallel; `firstcommand' and `secondcommand' are processed before any of the commands to build `b' are invoked: pgm:& a b a:
    firstcommand
    secondcommand
    lastcommand b:
    b-firstcommand
    b-secondcommand
    b-lastcommand To circumvent this, make all the commands be considered as one long shell command, as in: pgm:& a b a:
    firstcommand; \
    secondcommand; \
    lastcommand b:
    b-firstcommand; \
    b-secondcommand; \
    b-lastcommand The backslash at the end of a command line causes the following line to be regarded as a continuation. A Makefile set up in this way will have all the commands to build `a' be run in parallel with all the commands to build `b'. Note that all three commands to build `a' are now executed by the same shell (rather than three separate invocations of the shell). Commands interpreted by the shell directly (to change directory, for example) are no longer isolated to one particular command line. This should be taken into consideration when altering the Makefiles in this way.

FILES
makefile, Makefile

SEE ALSO
fortran(1), pascal(1), sh(1), touch(1), Make - A Program for Maintaining Computer Programs

BUGS
Some commands return nonzero status inappropriately. Use -i to overcome the difficulty.
Commands that are directly executed by the shell, notably cd(1), are ineffectual across newlines in make.

`VPATH' is intended to act like the System V `VPATH' support, but there is no guarantee that it functions identically.