update!
[unix-history] / usr / src / old / make / make.1
CommitLineData
4de361a5
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
17c4a841 5.\" @(#)make.1 6.4 (Berkeley) %G%
4de361a5 6.\"
2ec39d6d 7.TH MAKE 1 ""
4de361a5
KM
8.UC 4
9.SH NAME
10make \- maintain program groups
11.SH SYNOPSIS
12.B make
13[
14.B \-f
15makefile ] [ option ] ...
16file ...
17.SH DESCRIPTION
18.I Make
19executes commands in
20.I makefile
21to update
22one or more target
23.IR names .
24.I Name
25is typically a program.
26If no
27.B \-f
28option is present, `makefile' and `Makefile' are
29tried in order.
30If
31.I makefile
32is `\-', the standard input is taken.
33More than one
34.B \-f
bfe02f44 35option may appear.
4de361a5
KM
36.PP
37.I Make
38updates a target if it depends on prerequisite files
39that have been modified since the target was last modified,
40or if the target does not exist.
41.PP
42.I Makefile
43contains a sequence of entries that specify dependencies.
44The first line of an entry is a
45blank-separated list of targets, then a colon,
46then a list of prerequisite files.
47Text following a semicolon, and all following lines
48that begin with a tab, are shell commands
49to be executed to update the target.
50If a name appears on the left of more than one `colon' line, then it depends
51on all of the names on the right of the colon on those lines, but only
52one command sequence may be specified for it.
53If a name appears on a line with a double colon
54.B "::"
55then the command sequence following that line is performed
56only if the name is out of date with respect to the names to the right
57of the double colon, and is not affected by other double colon lines
58on which that name may appear.
59.PP
60Two special forms of a name are recognized.
61A name like
28e84832 62.IR a ( b )
4de361a5
KM
63means the file named
64.I b
65stored in the archive named
66.I a.
67A name like
28e84832 68.IR a (( b ))
4de361a5
KM
69means the file stored in archive
70.I a
71containing the entry point
72.I b.
73.PP
74Sharp and newline surround comments.
75.PP
76The following makefile says that `pgm' depends on two
77files `a.o' and `b.o', and that they in turn depend on
78`.c' files and a common file `incl'.
79.RS
80.HP
81.PD 0
82.nf
83pgm: a.o b.o
84cc a.o b.o \-lm \-o pgm
85.HP
86a.o: incl a.c
87cc \-c a.c
88.HP
89b.o: incl b.c
90cc \-c b.c
91.fi
92.RE
93.PD
94.PP
95.I Makefile
96entries of the form
97.PP
98.IP
99string1 = string2
100.PP
101are macro definitions.
102Subsequent appearances of
28e84832
KM
103.RI $( string1 )
104or
105.RI ${ string1 }
4de361a5
KM
106are replaced by
107.IR string2 .
108If
109.I string1
28e84832
KM
110is a single character, the parentheses or braces
111are optional.
4de361a5
KM
112.PP
113.I Make
114infers prerequisites for files for which
115.I makefile
116gives no construction commands.
117For example, a
118`.c' file may be inferred as prerequisite for a `.o' file
119and be compiled to produce the `.o' file.
120Thus the preceding example can be done more briefly:
121.RS
122.HP
123.PD 0
124.nf
125pgm: a.o b.o
126cc a.o b.o \-lm \-o pgm
127.HP
128a.o b.o: incl
129.fi
130.RE
131.PD
132.PP
133Prerequisites are inferred according to selected suffixes
134listed as the `prerequisites' for the special name `.SUFFIXES';
135multiple lists accumulate;
136an empty list clears what came before.
137Order is significant; the first possible name for which both
138a file and a rule as described in the next paragraph exist
139is inferred.
140The default list is
141.IP
142\&.SUFFIXES: .out .o .c .e .r .f .y .l .s .p
143.PP
144The rule to create a file with suffix
145.I s2
146that depends on a similarly named file with suffix
147.I s1
148is specified as an entry
149for the `target'
150.IR s1s2 .
151In such an entry, the special macro $* stands for
152the target name with suffix deleted, $@ for the full target name,
153$< for the complete list of prerequisites,
154and
155$? for the list of prerequisites that are out of date.
156For example, a rule for making
157optimized `.o' files from `.c' files is
158.IP
159\&.c.o: ; cc \-c \-O \-o $@ $*.c
160.PP
161Certain macros are used by the default inference rules
162to communicate optional arguments to
163any resulting compilations.
164In particular,
165`CFLAGS' is used for
166.IR cc (1)
167options,
168`FFLAGS' for
169.IR f77 (1)
170options,
171`PFLAGS' for
172.IR pc (1)
173options,
174and `LFLAGS' and `YFLAGS' for
175.I lex
176and
177.IR yacc (1)
28e84832
KM
178options. In addition, the macro `MFLAGS' is filled in
179with the initial command line options supplied to
180.IR make .
181This simplifies maintaining a hierarchy of makefiles as
182one may then invoke
183.I make
184on makefiles in subdirectories and pass along useful options
185such as
186.BR \-k .
4de361a5 187.PP
8662b8f7
KB
188The environment is read by \fImake\fP. All variables are assumed to be
189macro definitions and processed as such. The environmental variables
190are processed before any makefile and after the internal rules; thus,
191macro assignments in a makefile override environmental variables. The
192\fB-e\fP option causes the environment to override the macro assignments
193in a makefile. As with macro assignments, environmental variables are
194always overriden by the command line.
195.PP
93e0b34b
KM
196Another special macro is `VPATH'.
197The `VPATH' macro should be set to a list of directories separated by colons.
198When
199.I make
200searches for a file as a result of a dependency relation, it will
201first search the current directory and then each of the directories on the
202`VPATH' list.
203If the file is found, the actual path to the file will be used, rather than
204just the filename.
205If `VPATH' is not defined, then only the current directory is searched.
206.PP
207One use for `VPATH' is when one has several programs that compile from the
208same source.
209The source can be kept in one directory and each set of
210object files (along with a separate
211.IR makefile )
212would be in a separate subdirectory.
213The `VPATH' macro would point to the source directory in this case.
214.PP
4de361a5
KM
215Command lines are executed one at a time, each by its
216own shell.
217A line is printed when it is executed unless
218the special target `.SILENT'
219is in
220.I makefile,
221or the first character of the command is `@'.
222.PP
223Commands returning nonzero status (see
224.IR intro (1))
225cause
226.I make
227to terminate unless
228the special target `.IGNORE' is in
229.I makefile
230or the command begins with
231<tab><hyphen>.
232.PP
233Interrupt and quit cause the target to be deleted
28e84832
KM
234unless the target is a directory or
235depends on the special name `.PRECIOUS'.
4de361a5
KM
236.PP
237Other options:
238.TP
8662b8f7
KB
239.B \-e
240Environmental variables override assignments within makefiles.
241.TP
4de361a5
KM
242.B \-i
243Equivalent to the special entry `.IGNORE:'.
244.TP
245.B \-k
246When a command returns nonzero status,
247abandon work on the current entry, but
248continue on branches that do not depend on the current entry.
249.TP
250.B \-n
251Trace and print, but do not execute the commands
252needed to update the targets.
253.TP
254.B \-t
255Touch, i.e. update the modified date of targets, without
256executing any commands.
257.TP
258.B \-r
259Equivalent to an initial special entry `.SUFFIXES:'
260with no list.
261.TP
262.B \-s
263Equivalent to the special entry
264`.SILENT:'.
265.SH FILES
266makefile, Makefile
267.br
268.SH "SEE ALSO"
8662b8f7 269sh(1), touch(1), f77(1), pc(1), getenv(3)
4de361a5
KM
270.br
271S. I. Feldman
272.I
273Make \- A Program for Maintaining Computer Programs
274.SH BUGS
275Some commands return nonzero status inappropriately.
276Use
277.B \-i
278to overcome the difficulty.
279.br
280Commands that are directly executed by the shell,
281notably
282.IR cd (1),
283are ineffectual across newlines in
284.I make.
93e0b34b
KM
285.PP
286`VPATH' is intended to act like the System V `VPATH' support,
287but there is no guarantee that it functions identically.