BSD 3 development
[unix-history] / usr / man / man1 / make.1
CommitLineData
e6817382
BJ
1.TH MAKE 1
2.SH NAME
3make \- maintain program groups
4.SH SYNOPSIS
5.B make
6[
7.B \-f
8makefile ] [ option ] ...
9file ...
10.SH DESCRIPTION
11.I Make
12executes commands in
13.I makefile
14to update
15one or more target
16.IR names .
17.I Name
18is typically a program.
19If no
20.B \-f
21option is present, `makefile' and `Makefile' are
22tried in order.
23If
24.I makefile
25is `\-', the standard input is taken.
26More than one
27.B \-f
28option may appear
29.PP
30.I Make
31updates a target if it depends on prerequisite files
32that have been modified since the target was last modified,
33or if the target does not exist.
34.PP
35.I Makefile
36contains a sequence of entries that specify dependencies.
37The first line of an entry is a
38blank-separated list of targets, then a colon,
39then a list of prerequisite files.
40Text following a semicolon, and all following lines
41that begin with a tab, are shell commands
42to be executed to update the target.
43.PP
44Sharp and newline surround comments.
45.PP
46The following makefile says that `pgm' depends on two
47files `a.o' and `b.o', and that they in turn depend on
48`.c' files and a common file `incl'.
49.RS
50.HP
51.PD 0
52.nf
53pgm: a.o b.o
54cc a.o b.o \-lm \-o pgm
55.HP
56a.o: incl a.c
57cc \-c a.c
58.HP
59b.o: incl b.c
60cc \-c b.c
61.fi
62.RE
63.PD
64.PP
65.I Makefile
66entries of the form
67.PP
68.IP
69string1 = string2
70.PP
71are macro definitions.
72Subsequent appearances of
73.I $(string1)
74are replaced by
75.IR string2 .
76If
77.I string1
78is a single character, the parentheses are optional.
79.PP
80.I Make
81infers prerequisites for files for which
82.I makefile
83gives no construction commands.
84For example, a
85`.c' file may be inferred as prerequisite for a `.o' file
86and be compiled to produce the `.o' file.
87Thus the preceding example can be done more briefly:
88.RS
89.HP
90.PD 0
91.nf
92pgm: a.o b.o
93cc a.o b.o \-lm \-o pgm
94.HP
95a.o b.o: incl
96.fi
97.RE
98.PD
99.PP
100Prerequisites are inferred according to selected suffixes
101listed as the `prerequisites' for the special name `.SUFFIXES';
102multiple lists accumulate;
103an empty list clears what came before.
104Order is significant; the first possible name for which both
105a file and a rule as described in the next paragraph exist
106is inferred.
107The default list is
108.IP
109\&.SUFFIXES: .out .o .c .e .r .f .y .l .s
110.PP
111The rule to create a file with suffix
112.I s2
113that depends on a similarly named file with suffix
114.I s1
115is specified as an entry
116for the `target'
117.IR s1s2 .
118In such an entry, the special macro $* stands for
119the target name with suffix deleted, $@ for the full target name,
120$< for the complete list of prerequisites,
121and
122$? for the list of prerequisites that are out of date.
123For example, a rule for making
124optimized `.o' files from `.c' files is
125.IP
126\&.c.o: ; cc \-c \-O \-o $@ $*.c
127.PP
128Certain macros are used by the default inference rules
129to communicate optional arguments to
130any resulting compilations.
131In particular, `CFLAGS' is used for
132.I cc
133and
134.IR f77 (1)
135options, `LFLAGS' and `YFLAGS' for
136.I lex
137and
138.IR yacc (1)
139options.
140.PP
141Command lines are executed one at a time, each by its
142own shell.
143A line is printed when it is executed unless
144the special target `.SILENT'
145is in
146.I makefile,
147or the first character of the command is `@'.
148.PP
149Commands returning nonzero status (see
150.IR intro (1))
151cause
152.I make
153to terminate unless
154the special target `.IGNORE' is in
155.I makefile
156or the command begins with
157<tab><hyphen>.
158.PP
159Interrupt and quit cause the target to be deleted
160unless the target depends on the special name `.PRECIOUS'.
161.PP
162Other options:
163.TP
164.B \-i
165Equivalent to the special entry `.IGNORE:'.
166.TP
167.B \-k
168When a command returns nonzero status,
169abandon work on the current entry, but
170continue on branches that do not depend on the current entry.
171.TP
172.B \-n
173Trace and print, but do not execute the commands
174needed to update the targets.
175.TP
176.B \-t
177Touch, i.e. update the modified date of targets, without
178executing any commands.
179.TP
180.B \-r
181Equivalent to an initial special entry `.SUFFIXES:'
182with no list.
183.TP
184.B \-s
185Equivalent to the special entry
186`.SILENT:'.
187.SH FILES
188makefile, Makefile
189.br
190.SH "SEE ALSO"
191sh(1), touch(1)
192.br
193S. I. Feldman
194.I
195Make \- A Program for Maintaining Computer Programs
196.SH BUGS
197Some commands return nonzero status inappropriately.
198Use
199.B \-i
200to overcome the difficulty.
201.br
202Commands that are directly executed by the shell,
203notably
204.IR cd (1),
205are ineffectual across newlines in
206.I make.