BSD 4_3_Tahoe development
[unix-history] / usr / man / cat1 / make.0
MAKE(1) UNIX Programmer's Manual MAKE(1)
N\bNA\bAM\bME\bE
make - maintain program groups
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
m\bma\bak\bke\be [ -\b-f\bf makefile ] [ option ] ... file ...
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
_\bM_\ba_\bk_\be executes commands in _\bm_\ba_\bk_\be_\bf_\bi_\bl_\be to update one or more
target _\bn_\ba_\bm_\be_\bs. _\bN_\ba_\bm_\be is typically a program. If no -\b-f\bf option
is present, `makefile' and `Makefile' are tried in order.
If _\bm_\ba_\bk_\be_\bf_\bi_\bl_\be is `-', the standard input is taken. More than
one -\b-f\bf option may appear.
_\bM_\ba_\bk_\be 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.
_\bM_\ba_\bk_\be_\bf_\bi_\bl_\be contains a sequence of entries that specify depen-
dencies. 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 com-
mand sequence may be specified for it. If a name appears on
a line with a double colon :\b::\b: then the command sequence fol-
lowing 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
_\ba(_\bb) means the file named _\bb stored in the archive named _\ba. A
name like _\ba((_\bb)) means the file stored in archive _\ba contain-
ing the entry point _\bb.
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
_\bM_\ba_\bk_\be_\bf_\bi_\bl_\be entries of the form
Printed 7/9/88 August 24, 1987 1
MAKE(1) UNIX Programmer's Manual MAKE(1)
string1 = string2
are macro definitions. Subsequent appearances of $(_\bs_\bt_\br_\bi_\bn_\bg_\b1)
or ${_\bs_\bt_\br_\bi_\bn_\bg_\b1} are replaced by _\bs_\bt_\br_\bi_\bn_\bg_\b2. If _\bs_\bt_\br_\bi_\bn_\bg_\b1 is a sin-
gle character, the parentheses or braces are optional.
_\bM_\ba_\bk_\be infers prerequisites for files for which _\bm_\ba_\bk_\be_\bf_\bi_\bl_\be 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 `.SUF-
FIXES'; 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 _\bs_\b2 that depends on a
similarly named file with suffix _\bs_\b1 is specified as an entry
for the `target' _\bs_\b1_\bs_\b2. 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 prere-
quisites, 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 compila-
tions. In particular, `CFLAGS' is used for _\bc_\bc(1) options,
`FFLAGS' for _\bf_\b7_\b7(1) options, `PFLAGS' for _\bp_\bc(1) options, and
`LFLAGS' and `YFLAGS' for _\bl_\be_\bx and _\by_\ba_\bc_\bc(1) options. In addi-
tion, the macro `MFLAGS' is filled in with the initial com-
mand line options supplied to _\bm_\ba_\bk_\be. This simplifies main-
taining a hierarchy of makefiles as one may then invoke _\bm_\ba_\bk_\be
on makefiles in subdirectories and pass along useful options
such as -\b-k\bk.
The environment is read by _\bm_\ba_\bk_\be. All variables are assumed
to be macro definitions and processed as such. The environ-
mental variables are processed before any makefile and after
the internal rules; thus, macro assignments in a makefile
override environmental variables. The -\b-e\be option causes the
Printed 7/9/88 August 24, 1987 2
MAKE(1) UNIX Programmer's Manual MAKE(1)
environment to override the macro assignments in a makefile.
As with macro assignments, environmental variables are
always overriden by the command line.
Another special macro is `VPATH'. The `VPATH' macro should
be set to a list of directories separated by colons. When
_\bm_\ba_\bk_\be searches for a file as a result of a dependency rela-
tion, 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 _\bm_\ba_\bk_\be_\bf_\bi_\bl_\be) 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 _\bm_\ba_\bk_\be_\bf_\bi_\bl_\be, or the first char-
acter of the command is `@'.
Commands returning nonzero status (see _\bi_\bn_\bt_\br_\bo(1)) cause _\bm_\ba_\bk_\be
to terminate unless the special target `.IGNORE' is in
_\bm_\ba_\bk_\be_\bf_\bi_\bl_\be 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 `.PRE-
CIOUS'.
Other options:
-\b-e\be Environmental variables override assignments within
makefiles.
-\b-i\bi Equivalent to the special entry `.IGNORE:'.
-\b-k\bk When a command returns nonzero status, abandon work on
the current entry, but continue on branches that do not
depend on the current entry.
-\b-n\bn Trace and print, but do not execute the commands needed
to update the targets.
-\b-t\bt Touch, i.e. update the modified date of targets,
without executing any commands.
-\b-r\br Equivalent to an initial special entry `.SUFFIXES:'
with no list.
Printed 7/9/88 August 24, 1987 3
MAKE(1) UNIX Programmer's Manual MAKE(1)
-\b-s\bs Equivalent to the special entry `.SILENT:'.
F\bFI\bIL\bLE\bES\bS
makefile, Makefile
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
sh(1), touch(1), f77(1), pc(1), getenv(3)
S. I. Feldman _\bM_\ba_\bk_\be - _\bA _\bP_\br_\bo_\bg_\br_\ba_\bm _\bf_\bo_\br _\bM_\ba_\bi_\bn_\bt_\ba_\bi_\bn_\bi_\bn_\bg _\bC_\bo_\bm_\bp_\bu_\bt_\be_\br _\bP_\br_\bo_\b-
_\bg_\br_\ba_\bm_\bs
B\bBU\bUG\bGS\bS
Some commands return nonzero status inappropriately. Use -\b-i\bi
to overcome the difficulty.
Commands that are directly executed by the shell, notably
_\bc_\bd(1), are ineffectual across newlines in _\bm_\ba_\bk_\be.
`VPATH' is intended to act like the System V `VPATH' sup-
port, but there is no guarantee that it functions identi-
cally.
Printed 7/9/88 August 24, 1987 4