Blame


1 76193d7c 2003-09-30 devnull .TH MK 1
2 76193d7c 2003-09-30 devnull .de EX
3 76193d7c 2003-09-30 devnull .nf
4 76193d7c 2003-09-30 devnull .ft B
5 76193d7c 2003-09-30 devnull ..
6 76193d7c 2003-09-30 devnull .de EE
7 76193d7c 2003-09-30 devnull .fi
8 76193d7c 2003-09-30 devnull .ft R
9 76193d7c 2003-09-30 devnull ..
10 76193d7c 2003-09-30 devnull .de LR
11 76193d7c 2003-09-30 devnull .if t .BR \\$1 \\$2
12 76193d7c 2003-09-30 devnull .if n .RB ` \\$1 '\\$2
13 76193d7c 2003-09-30 devnull ..
14 76193d7c 2003-09-30 devnull .de L
15 76193d7c 2003-09-30 devnull .nh
16 76193d7c 2003-09-30 devnull .if t .B \\$1
17 76193d7c 2003-09-30 devnull .if n .RB ` \\$1 '
18 76193d7c 2003-09-30 devnull ..
19 76193d7c 2003-09-30 devnull .SH NAME
20 76193d7c 2003-09-30 devnull mk \- maintain (make) related files
21 76193d7c 2003-09-30 devnull .SH SYNOPSIS
22 76193d7c 2003-09-30 devnull .B mk
23 76193d7c 2003-09-30 devnull [
24 76193d7c 2003-09-30 devnull .B -f
25 76193d7c 2003-09-30 devnull .I mkfile
26 76193d7c 2003-09-30 devnull ] ...
27 76193d7c 2003-09-30 devnull [
28 76193d7c 2003-09-30 devnull .I option ...
29 76193d7c 2003-09-30 devnull ]
30 76193d7c 2003-09-30 devnull [
31 76193d7c 2003-09-30 devnull .I target ...
32 76193d7c 2003-09-30 devnull ]
33 76193d7c 2003-09-30 devnull .SH DESCRIPTION
34 76193d7c 2003-09-30 devnull .I Mk
35 76193d7c 2003-09-30 devnull uses the dependency rules specified in
36 76193d7c 2003-09-30 devnull .I mkfile
37 76193d7c 2003-09-30 devnull to control the update (usually by compilation) of
38 76193d7c 2003-09-30 devnull .I targets
39 76193d7c 2003-09-30 devnull (usually files)
40 76193d7c 2003-09-30 devnull from the source files upon which they depend.
41 76193d7c 2003-09-30 devnull The
42 76193d7c 2003-09-30 devnull .I mkfile
43 76193d7c 2003-09-30 devnull (default
44 76193d7c 2003-09-30 devnull .LR mkfile )
45 76193d7c 2003-09-30 devnull contains a
46 76193d7c 2003-09-30 devnull .I rule
47 76193d7c 2003-09-30 devnull for each target that identifies the files and other
48 76193d7c 2003-09-30 devnull targets upon which it depends and an
49 76193d7c 2003-09-30 devnull .IR sh (1)
50 76193d7c 2003-09-30 devnull script, a
51 76193d7c 2003-09-30 devnull .IR recipe ,
52 76193d7c 2003-09-30 devnull to update the target.
53 76193d7c 2003-09-30 devnull The script is run if the target does not exist
54 76193d7c 2003-09-30 devnull or if it is older than any of the files it depends on.
55 76193d7c 2003-09-30 devnull .I Mkfile
56 76193d7c 2003-09-30 devnull may also contain
57 76193d7c 2003-09-30 devnull .I meta-rules
58 76193d7c 2003-09-30 devnull that define actions for updating implicit targets.
59 76193d7c 2003-09-30 devnull If no
60 76193d7c 2003-09-30 devnull .I target
61 76193d7c 2003-09-30 devnull is specified, the target of the first rule (not meta-rule) in
62 76193d7c 2003-09-30 devnull .I mkfile
63 76193d7c 2003-09-30 devnull is updated.
64 76193d7c 2003-09-30 devnull .PP
65 76193d7c 2003-09-30 devnull The environment variable
66 76193d7c 2003-09-30 devnull .B $NPROC
67 76193d7c 2003-09-30 devnull determines how many targets may be updated simultaneously;
68 76193d7c 2003-09-30 devnull Some operating systems, e.g., Plan 9, set
69 76193d7c 2003-09-30 devnull .B $NPROC
70 76193d7c 2003-09-30 devnull automatically to the number of CPUs on the current machine.
71 76193d7c 2003-09-30 devnull .PP
72 76193d7c 2003-09-30 devnull Options are:
73 76193d7c 2003-09-30 devnull .TP \w'\fL-d[egp]\ 'u
74 76193d7c 2003-09-30 devnull .B -a
75 76193d7c 2003-09-30 devnull Assume all targets to be out of date.
76 76193d7c 2003-09-30 devnull Thus, everything is updated.
77 76193d7c 2003-09-30 devnull .PD 0
78 76193d7c 2003-09-30 devnull .TP
79 76193d7c 2003-09-30 devnull .BR -d [ egp ]
80 76193d7c 2003-09-30 devnull Produce debugging output
81 76193d7c 2003-09-30 devnull .RB ( p
82 76193d7c 2003-09-30 devnull is for parsing,
83 76193d7c 2003-09-30 devnull .B g
84 76193d7c 2003-09-30 devnull for graph building,
85 76193d7c 2003-09-30 devnull .B e
86 76193d7c 2003-09-30 devnull for execution).
87 76193d7c 2003-09-30 devnull .TP
88 76193d7c 2003-09-30 devnull .B -e
89 76193d7c 2003-09-30 devnull Explain why each target is made.
90 76193d7c 2003-09-30 devnull .TP
91 76193d7c 2003-09-30 devnull .B -i
92 76193d7c 2003-09-30 devnull Force any missing intermediate targets to be made.
93 76193d7c 2003-09-30 devnull .TP
94 76193d7c 2003-09-30 devnull .B -k
95 76193d7c 2003-09-30 devnull Do as much work as possible in the face of errors.
96 76193d7c 2003-09-30 devnull .TP
97 76193d7c 2003-09-30 devnull .B -n
98 76193d7c 2003-09-30 devnull Print, but do not execute, the commands
99 76193d7c 2003-09-30 devnull needed to update the targets.
100 76193d7c 2003-09-30 devnull .TP
101 76193d7c 2003-09-30 devnull .B -s
102 76193d7c 2003-09-30 devnull Make the command line arguments sequentially rather than in parallel.
103 76193d7c 2003-09-30 devnull .TP
104 76193d7c 2003-09-30 devnull .B -t
105 76193d7c 2003-09-30 devnull Touch (update the modified date of) file targets, without
106 76193d7c 2003-09-30 devnull executing any recipes.
107 76193d7c 2003-09-30 devnull .TP
108 76193d7c 2003-09-30 devnull .BI -w target1 , target2,...
109 76193d7c 2003-09-30 devnull Pretend the modify time for each
110 76193d7c 2003-09-30 devnull .I target
111 76193d7c 2003-09-30 devnull is the current time; useful in conjunction with
112 76193d7c 2003-09-30 devnull .B -n
113 76193d7c 2003-09-30 devnull to learn what updates would be triggered by
114 76193d7c 2003-09-30 devnull modifying the
115 76193d7c 2003-09-30 devnull .IR targets .
116 76193d7c 2003-09-30 devnull .PD
117 76193d7c 2003-09-30 devnull .SS The \fLmkfile\fP
118 76193d7c 2003-09-30 devnull A
119 76193d7c 2003-09-30 devnull .I mkfile
120 76193d7c 2003-09-30 devnull consists of
121 76193d7c 2003-09-30 devnull .I assignments
122 76193d7c 2003-09-30 devnull (described under `Environment') and
123 76193d7c 2003-09-30 devnull .IR rules .
124 76193d7c 2003-09-30 devnull A rule contains
125 76193d7c 2003-09-30 devnull .I targets
126 76193d7c 2003-09-30 devnull and a
127 76193d7c 2003-09-30 devnull .IR tail .
128 76193d7c 2003-09-30 devnull A target is a literal string
129 76193d7c 2003-09-30 devnull and is normally a file name.
130 76193d7c 2003-09-30 devnull The tail contains zero or more
131 76193d7c 2003-09-30 devnull .I prerequisites
132 76193d7c 2003-09-30 devnull and an optional
133 76193d7c 2003-09-30 devnull .IR recipe ,
134 76193d7c 2003-09-30 devnull which is an
135 76193d7c 2003-09-30 devnull .B shell
136 76193d7c 2003-09-30 devnull script.
137 76193d7c 2003-09-30 devnull Each line of the recipe must begin with white space.
138 76193d7c 2003-09-30 devnull A rule takes the form
139 76193d7c 2003-09-30 devnull .IP
140 76193d7c 2003-09-30 devnull .EX
141 76193d7c 2003-09-30 devnull target: prereq1 prereq2
142 76193d7c 2003-09-30 devnull \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
143 76193d7c 2003-09-30 devnull .EE
144 76193d7c 2003-09-30 devnull .PP
145 76193d7c 2003-09-30 devnull When the recipe is executed,
146 76193d7c 2003-09-30 devnull the first character on every line is elided.
147 76193d7c 2003-09-30 devnull .PP
148 76193d7c 2003-09-30 devnull After the colon on the target line, a rule may specify
149 76193d7c 2003-09-30 devnull .IR attributes ,
150 76193d7c 2003-09-30 devnull described below.
151 76193d7c 2003-09-30 devnull .PP
152 76193d7c 2003-09-30 devnull A
153 76193d7c 2003-09-30 devnull .I meta-rule
154 76193d7c 2003-09-30 devnull has a target of the form
155 76193d7c 2003-09-30 devnull .IB A % B
156 76193d7c 2003-09-30 devnull where
157 76193d7c 2003-09-30 devnull .I A
158 76193d7c 2003-09-30 devnull and
159 76193d7c 2003-09-30 devnull .I B
160 76193d7c 2003-09-30 devnull are (possibly empty) strings.
161 76193d7c 2003-09-30 devnull A meta-rule acts as a rule for any potential target whose
162 76193d7c 2003-09-30 devnull name matches
163 76193d7c 2003-09-30 devnull .IB A % B
164 76193d7c 2003-09-30 devnull with
165 76193d7c 2003-09-30 devnull .B %
166 76193d7c 2003-09-30 devnull replaced by an arbitrary string, called the
167 76193d7c 2003-09-30 devnull .IR stem .
168 76193d7c 2003-09-30 devnull In interpreting a meta-rule,
169 76193d7c 2003-09-30 devnull the stem is substituted for all occurrences of
170 76193d7c 2003-09-30 devnull .B %
171 76193d7c 2003-09-30 devnull in the prerequisite names.
172 76193d7c 2003-09-30 devnull In the recipe of a meta-rule, the environment variable
173 76193d7c 2003-09-30 devnull .B $stem
174 76193d7c 2003-09-30 devnull contains the string matched by the
175 76193d7c 2003-09-30 devnull .BR % .
176 76193d7c 2003-09-30 devnull For example, a meta-rule to compile a C program using
177 76193d7c 2003-09-30 devnull .IR cc (1)
178 76193d7c 2003-09-30 devnull might be:
179 76193d7c 2003-09-30 devnull .IP
180 76193d7c 2003-09-30 devnull .EX
181 76193d7c 2003-09-30 devnull %: %.c
182 76193d7c 2003-09-30 devnull cc -c $stem.c
183 76193d7c 2003-09-30 devnull cc -o $stem $stem.o
184 76193d7c 2003-09-30 devnull .EE
185 76193d7c 2003-09-30 devnull .PP
186 76193d7c 2003-09-30 devnull Meta-rules may contain an ampersand
187 76193d7c 2003-09-30 devnull .B &
188 76193d7c 2003-09-30 devnull rather than a percent sign
189 76193d7c 2003-09-30 devnull .BR % .
190 76193d7c 2003-09-30 devnull A
191 76193d7c 2003-09-30 devnull .B %
192 76193d7c 2003-09-30 devnull matches a maximal length string of any characters;
193 76193d7c 2003-09-30 devnull an
194 76193d7c 2003-09-30 devnull .B &
195 76193d7c 2003-09-30 devnull matches a maximal length string of any characters except period
196 76193d7c 2003-09-30 devnull or slash.
197 76193d7c 2003-09-30 devnull .PP
198 76193d7c 2003-09-30 devnull The text of the
199 76193d7c 2003-09-30 devnull .I mkfile
200 76193d7c 2003-09-30 devnull is processed as follows.
201 76193d7c 2003-09-30 devnull Lines beginning with
202 76193d7c 2003-09-30 devnull .B <
203 76193d7c 2003-09-30 devnull followed by a file name are replaced by the contents of the named
204 76193d7c 2003-09-30 devnull file.
205 76193d7c 2003-09-30 devnull Lines beginning with
206 76193d7c 2003-09-30 devnull .B "<|"
207 76193d7c 2003-09-30 devnull followed by a file name are replaced by the output
208 76193d7c 2003-09-30 devnull of the execution of the named
209 76193d7c 2003-09-30 devnull file.
210 76193d7c 2003-09-30 devnull Blank lines and comments, which run from unquoted
211 76193d7c 2003-09-30 devnull .B #
212 76193d7c 2003-09-30 devnull characters to the following newline, are deleted.
213 76193d7c 2003-09-30 devnull The character sequence backslash-newline is deleted,
214 76193d7c 2003-09-30 devnull so long lines in
215 76193d7c 2003-09-30 devnull .I mkfile
216 76193d7c 2003-09-30 devnull may be folded.
217 76193d7c 2003-09-30 devnull Non-recipe lines are processed by substituting for
218 76193d7c 2003-09-30 devnull .BI `{ command }
219 76193d7c 2003-09-30 devnull the output of the
220 76193d7c 2003-09-30 devnull .I command
221 76193d7c 2003-09-30 devnull when run by
222 76193d7c 2003-09-30 devnull .IR sh .
223 76193d7c 2003-09-30 devnull References to variables are replaced by the variables' values.
224 76193d7c 2003-09-30 devnull Special characters may be quoted using single quotes
225 76193d7c 2003-09-30 devnull .BR \&''
226 76193d7c 2003-09-30 devnull as in
227 76193d7c 2003-09-30 devnull .IR sh (1).
228 76193d7c 2003-09-30 devnull .PP
229 76193d7c 2003-09-30 devnull Assignments and rules are distinguished by
230 76193d7c 2003-09-30 devnull the first unquoted occurrence of
231 76193d7c 2003-09-30 devnull .B :
232 76193d7c 2003-09-30 devnull (rule)
233 76193d7c 2003-09-30 devnull or
234 76193d7c 2003-09-30 devnull .B =
235 76193d7c 2003-09-30 devnull (assignment).
236 76193d7c 2003-09-30 devnull .PP
237 76193d7c 2003-09-30 devnull A later rule may modify or override an existing rule under the
238 76193d7c 2003-09-30 devnull following conditions:
239 76193d7c 2003-09-30 devnull .TP
240 76193d7c 2003-09-30 devnull \-
241 76193d7c 2003-09-30 devnull If the targets of the rules exactly match and one rule
242 76193d7c 2003-09-30 devnull contains only a prerequisite clause and no recipe, the
243 76193d7c 2003-09-30 devnull clause is added to the prerequisites of the other rule.
244 76193d7c 2003-09-30 devnull If either or both targets are virtual, the recipe is
245 76193d7c 2003-09-30 devnull always executed.
246 76193d7c 2003-09-30 devnull .TP
247 76193d7c 2003-09-30 devnull \-
248 76193d7c 2003-09-30 devnull If the targets of the rules match exactly and the
249 76193d7c 2003-09-30 devnull prerequisites do not match and both rules
250 76193d7c 2003-09-30 devnull contain recipes,
251 76193d7c 2003-09-30 devnull .I mk
252 76193d7c 2003-09-30 devnull reports an ``ambiguous recipe'' error.
253 76193d7c 2003-09-30 devnull .TP
254 76193d7c 2003-09-30 devnull \-
255 76193d7c 2003-09-30 devnull If the target and prerequisites of both rules match exactly,
256 76193d7c 2003-09-30 devnull the second rule overrides the first.
257 76193d7c 2003-09-30 devnull .SS Environment
258 76193d7c 2003-09-30 devnull Rules may make use of
259 76193d7c 2003-09-30 devnull shell
260 76193d7c 2003-09-30 devnull environment variables.
261 76193d7c 2003-09-30 devnull A legal reference of the form
262 76193d7c 2003-09-30 devnull .B $OBJ
263 76193d7c 2003-09-30 devnull or
264 76193d7c 2003-09-30 devnull .B ${name}
265 76193d7c 2003-09-30 devnull is expanded as in
266 76193d7c 2003-09-30 devnull .IR sh (1).
267 76193d7c 2003-09-30 devnull A reference of the form
268 76193d7c 2003-09-30 devnull .BI ${name: A % B = C\fL%\fID\fL}\fR,
269 76193d7c 2003-09-30 devnull where
270 76193d7c 2003-09-30 devnull .I A, B, C, D
271 76193d7c 2003-09-30 devnull are (possibly empty) strings,
272 76193d7c 2003-09-30 devnull has the value formed by expanding
273 76193d7c 2003-09-30 devnull .B $name
274 76193d7c 2003-09-30 devnull and substituting
275 76193d7c 2003-09-30 devnull .I C
276 76193d7c 2003-09-30 devnull for
277 76193d7c 2003-09-30 devnull .I A
278 76193d7c 2003-09-30 devnull and
279 76193d7c 2003-09-30 devnull .I D
280 76193d7c 2003-09-30 devnull for
281 76193d7c 2003-09-30 devnull .I B
282 76193d7c 2003-09-30 devnull in each word in
283 76193d7c 2003-09-30 devnull .B $name
284 76193d7c 2003-09-30 devnull that matches pattern
285 76193d7c 2003-09-30 devnull .IB A % B\f1.
286 76193d7c 2003-09-30 devnull .PP
287 76193d7c 2003-09-30 devnull Variables can be set by
288 76193d7c 2003-09-30 devnull assignments of the form
289 76193d7c 2003-09-30 devnull .I
290 76193d7c 2003-09-30 devnull var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
291 76193d7c 2003-09-30 devnull .br
292 76193d7c 2003-09-30 devnull Blanks in the
293 76193d7c 2003-09-30 devnull .I value
294 76193d7c 2003-09-30 devnull break it into words.
295 76193d7c 2003-09-30 devnull Such variables are exported
296 76193d7c 2003-09-30 devnull to the environment of
297 76193d7c 2003-09-30 devnull recipes as they are executed, unless
298 76193d7c 2003-09-30 devnull .BR U ,
299 76193d7c 2003-09-30 devnull the only legal attribute
300 76193d7c 2003-09-30 devnull .IR attr ,
301 76193d7c 2003-09-30 devnull is present.
302 76193d7c 2003-09-30 devnull The initial value of a variable is
303 76193d7c 2003-09-30 devnull taken from (in increasing order of precedence)
304 76193d7c 2003-09-30 devnull the default values below,
305 76193d7c 2003-09-30 devnull .I mk's
306 76193d7c 2003-09-30 devnull environment, the
307 76193d7c 2003-09-30 devnull .IR mkfiles ,
308 76193d7c 2003-09-30 devnull and any command line assignment as an argument to
309 76193d7c 2003-09-30 devnull .IR mk .
310 76193d7c 2003-09-30 devnull A variable assignment argument overrides the first (but not any subsequent)
311 76193d7c 2003-09-30 devnull assignment to that variable.
312 76193d7c 2003-09-30 devnull The variable
313 76193d7c 2003-09-30 devnull .B MKFLAGS
314 76193d7c 2003-09-30 devnull contains all the option arguments (arguments starting with
315 76193d7c 2003-09-30 devnull .L -
316 76193d7c 2003-09-30 devnull or containing
317 76193d7c 2003-09-30 devnull .LR = )
318 76193d7c 2003-09-30 devnull and
319 76193d7c 2003-09-30 devnull .B MKARGS
320 76193d7c 2003-09-30 devnull contains all the targets in the call to
321 76193d7c 2003-09-30 devnull .IR mk .
322 76193d7c 2003-09-30 devnull .PP
323 76193d7c 2003-09-30 devnull Dynamic information may be included in the mkfile by using a line of the form
324 76193d7c 2003-09-30 devnull .IP
325 76193d7c 2003-09-30 devnull \fR<|\fIcommand\fR \fIargs\fR
326 76193d7c 2003-09-30 devnull .LP
327 76193d7c 2003-09-30 devnull This runs the command
328 76193d7c 2003-09-30 devnull .I command
329 76193d7c 2003-09-30 devnull with the given arguments
330 76193d7c 2003-09-30 devnull .I args
331 76193d7c 2003-09-30 devnull and pipes its standard output to
332 76193d7c 2003-09-30 devnull .I mk
333 76193d7c 2003-09-30 devnull to be included as part of the mkfile. For instance, the Inferno kernels
334 76193d7c 2003-09-30 devnull use this technique
335 76193d7c 2003-09-30 devnull to run a shell command with an awk script and a configuration
336 76193d7c 2003-09-30 devnull file as arguments in order for
337 76193d7c 2003-09-30 devnull the
338 76193d7c 2003-09-30 devnull .I awk
339 76193d7c 2003-09-30 devnull script to process the file and output a set of variables and their values.
340 76193d7c 2003-09-30 devnull .SS Execution
341 76193d7c 2003-09-30 devnull .PP
342 76193d7c 2003-09-30 devnull During execution,
343 76193d7c 2003-09-30 devnull .I mk
344 76193d7c 2003-09-30 devnull determines which targets must be updated, and in what order,
345 76193d7c 2003-09-30 devnull to build the
346 76193d7c 2003-09-30 devnull .I names
347 76193d7c 2003-09-30 devnull specified on the command line.
348 76193d7c 2003-09-30 devnull It then runs the associated recipes.
349 76193d7c 2003-09-30 devnull .PP
350 76193d7c 2003-09-30 devnull A target is considered up to date if it has no prerequisites or
351 76193d7c 2003-09-30 devnull if all its prerequisites are up to date and it is newer
352 76193d7c 2003-09-30 devnull than all its prerequisites.
353 76193d7c 2003-09-30 devnull Once the recipe for a target has executed, the target is
354 76193d7c 2003-09-30 devnull considered up to date.
355 76193d7c 2003-09-30 devnull .PP
356 76193d7c 2003-09-30 devnull The date stamp
357 76193d7c 2003-09-30 devnull used to determine if a target is up to date is computed
358 76193d7c 2003-09-30 devnull differently for different types of targets.
359 76193d7c 2003-09-30 devnull If a target is
360 76193d7c 2003-09-30 devnull .I virtual
361 76193d7c 2003-09-30 devnull (the target of a rule with the
362 76193d7c 2003-09-30 devnull .B V
363 76193d7c 2003-09-30 devnull attribute),
364 76193d7c 2003-09-30 devnull its date stamp is initially zero; when the target is
365 76193d7c 2003-09-30 devnull updated the date stamp is set to
366 76193d7c 2003-09-30 devnull the most recent date stamp of its prerequisites.
367 76193d7c 2003-09-30 devnull Otherwise, if a target does not exist as a file,
368 76193d7c 2003-09-30 devnull its date stamp is set to the most recent date stamp of its prerequisites,
369 76193d7c 2003-09-30 devnull or zero if it has no prerequisites.
370 76193d7c 2003-09-30 devnull Otherwise, the target is the name of a file and
371 76193d7c 2003-09-30 devnull the target's date stamp is always that file's modification date.
372 76193d7c 2003-09-30 devnull The date stamp is computed when the target is needed in
373 76193d7c 2003-09-30 devnull the execution of a rule; it is not a static value.
374 76193d7c 2003-09-30 devnull .PP
375 76193d7c 2003-09-30 devnull Nonexistent targets that have prerequisites
376 76193d7c 2003-09-30 devnull and are themselves prerequisites are treated specially.
377 76193d7c 2003-09-30 devnull Such a target
378 76193d7c 2003-09-30 devnull .I t
379 76193d7c 2003-09-30 devnull is given the date stamp of its most recent prerequisite
380 76193d7c 2003-09-30 devnull and if this causes all the targets which have
381 76193d7c 2003-09-30 devnull .I t
382 76193d7c 2003-09-30 devnull as a prerequisite to be up to date,
383 76193d7c 2003-09-30 devnull .I t
384 76193d7c 2003-09-30 devnull is considered up to date.
385 76193d7c 2003-09-30 devnull Otherwise,
386 76193d7c 2003-09-30 devnull .I t
387 76193d7c 2003-09-30 devnull is made in the normal fashion.
388 76193d7c 2003-09-30 devnull The
389 76193d7c 2003-09-30 devnull .B -i
390 76193d7c 2003-09-30 devnull flag overrides this special treatment.
391 76193d7c 2003-09-30 devnull .PP
392 76193d7c 2003-09-30 devnull Files may be made in any order that respects
393 76193d7c 2003-09-30 devnull the preceding restrictions.
394 76193d7c 2003-09-30 devnull .PP
395 76193d7c 2003-09-30 devnull A recipe is executed by supplying the recipe as standard input to
396 76193d7c 2003-09-30 devnull the command
397 76193d7c 2003-09-30 devnull .BR /bin/sh .
398 76193d7c 2003-09-30 devnull (Note that unlike
399 76193d7c 2003-09-30 devnull .IR make ,
400 76193d7c 2003-09-30 devnull .I mk
401 76193d7c 2003-09-30 devnull feeds the entire recipe to the shell rather than running each line
402 76193d7c 2003-09-30 devnull of the recipe separately.)
403 76193d7c 2003-09-30 devnull The environment is augmented by the following variables:
404 76193d7c 2003-09-30 devnull .TP 14
405 76193d7c 2003-09-30 devnull .B $alltarget
406 76193d7c 2003-09-30 devnull all the targets of this rule.
407 76193d7c 2003-09-30 devnull .TP
408 76193d7c 2003-09-30 devnull .B $newprereq
409 76193d7c 2003-09-30 devnull the prerequisites that caused this rule to execute.
410 76193d7c 2003-09-30 devnull .TP
411 76193d7c 2003-09-30 devnull .B $newmember
412 76193d7c 2003-09-30 devnull the prerequisites that are members of an aggregate
413 76193d7c 2003-09-30 devnull that caused this rule to execute.
414 76193d7c 2003-09-30 devnull When the prerequisites of a rule are members of an
415 76193d7c 2003-09-30 devnull aggregate,
416 76193d7c 2003-09-30 devnull .B $newprereq
417 76193d7c 2003-09-30 devnull contains the name of the aggregate and out of date
418 76193d7c 2003-09-30 devnull members, while
419 76193d7c 2003-09-30 devnull .B $newmember
420 76193d7c 2003-09-30 devnull contains only the name of the members.
421 76193d7c 2003-09-30 devnull .TP
422 76193d7c 2003-09-30 devnull .B $nproc
423 76193d7c 2003-09-30 devnull the process slot for this recipe.
424 76193d7c 2003-09-30 devnull It satisfies
425 76193d7c 2003-09-30 devnull .RB 0≤ $nproc < $NPROC .
426 76193d7c 2003-09-30 devnull .TP
427 76193d7c 2003-09-30 devnull .B $pid
428 76193d7c 2003-09-30 devnull the process id for the
429 76193d7c 2003-09-30 devnull .I mk
430 76193d7c 2003-09-30 devnull executing the recipe.
431 76193d7c 2003-09-30 devnull .TP
432 76193d7c 2003-09-30 devnull .B $prereq
433 76193d7c 2003-09-30 devnull all the prerequisites for this rule.
434 76193d7c 2003-09-30 devnull .TP
435 76193d7c 2003-09-30 devnull .B $stem
436 76193d7c 2003-09-30 devnull if this is a meta-rule,
437 76193d7c 2003-09-30 devnull .B $stem
438 76193d7c 2003-09-30 devnull is the string that matched
439 76193d7c 2003-09-30 devnull .B %
440 76193d7c 2003-09-30 devnull or
441 76193d7c 2003-09-30 devnull .BR & .
442 76193d7c 2003-09-30 devnull Otherwise, it is empty.
443 76193d7c 2003-09-30 devnull For regular expression meta-rules (see below), the variables
444 76193d7c 2003-09-30 devnull .LR stem0 ", ...,"
445 76193d7c 2003-09-30 devnull .L stem9
446 76193d7c 2003-09-30 devnull are set to the corresponding subexpressions.
447 76193d7c 2003-09-30 devnull .TP
448 76193d7c 2003-09-30 devnull .B $target
449 76193d7c 2003-09-30 devnull the targets for this rule that need to be remade.
450 76193d7c 2003-09-30 devnull .PP
451 76193d7c 2003-09-30 devnull These variables are available only during the execution of a recipe,
452 76193d7c 2003-09-30 devnull not while evaluating the
453 76193d7c 2003-09-30 devnull .IR mkfile .
454 76193d7c 2003-09-30 devnull .PP
455 76193d7c 2003-09-30 devnull Unless the rule has the
456 76193d7c 2003-09-30 devnull .B Q
457 76193d7c 2003-09-30 devnull attribute,
458 76193d7c 2003-09-30 devnull the recipe is printed prior to execution
459 76193d7c 2003-09-30 devnull with recognizable environment variables expanded.
460 76193d7c 2003-09-30 devnull Commands returning error status
461 76193d7c 2003-09-30 devnull cause
462 76193d7c 2003-09-30 devnull .I mk
463 76193d7c 2003-09-30 devnull to terminate.
464 76193d7c 2003-09-30 devnull .PP
465 76193d7c 2003-09-30 devnull Recipes and backquoted
466 76193d7c 2003-09-30 devnull .B rc
467 76193d7c 2003-09-30 devnull commands in places such as assignments
468 76193d7c 2003-09-30 devnull execute in a copy of
469 76193d7c 2003-09-30 devnull .I mk's
470 76193d7c 2003-09-30 devnull environment; changes they make to
471 76193d7c 2003-09-30 devnull environment variables are not visible from
472 76193d7c 2003-09-30 devnull .IR mk .
473 76193d7c 2003-09-30 devnull .PP
474 76193d7c 2003-09-30 devnull Variable substitution in a rule is done when
475 76193d7c 2003-09-30 devnull the rule is read; variable substitution in the recipe is done
476 76193d7c 2003-09-30 devnull when the recipe is executed. For example:
477 76193d7c 2003-09-30 devnull .IP
478 76193d7c 2003-09-30 devnull .EX
479 76193d7c 2003-09-30 devnull bar=a.c
480 76193d7c 2003-09-30 devnull foo: $bar
481 76193d7c 2003-09-30 devnull $CC -o foo $bar
482 76193d7c 2003-09-30 devnull bar=b.c
483 76193d7c 2003-09-30 devnull .EE
484 76193d7c 2003-09-30 devnull .PP
485 76193d7c 2003-09-30 devnull will compile
486 76193d7c 2003-09-30 devnull .B b.c
487 76193d7c 2003-09-30 devnull into
488 76193d7c 2003-09-30 devnull .BR foo ,
489 76193d7c 2003-09-30 devnull if
490 76193d7c 2003-09-30 devnull .B a.c
491 76193d7c 2003-09-30 devnull is newer than
492 76193d7c 2003-09-30 devnull .BR foo .
493 76193d7c 2003-09-30 devnull .SS Aggregates
494 76193d7c 2003-09-30 devnull Names of the form
495 76193d7c 2003-09-30 devnull .IR a ( b )
496 76193d7c 2003-09-30 devnull refer to member
497 76193d7c 2003-09-30 devnull .I b
498 76193d7c 2003-09-30 devnull of the aggregate
499 76193d7c 2003-09-30 devnull .IR a .
500 76193d7c 2003-09-30 devnull Currently, the only aggregates supported are
501 76193d7c 2003-09-30 devnull .IR ar (1)
502 76193d7c 2003-09-30 devnull archives.
503 76193d7c 2003-09-30 devnull .SS Attributes
504 76193d7c 2003-09-30 devnull The colon separating the target from the prerequisites
505 76193d7c 2003-09-30 devnull may be
506 76193d7c 2003-09-30 devnull immediately followed by
507 76193d7c 2003-09-30 devnull .I attributes
508 76193d7c 2003-09-30 devnull and another colon.
509 76193d7c 2003-09-30 devnull The attributes are:
510 76193d7c 2003-09-30 devnull .TP
511 76193d7c 2003-09-30 devnull .B D
512 76193d7c 2003-09-30 devnull If the recipe exits with a non-null status, the target is deleted.
513 76193d7c 2003-09-30 devnull .TP
514 76193d7c 2003-09-30 devnull .B E
515 76193d7c 2003-09-30 devnull Continue execution if the recipe draws errors.
516 76193d7c 2003-09-30 devnull .TP
517 76193d7c 2003-09-30 devnull .B N
518 76193d7c 2003-09-30 devnull If there is no recipe, the target has its time updated.
519 76193d7c 2003-09-30 devnull .TP
520 76193d7c 2003-09-30 devnull .B n
521 76193d7c 2003-09-30 devnull The rule is a meta-rule that cannot be a target of a virtual rule.
522 76193d7c 2003-09-30 devnull Only files match the pattern in the target.
523 76193d7c 2003-09-30 devnull .TP
524 76193d7c 2003-09-30 devnull .B P
525 76193d7c 2003-09-30 devnull The characters after the
526 76193d7c 2003-09-30 devnull .B P
527 76193d7c 2003-09-30 devnull until the terminating
528 76193d7c 2003-09-30 devnull .B :
529 76193d7c 2003-09-30 devnull are taken as a program name.
530 76193d7c 2003-09-30 devnull It will be invoked as
531 76193d7c 2003-09-30 devnull .B "sh -c prog 'arg1' 'arg2'"
532 76193d7c 2003-09-30 devnull and should return a zero exit status
533 76193d7c 2003-09-30 devnull if and only if arg1 is up to date with respect to arg2.
534 76193d7c 2003-09-30 devnull Date stamps are still propagated in the normal way.
535 76193d7c 2003-09-30 devnull .TP
536 76193d7c 2003-09-30 devnull .B Q
537 76193d7c 2003-09-30 devnull The recipe is not printed prior to execution.
538 76193d7c 2003-09-30 devnull .TP
539 76193d7c 2003-09-30 devnull .B R
540 76193d7c 2003-09-30 devnull The rule is a meta-rule using regular expressions.
541 76193d7c 2003-09-30 devnull In the rule,
542 76193d7c 2003-09-30 devnull .B %
543 76193d7c 2003-09-30 devnull has no special meaning.
544 76193d7c 2003-09-30 devnull The target is interpreted as a regular expression as defined in
545 76193d7c 2003-09-30 devnull .IR regexp (6).
546 76193d7c 2003-09-30 devnull The prerequisites may contain references
547 76193d7c 2003-09-30 devnull to subexpressions in form
548 76193d7c 2003-09-30 devnull .BI \e n\f1,
549 76193d7c 2003-09-30 devnull as in the substitute command of
550 76193d7c 2003-09-30 devnull .IR sed (1).
551 76193d7c 2003-09-30 devnull .TP
552 76193d7c 2003-09-30 devnull .B U
553 76193d7c 2003-09-30 devnull The targets are considered to have been updated
554 76193d7c 2003-09-30 devnull even if the recipe did not do so.
555 76193d7c 2003-09-30 devnull .TP
556 76193d7c 2003-09-30 devnull .B V
557 76193d7c 2003-09-30 devnull The targets of this rule are marked as virtual.
558 76193d7c 2003-09-30 devnull They are distinct from files of the same name.
559 76193d7c 2003-09-30 devnull .PD
560 76193d7c 2003-09-30 devnull .SH EXAMPLES
561 76193d7c 2003-09-30 devnull A simple mkfile to compile a program:
562 76193d7c 2003-09-30 devnull .IP
563 76193d7c 2003-09-30 devnull .EX
564 76193d7c 2003-09-30 devnull .ta 8n +8n +8n +8n +8n +8n +8n
565 76193d7c 2003-09-30 devnull </$objtype/mkfile
566 76193d7c 2003-09-30 devnull
567 76193d7c 2003-09-30 devnull prog: a.$O b.$O c.$O
568 76193d7c 2003-09-30 devnull $LD $LDFLAGS -o $target $prereq
569 76193d7c 2003-09-30 devnull
570 76193d7c 2003-09-30 devnull %.$O: %.c
571 76193d7c 2003-09-30 devnull $CC $CFLAGS $stem.c
572 76193d7c 2003-09-30 devnull .EE
573 76193d7c 2003-09-30 devnull .PP
574 76193d7c 2003-09-30 devnull Override flag settings in the mkfile:
575 76193d7c 2003-09-30 devnull .IP
576 76193d7c 2003-09-30 devnull .EX
577 76193d7c 2003-09-30 devnull % mk target 'CFLAGS=-S -w'
578 76193d7c 2003-09-30 devnull .EE
579 76193d7c 2003-09-30 devnull .PP
580 76193d7c 2003-09-30 devnull Maintain a library:
581 76193d7c 2003-09-30 devnull .IP
582 76193d7c 2003-09-30 devnull .EX
583 76193d7c 2003-09-30 devnull libc.a(%.$O):N: %.$O
584 76193d7c 2003-09-30 devnull libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
585 76193d7c 2003-09-30 devnull ar r libc.a $newmember
586 76193d7c 2003-09-30 devnull .EE
587 76193d7c 2003-09-30 devnull .PP
588 76193d7c 2003-09-30 devnull String expression variables to derive names from a master list:
589 76193d7c 2003-09-30 devnull .IP
590 76193d7c 2003-09-30 devnull .EX
591 76193d7c 2003-09-30 devnull NAMES=alloc arc bquote builtins expand main match mk var word
592 76193d7c 2003-09-30 devnull OBJ=${NAMES:%=%.$O}
593 76193d7c 2003-09-30 devnull .EE
594 76193d7c 2003-09-30 devnull .PP
595 76193d7c 2003-09-30 devnull Regular expression meta-rules:
596 76193d7c 2003-09-30 devnull .IP
597 76193d7c 2003-09-30 devnull .EX
598 76193d7c 2003-09-30 devnull ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
599 76193d7c 2003-09-30 devnull cd $stem1; $CC $CFLAGS $stem2.c
600 76193d7c 2003-09-30 devnull .EE
601 76193d7c 2003-09-30 devnull .PP
602 76193d7c 2003-09-30 devnull A correct way to deal with
603 76193d7c 2003-09-30 devnull .IR yacc (1)
604 76193d7c 2003-09-30 devnull grammars.
605 76193d7c 2003-09-30 devnull The file
606 76193d7c 2003-09-30 devnull .B lex.c
607 76193d7c 2003-09-30 devnull includes the file
608 76193d7c 2003-09-30 devnull .B x.tab.h
609 76193d7c 2003-09-30 devnull rather than
610 76193d7c 2003-09-30 devnull .B y.tab.h
611 76193d7c 2003-09-30 devnull in order to reflect changes in content, not just modification time.
612 76193d7c 2003-09-30 devnull .IP
613 76193d7c 2003-09-30 devnull .EX
614 76193d7c 2003-09-30 devnull lex.$O: x.tab.h
615 76193d7c 2003-09-30 devnull x.tab.h: y.tab.h
616 76193d7c 2003-09-30 devnull cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
617 76193d7c 2003-09-30 devnull y.tab.c y.tab.h: gram.y
618 76193d7c 2003-09-30 devnull $YACC -d gram.y
619 76193d7c 2003-09-30 devnull .EE
620 76193d7c 2003-09-30 devnull .PP
621 76193d7c 2003-09-30 devnull The above example could also use the
622 76193d7c 2003-09-30 devnull .B P
623 76193d7c 2003-09-30 devnull attribute for the
624 76193d7c 2003-09-30 devnull .B x.tab.h
625 76193d7c 2003-09-30 devnull rule:
626 76193d7c 2003-09-30 devnull .IP
627 76193d7c 2003-09-30 devnull .EX
628 76193d7c 2003-09-30 devnull x.tab.h:Pcmp -s: y.tab.h
629 76193d7c 2003-09-30 devnull cp y.tab.h x.tab.h
630 76193d7c 2003-09-30 devnull .EE
631 76193d7c 2003-09-30 devnull .SH SEE ALSO
632 76193d7c 2003-09-30 devnull .IR sh (1),
633 76193d7c 2003-09-30 devnull .IR regexp9 (7)
634 76193d7c 2003-09-30 devnull .PP
635 76193d7c 2003-09-30 devnull A. Hume,
636 76193d7c 2003-09-30 devnull ``Mk: a Successor to Make''
637 76193d7c 2003-09-30 devnull (Tenth Edition Research Unix Manuals).
638 76193d7c 2003-09-30 devnull .PP
639 76193d7c 2003-09-30 devnull Andrew G. Hume and Bob Flandrena,
640 76193d7c 2003-09-30 devnull ``Maintaining Files on Plan 9 with Mk''.
641 76193d7c 2003-09-30 devnull DOCPREFIX/doc/mk.pdf
642 76193d7c 2003-09-30 devnull .SH HISTORY
643 76193d7c 2003-09-30 devnull Andrew Hume wrote
644 76193d7c 2003-09-30 devnull .I mk
645 76193d7c 2003-09-30 devnull for Tenth Edition Research Unix.
646 76193d7c 2003-09-30 devnull It was later ported to Plan 9.
647 76193d7c 2003-09-30 devnull This software is a port of the Plan 9 version back to Unix.
648 76193d7c 2003-09-30 devnull .SH BUGS
649 76193d7c 2003-09-30 devnull Identical recipes for regular expression meta-rules only have one target.
650 76193d7c 2003-09-30 devnull .br
651 76193d7c 2003-09-30 devnull Seemingly appropriate input like
652 76193d7c 2003-09-30 devnull .B CFLAGS=-DHZ=60
653 76193d7c 2003-09-30 devnull is parsed as an erroneous attribute; correct it by inserting
654 76193d7c 2003-09-30 devnull a space after the first
655 76193d7c 2003-09-30 devnull .LR = .
656 76193d7c 2003-09-30 devnull .br
657 76193d7c 2003-09-30 devnull The recipes printed by
658 76193d7c 2003-09-30 devnull .I mk
659 76193d7c 2003-09-30 devnull before being passed to
660 76193d7c 2003-09-30 devnull .I sh
661 76193d7c 2003-09-30 devnull for execution are sometimes erroneously expanded
662 76193d7c 2003-09-30 devnull for printing. Don't trust what's printed; rely
663 76193d7c 2003-09-30 devnull on what
664 76193d7c 2003-09-30 devnull .I sh
665 76193d7c 2003-09-30 devnull does.