.TH MAKE 1
.SH NAME
make \- maintain collections of programs
.SH SYNOPSIS
.B ape/make
[
.B \-f
makefile ] [ option ] ...
[ name ] ...
.SH DESCRIPTION
.I Make
executes commands in
.I makefile
to update
the target
.IR names
(usually programs).
If no target is specified, the targets of the first rule in
.I makefile
are updated.
If no
.B \-f
option is present, `makefile' and `Makefile' are
tried in order.
If
.I makefile
is `\-', the standard input is taken.
More than one
.B \-f
option may appear.
.PP
.I 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.
The prerequisites are updated before the target.
.PP
The makefile
comprises a sequence of rules and macro definitions.
The first line of a rule is a
blank-separated list of targets, then a single or double colon,
then a list of prerequisite files terminated by semicolon or newline.
Text following a semicolon, and all following lines
that begin with a tab, are shell commands
to be executed to update the target.
.PP
If a name appears as target in more than one single-colon rule, it depends
on all of the prerequisites of those rules, but only
one command sequence may be specified among the rules.
A target in a double-colon rule is updated by the following
command sequence only if it is out of date with respect to the
prerequisites of that rule.
.PP
Two special forms of name are recognized.
A name like
.IR a ( b )
means the file named
.I b
stored in the archive named
.I a.
A name like
.IR a (( b ))
means the file stored in archive
.I a
and containing the entry point
.I b.
.PP
Sharp and newline surround comments.
.PP
In this makefile `pgm' depends on two
files `a.o' and `b.o', and they in turn depend on
`.c' files and a common file `ab.h':
.RS
.HP
.PD 0
.nf
pgm: a.o b.o
cc a.o b.o \-lplot \-o pgm
.HP
a.o: ab.h a.c
cc \-c a.c
.HP
b.o: ab.h b.c
cc \-c b.c
.fi
.RE
.PD
.PP
Makefile lines of the form
.IP
string1 = string2
.LP
are macro definitions.
Subsequent appearances of
.RI $( string1 )
are replaced by
.IR string2 .
If
.I string1
is a single character, the parentheses are optional.
Each entry in the environment (see
.IR sh (1))
of the
.I make
command is taken as a macro definition,
as are command arguments with embedded equal signs.
.PP
A target containing a single `%' introduces a pattern rule,
which controls the making of names that do not occur
explicitly as targets.
The `%' matches an arbitrary string called the stem:
A%B matches any string that begins with A and ends with B.
A `%' in a prerequisite name stands for the stem;
and the special macro `$%' stands for the stem in the
construction commands.
A name that has no explicit rule is
matched against the target of each pattern rule.
The first pattern rule for which the prerequisites exist
specifies
further dependencies.
.PP
This pattern rule maintains an object library where all the C source files
share a common include file `defs.h'.
The macro `CFLAGS' sets compiler options.
.RS
.HP
.PD 0
.nf
.HP
arch.a(%.o) : %.c defs.h
cc $(CFLAGS) -c $%.c
ar r arch.a $%.o
rm $%.o
.fi
.RE
.PD
.PP
A set of default pattern rules is built in, and effectively
follows the user's list of rules.
Assuming these rules,
which tell, among other things, how to make `.o' files
from `.c' files, the first example becomes:
.RS
.HP
.PD 0
.nf
pgm: a.o b.o
cc a.o b.o \-lplot \-o pgm
.HP
a.o b.o: ab.h
.fi
.RE
.PD
.PP
Here, greatly simplified, is a sample of the built-in rules:
.PP
.RS
.PD 0
.nf
.HP
CC = cc
.HP
%.o: %.c
$(CC) $(CFLAGS) \-c $%.c
.HP
%.o: %.f
f77 $(FFLAGS) \-c $%.f
.HP
% : %.c
$(CC) $(CFLAGS) \-o $% $%.c
.fi
.RE
.PD
.PP
The first rule
says that a name ending in `.o' could be made
if a matching name ending in `.c' were present.
The second states a similar rule for files ending in `.f'.
The third says that an arbitrary name can be made
by compiling a file with that name suffixed by `.c'.
.PP
Macros make the builtin pattern rules flexible:
CC names the particular C compiler, CFLAGS gives
.IR cc (1)
options, FFLAGS for
.IR f77 (1),
LFLAGS for
.IR lex (1),
YFLAGS for
.IR yacc (1),
and PFLAGS for
.IR pascal (1).
.PP
An older, now disparaged, means of specifying default rules
is based only on suffixes.
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.
.PP
The rule to create a file with suffix
.I s2
that depends on a similarly named file with suffix
.I s1
is specified as an entry
for the `target'
.IR s1s2 .
Order is significant; the first possible name for which both
a file and a rule exist
is inferred.
An old style rule for making
optimized `.o' files from `.c' files is
.IP
\&.c.o: ; cc \-c \-O \-o $@ $*.c
.PP
The following two macros are defined for use in any rule:
.nf
$($@) full name of target
$($/) target name beginning at the last slash, if any
.fi
.LP
A number of other special macros are defined
automatically in rules invoked by one of the implicit mechanisms:
.nf
$* target name with suffix deleted
$@ full target name
$< list of prerequisites in an implicit rule
$? list of prerequisites that are out of date
$^ list of all prerequisites
.LP
The following are included for consistency with System V:
.nf
$(@D) directory part of $@ (up to last slash)
$(@F) file name part of $@ (after last slash)
$(*D) directory part of $* (up to last slash)
$(*F) file name part of $* (after last slash)
$(<D) directory part of $< (up to last slash)
$(<F) file name part of $< (after last slash)
.fi
.PP
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 the makefile,
or the first character of the command is `@'.
.PP
Commands returning nonzero status (see
.IR intro (1))
cause
.I make
to terminate unless
the special target `.IGNORE' is in
the makefile
or the command begins with
<tab><hyphen>.
.PP
Interrupt and quit cause the target to be deleted
unless the target depends on the special name `.PRECIOUS'.
.PP
.I Make
includes a rudimentary parallel processing ability.
If the separation string is `:&' or `::&',
.I make
can run the command sequences to create 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.
.PP
Other options:
.TP
.B \-i
Equivalent to the special entry `.IGNORE:'.
.TP
.B \-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.
.TP
.B \-n
Trace and print, but do not execute the commands
needed to update the targets.
.TP
.B \-t
Touch, i.e. update the modified date of targets, without
executing any commands.
.TP
.B \-r
Equivalent to an initial special entry `.SUFFIXES:'
with no list.
.TP
.B \-s
Equivalent to the special entry
`.SILENT:'.
.TP
.B \-e
Environment definitions override conflicting definitions in arguments
or in makefiles.
Ordinary precedence is argument over makefile
over environment.
.TP
.B \-o
Assume old style default suffix list:
\&.SUFFIXES: .out .o .c .e .r .f .y .l .s .p
.TP
.BI \-P n
Permit
.I n
command sequences to be done in parallel with `&'.
.SH FILES
makefile, Makefile
.br
.SH "SEE ALSO"
sh(1), touch(1), ar(1)
.br
S. I. Feldman
.I
Make \- A Program for Maintaining Computer Programs
|