reality treatment similar to rshd.8c delta 6.2
[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.\"
93e0b34b 5.\" @(#)make.1 6.2 (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
35option may appear
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
93e0b34b
KM
188Another special macro is `VPATH'.
189The `VPATH' macro should be set to a list of directories separated by colons.
190When
191.I make
192searches for a file as a result of a dependency relation, it will
193first search the current directory and then each of the directories on the
194`VPATH' list.
195If the file is found, the actual path to the file will be used, rather than
196just the filename.
197If `VPATH' is not defined, then only the current directory is searched.
198.PP
199One use for `VPATH' is when one has several programs that compile from the
200same source.
201The source can be kept in one directory and each set of
202object files (along with a separate
203.IR makefile )
204would be in a separate subdirectory.
205The `VPATH' macro would point to the source directory in this case.
206.PP
4de361a5
KM
207Command lines are executed one at a time, each by its
208own shell.
209A line is printed when it is executed unless
210the special target `.SILENT'
211is in
212.I makefile,
213or the first character of the command is `@'.
214.PP
215Commands returning nonzero status (see
216.IR intro (1))
217cause
218.I make
219to terminate unless
220the special target `.IGNORE' is in
221.I makefile
222or the command begins with
223<tab><hyphen>.
224.PP
225Interrupt and quit cause the target to be deleted
28e84832
KM
226unless the target is a directory or
227depends on the special name `.PRECIOUS'.
4de361a5
KM
228.PP
229Other options:
230.TP
231.B \-i
232Equivalent to the special entry `.IGNORE:'.
233.TP
234.B \-k
235When a command returns nonzero status,
236abandon work on the current entry, but
237continue on branches that do not depend on the current entry.
238.TP
239.B \-n
240Trace and print, but do not execute the commands
241needed to update the targets.
242.TP
243.B \-t
244Touch, i.e. update the modified date of targets, without
245executing any commands.
246.TP
247.B \-r
248Equivalent to an initial special entry `.SUFFIXES:'
249with no list.
250.TP
251.B \-s
252Equivalent to the special entry
253`.SILENT:'.
254.SH FILES
255makefile, Makefile
256.br
257.SH "SEE ALSO"
258sh(1), touch(1), f77(1), pc(1)
259.br
260S. I. Feldman
261.I
262Make \- A Program for Maintaining Computer Programs
263.SH BUGS
264Some commands return nonzero status inappropriately.
265Use
266.B \-i
267to overcome the difficulty.
268.br
269Commands that are directly executed by the shell,
270notably
271.IR cd (1),
272are ineffectual across newlines in
273.I make.
93e0b34b
KM
274.PP
275`VPATH' is intended to act like the System V `VPATH' support,
276but there is no guarantee that it functions identically.