3 78e51a8c 2005-01-14 devnull mk \- maintain (make) related files
4 78e51a8c 2005-01-14 devnull .SH SYNOPSIS
11 78e51a8c 2005-01-14 devnull .I option ...
14 78e51a8c 2005-01-14 devnull .I target ...
16 78e51a8c 2005-01-14 devnull .SH DESCRIPTION
18 78e51a8c 2005-01-14 devnull uses the dependency rules specified in
19 78e51a8c 2005-01-14 devnull .I mkfile
20 78e51a8c 2005-01-14 devnull to control the update (usually by compilation) of
21 78e51a8c 2005-01-14 devnull .I targets
22 78e51a8c 2005-01-14 devnull (usually files)
23 78e51a8c 2005-01-14 devnull from the source files upon which they depend.
25 78e51a8c 2005-01-14 devnull .I mkfile
27 78e51a8c 2005-01-14 devnull .LR mkfile )
28 78e51a8c 2005-01-14 devnull contains a
30 78e51a8c 2005-01-14 devnull for each target that identifies the files and other
31 78e51a8c 2005-01-14 devnull targets upon which it depends and an
32 78e51a8c 2005-01-14 devnull .IR sh (1)
33 78e51a8c 2005-01-14 devnull script, a
34 78e51a8c 2005-01-14 devnull .IR recipe ,
35 78e51a8c 2005-01-14 devnull to update the target.
36 78e51a8c 2005-01-14 devnull The script is run if the target does not exist
37 78e51a8c 2005-01-14 devnull or if it is older than any of the files it depends on.
38 78e51a8c 2005-01-14 devnull .I Mkfile
39 78e51a8c 2005-01-14 devnull may also contain
40 78e51a8c 2005-01-14 devnull .I meta-rules
41 78e51a8c 2005-01-14 devnull that define actions for updating implicit targets.
43 78e51a8c 2005-01-14 devnull .I target
44 78e51a8c 2005-01-14 devnull is specified, the target of the first rule (not meta-rule) in
45 78e51a8c 2005-01-14 devnull .I mkfile
46 78e51a8c 2005-01-14 devnull is updated.
48 78e51a8c 2005-01-14 devnull The environment variable
49 78e51a8c 2005-01-14 devnull .B $NPROC
50 78e51a8c 2005-01-14 devnull determines how many targets may be updated simultaneously;
51 78e51a8c 2005-01-14 devnull Some operating systems, e.g., Plan 9, set
52 78e51a8c 2005-01-14 devnull .B $NPROC
53 78e51a8c 2005-01-14 devnull automatically to the number of CPUs on the current machine.
55 78e51a8c 2005-01-14 devnull Options are:
56 78e51a8c 2005-01-14 devnull .TP \w'\fL-d[egp]\ 'u
58 78e51a8c 2005-01-14 devnull Assume all targets to be out of date.
59 78e51a8c 2005-01-14 devnull Thus, everything is updated.
62 78e51a8c 2005-01-14 devnull .BR -d [ egp ]
63 78e51a8c 2005-01-14 devnull Produce debugging output
65 78e51a8c 2005-01-14 devnull is for parsing,
67 78e51a8c 2005-01-14 devnull for graph building,
69 78e51a8c 2005-01-14 devnull for execution).
72 78e51a8c 2005-01-14 devnull Explain why each target is made.
75 78e51a8c 2005-01-14 devnull Force any missing intermediate targets to be made.
78 78e51a8c 2005-01-14 devnull Do as much work as possible in the face of errors.
81 78e51a8c 2005-01-14 devnull Print, but do not execute, the commands
82 78e51a8c 2005-01-14 devnull needed to update the targets.
85 78e51a8c 2005-01-14 devnull Make the command line arguments sequentially rather than in parallel.
88 78e51a8c 2005-01-14 devnull Touch (update the modified date of) file targets, without
89 78e51a8c 2005-01-14 devnull executing any recipes.
91 78e51a8c 2005-01-14 devnull .BI -w target1 , target2,...
92 78e51a8c 2005-01-14 devnull Pretend the modify time for each
93 78e51a8c 2005-01-14 devnull .I target
94 78e51a8c 2005-01-14 devnull is the current time; useful in conjunction with
96 78e51a8c 2005-01-14 devnull to learn what updates would be triggered by
97 78e51a8c 2005-01-14 devnull modifying the
98 78e51a8c 2005-01-14 devnull .IR targets .
100 78e51a8c 2005-01-14 devnull .SS The \fLmkfile\fP
102 78e51a8c 2005-01-14 devnull .I mkfile
103 78e51a8c 2005-01-14 devnull consists of
104 78e51a8c 2005-01-14 devnull .I assignments
105 78e51a8c 2005-01-14 devnull (described under `Environment') and
106 78e51a8c 2005-01-14 devnull .IR rules .
107 78e51a8c 2005-01-14 devnull A rule contains
108 78e51a8c 2005-01-14 devnull .I targets
110 78e51a8c 2005-01-14 devnull .IR tail .
111 78e51a8c 2005-01-14 devnull A target is a literal string
112 78e51a8c 2005-01-14 devnull and is normally a file name.
113 78e51a8c 2005-01-14 devnull The tail contains zero or more
114 78e51a8c 2005-01-14 devnull .I prerequisites
115 78e51a8c 2005-01-14 devnull and an optional
116 78e51a8c 2005-01-14 devnull .IR recipe ,
117 78e51a8c 2005-01-14 devnull which is an
118 78e51a8c 2005-01-14 devnull .B shell
120 78e51a8c 2005-01-14 devnull Each line of the recipe must begin with white space.
121 78e51a8c 2005-01-14 devnull A rule takes the form
124 78e51a8c 2005-01-14 devnull target: prereq1 prereq2
125 78e51a8c 2005-01-14 devnull \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
128 78e51a8c 2005-01-14 devnull When the recipe is executed,
129 78e51a8c 2005-01-14 devnull the first character on every line is elided.
131 78e51a8c 2005-01-14 devnull After the colon on the target line, a rule may specify
132 78e51a8c 2005-01-14 devnull .IR attributes ,
133 78e51a8c 2005-01-14 devnull described below.
136 78e51a8c 2005-01-14 devnull .I meta-rule
137 78e51a8c 2005-01-14 devnull has a target of the form
138 78e51a8c 2005-01-14 devnull .IB A % B
143 78e51a8c 2005-01-14 devnull are (possibly empty) strings.
144 78e51a8c 2005-01-14 devnull A meta-rule acts as a rule for any potential target whose
145 78e51a8c 2005-01-14 devnull name matches
146 78e51a8c 2005-01-14 devnull .IB A % B
149 78e51a8c 2005-01-14 devnull replaced by an arbitrary string, called the
150 78e51a8c 2005-01-14 devnull .IR stem .
151 78e51a8c 2005-01-14 devnull In interpreting a meta-rule,
152 78e51a8c 2005-01-14 devnull the stem is substituted for all occurrences of
154 78e51a8c 2005-01-14 devnull in the prerequisite names.
155 78e51a8c 2005-01-14 devnull In the recipe of a meta-rule, the environment variable
156 78e51a8c 2005-01-14 devnull .B $stem
157 78e51a8c 2005-01-14 devnull contains the string matched by the
159 78e51a8c 2005-01-14 devnull For example, a meta-rule to compile a C program
160 78e51a8c 2005-01-14 devnull might be:
164 78e51a8c 2005-01-14 devnull cc -c $stem.c
165 78e51a8c 2005-01-14 devnull ld -o $stem $stem.o
168 78e51a8c 2005-01-14 devnull Meta-rules may contain an ampersand
170 78e51a8c 2005-01-14 devnull rather than a percent sign
174 78e51a8c 2005-01-14 devnull matches a maximal length string of any characters;
177 78e51a8c 2005-01-14 devnull matches a maximal length string of any characters except period
178 78e51a8c 2005-01-14 devnull or slash.
180 78e51a8c 2005-01-14 devnull The text of the
181 78e51a8c 2005-01-14 devnull .I mkfile
182 78e51a8c 2005-01-14 devnull is processed as follows.
183 78e51a8c 2005-01-14 devnull Lines beginning with
185 78e51a8c 2005-01-14 devnull followed by a file name are replaced by the contents of the named
187 78e51a8c 2005-01-14 devnull Lines beginning with
189 78e51a8c 2005-01-14 devnull followed by a file name are replaced by the output
190 78e51a8c 2005-01-14 devnull of the execution of the named
192 78e51a8c 2005-01-14 devnull Blank lines and comments, which run from unquoted
194 78e51a8c 2005-01-14 devnull characters to the following newline, are deleted.
195 78e51a8c 2005-01-14 devnull The character sequence backslash-newline is deleted,
196 78e51a8c 2005-01-14 devnull so long lines in
197 78e51a8c 2005-01-14 devnull .I mkfile
198 78e51a8c 2005-01-14 devnull may be folded.
199 78e51a8c 2005-01-14 devnull Non-recipe lines are processed by substituting for
200 78e51a8c 2005-01-14 devnull .BI `{ command }
201 78e51a8c 2005-01-14 devnull the output of the
202 78e51a8c 2005-01-14 devnull .I command
203 78e51a8c 2005-01-14 devnull when run by
204 78e51a8c 2005-01-14 devnull .IR sh .
205 78e51a8c 2005-01-14 devnull References to variables are replaced by the variables' values.
206 78e51a8c 2005-01-14 devnull Special characters may be quoted using single quotes
207 78e51a8c 2005-01-14 devnull .BR \&''
209 78e51a8c 2005-01-14 devnull .IR sh (1).
211 78e51a8c 2005-01-14 devnull Assignments and rules are distinguished by
212 78e51a8c 2005-01-14 devnull the first unquoted occurrence of
217 78e51a8c 2005-01-14 devnull (assignment).
219 78e51a8c 2005-01-14 devnull A later rule may modify or override an existing rule under the
220 78e51a8c 2005-01-14 devnull following conditions:
223 78e51a8c 2005-01-14 devnull If the targets of the rules exactly match and one rule
224 78e51a8c 2005-01-14 devnull contains only a prerequisite clause and no recipe, the
225 78e51a8c 2005-01-14 devnull clause is added to the prerequisites of the other rule.
226 78e51a8c 2005-01-14 devnull If either or both targets are virtual, the recipe is
227 78e51a8c 2005-01-14 devnull always executed.
230 78e51a8c 2005-01-14 devnull If the targets of the rules match exactly and the
231 78e51a8c 2005-01-14 devnull prerequisites do not match and both rules
232 78e51a8c 2005-01-14 devnull contain recipes,
234 78e51a8c 2005-01-14 devnull reports an ``ambiguous recipe'' error.
237 78e51a8c 2005-01-14 devnull If the target and prerequisites of both rules match exactly,
238 78e51a8c 2005-01-14 devnull the second rule overrides the first.
239 78e51a8c 2005-01-14 devnull .SS Environment
240 78e51a8c 2005-01-14 devnull Rules may make use of
242 78e51a8c 2005-01-14 devnull environment variables.
243 78e51a8c 2005-01-14 devnull A legal reference of the form
246 78e51a8c 2005-01-14 devnull .B ${name}
247 78e51a8c 2005-01-14 devnull is expanded as in
248 78e51a8c 2005-01-14 devnull .IR sh (1).
249 78e51a8c 2005-01-14 devnull A reference of the form
250 78e51a8c 2005-01-14 devnull .BI ${name: A % B = C\fL%\fID\fL}\fR,
252 78e51a8c 2005-01-14 devnull .I A, B, C, D
253 78e51a8c 2005-01-14 devnull are (possibly empty) strings,
254 78e51a8c 2005-01-14 devnull has the value formed by expanding
255 78e51a8c 2005-01-14 devnull .B $name
256 78e51a8c 2005-01-14 devnull and substituting
264 78e51a8c 2005-01-14 devnull in each word in
265 78e51a8c 2005-01-14 devnull .B $name
266 78e51a8c 2005-01-14 devnull that matches pattern
267 78e51a8c 2005-01-14 devnull .IB A % B\f1.
269 78e51a8c 2005-01-14 devnull Variables can be set by
270 78e51a8c 2005-01-14 devnull assignments of the form
272 78e51a8c 2005-01-14 devnull var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
274 78e51a8c 2005-01-14 devnull Blanks in the
275 78e51a8c 2005-01-14 devnull .I value
276 78e51a8c 2005-01-14 devnull break it into words.
277 78e51a8c 2005-01-14 devnull Such variables are exported
278 78e51a8c 2005-01-14 devnull to the environment of
279 78e51a8c 2005-01-14 devnull recipes as they are executed, unless
281 78e51a8c 2005-01-14 devnull the only legal attribute
282 78e51a8c 2005-01-14 devnull .IR attr ,
283 78e51a8c 2005-01-14 devnull is present.
284 78e51a8c 2005-01-14 devnull The initial value of a variable is
285 78e51a8c 2005-01-14 devnull taken from (in increasing order of precedence)
286 78e51a8c 2005-01-14 devnull the default values below,
288 78e51a8c 2005-01-14 devnull environment, the
289 78e51a8c 2005-01-14 devnull .IR mkfiles ,
290 78e51a8c 2005-01-14 devnull and any command line assignment as an argument to
291 78e51a8c 2005-01-14 devnull .IR mk .
292 78e51a8c 2005-01-14 devnull A variable assignment argument overrides the first (but not any subsequent)
293 78e51a8c 2005-01-14 devnull assignment to that variable.
295 78e51a8c 2005-01-14 devnull The variable
296 78e51a8c 2005-01-14 devnull .B MKFLAGS
297 78e51a8c 2005-01-14 devnull contains all the option arguments (arguments starting with
299 78e51a8c 2005-01-14 devnull or containing
302 78e51a8c 2005-01-14 devnull .B MKARGS
303 78e51a8c 2005-01-14 devnull contains all the targets in the call to
304 78e51a8c 2005-01-14 devnull .IR mk .
306 78e51a8c 2005-01-14 devnull The variable
307 78e51a8c 2005-01-14 devnull .B MKSHELL
308 78e51a8c 2005-01-14 devnull contains the shell command line
310 78e51a8c 2005-01-14 devnull uses to run recipes.
311 78e51a8c 2005-01-14 devnull If the first word of the command ends in
314 78e51a8c 2005-01-14 devnull .BR rcsh ,
317 78e51a8c 2005-01-14 devnull .IR rc (1)'s
318 78e51a8c 2005-01-14 devnull quoting rules; otherwise it uses
319 78e51a8c 2005-01-14 devnull .IR sh (1)'s.
321 78e51a8c 2005-01-14 devnull .B MKSHELL
322 78e51a8c 2005-01-14 devnull variable is consulted when the mkfile is read, not when it is executed,
323 78e51a8c 2005-01-14 devnull so that different shells can be used within a single mkfile:
326 78e51a8c 2005-01-14 devnull MKSHELL=$PLAN9/bin/rc
327 78e51a8c 2005-01-14 devnull use-rc:V:
328 78e51a8c 2005-01-14 devnull for(i in a b c) echo $i
330 78e51a8c 2005-01-14 devnull MKSHELL=sh
331 78e51a8c 2005-01-14 devnull use-sh:V:
332 78e51a8c 2005-01-14 devnull for i in a b c; do echo $i; done
335 78e51a8c 2005-01-14 devnull Mkfiles included via
339 78e51a8c 2005-01-14 devnull .RI ( q.v. )
340 78e51a8c 2005-01-14 devnull see their own private copy of
341 78e51a8c 2005-01-14 devnull .BR MKSHELL ,
342 78e51a8c 2005-01-14 devnull which always starts set to
345 78e51a8c 2005-01-14 devnull Dynamic information may be included in the mkfile by using a line of the form
347 78e51a8c 2005-01-14 devnull \fR<|\fIcommand\fR \fIargs\fR
349 78e51a8c 2005-01-14 devnull This runs the command
350 78e51a8c 2005-01-14 devnull .I command
351 78e51a8c 2005-01-14 devnull with the given arguments
353 78e51a8c 2005-01-14 devnull and pipes its standard output to
355 78e51a8c 2005-01-14 devnull to be included as part of the mkfile. For instance, the Inferno kernels
356 78e51a8c 2005-01-14 devnull use this technique
357 78e51a8c 2005-01-14 devnull to run a shell command with an awk script and a configuration
358 78e51a8c 2005-01-14 devnull file as arguments in order for
361 78e51a8c 2005-01-14 devnull script to process the file and output a set of variables and their values.
362 78e51a8c 2005-01-14 devnull .SS Execution
364 78e51a8c 2005-01-14 devnull During execution,
366 78e51a8c 2005-01-14 devnull determines which targets must be updated, and in what order,
367 78e51a8c 2005-01-14 devnull to build the
368 78e51a8c 2005-01-14 devnull .I names
369 78e51a8c 2005-01-14 devnull specified on the command line.
370 78e51a8c 2005-01-14 devnull It then runs the associated recipes.
372 78e51a8c 2005-01-14 devnull A target is considered up to date if it has no prerequisites or
373 78e51a8c 2005-01-14 devnull if all its prerequisites are up to date and it is newer
374 78e51a8c 2005-01-14 devnull than all its prerequisites.
375 78e51a8c 2005-01-14 devnull Once the recipe for a target has executed, the target is
376 78e51a8c 2005-01-14 devnull considered up to date.
378 78e51a8c 2005-01-14 devnull The date stamp
379 78e51a8c 2005-01-14 devnull used to determine if a target is up to date is computed
380 78e51a8c 2005-01-14 devnull differently for different types of targets.
381 78e51a8c 2005-01-14 devnull If a target is
382 78e51a8c 2005-01-14 devnull .I virtual
383 78e51a8c 2005-01-14 devnull (the target of a rule with the
385 78e51a8c 2005-01-14 devnull attribute),
386 78e51a8c 2005-01-14 devnull its date stamp is initially zero; when the target is
387 78e51a8c 2005-01-14 devnull updated the date stamp is set to
388 78e51a8c 2005-01-14 devnull the most recent date stamp of its prerequisites.
389 78e51a8c 2005-01-14 devnull Otherwise, if a target does not exist as a file,
390 78e51a8c 2005-01-14 devnull its date stamp is set to the most recent date stamp of its prerequisites,
391 78e51a8c 2005-01-14 devnull or zero if it has no prerequisites.
392 78e51a8c 2005-01-14 devnull Otherwise, the target is the name of a file and
393 78e51a8c 2005-01-14 devnull the target's date stamp is always that file's modification date.
394 78e51a8c 2005-01-14 devnull The date stamp is computed when the target is needed in
395 78e51a8c 2005-01-14 devnull the execution of a rule; it is not a static value.
397 78e51a8c 2005-01-14 devnull Nonexistent targets that have prerequisites
398 78e51a8c 2005-01-14 devnull and are themselves prerequisites are treated specially.
399 78e51a8c 2005-01-14 devnull Such a target
401 78e51a8c 2005-01-14 devnull is given the date stamp of its most recent prerequisite
402 78e51a8c 2005-01-14 devnull and if this causes all the targets which have
404 78e51a8c 2005-01-14 devnull as a prerequisite to be up to date,
406 78e51a8c 2005-01-14 devnull is considered up to date.
407 78e51a8c 2005-01-14 devnull Otherwise,
409 78e51a8c 2005-01-14 devnull is made in the normal fashion.
412 78e51a8c 2005-01-14 devnull flag overrides this special treatment.
414 78e51a8c 2005-01-14 devnull Files may be made in any order that respects
415 78e51a8c 2005-01-14 devnull the preceding restrictions.
417 78e51a8c 2005-01-14 devnull A recipe is executed by supplying the recipe as standard input to
418 78e51a8c 2005-01-14 devnull the command
419 78e51a8c 2005-01-14 devnull .BR /bin/sh .
420 78e51a8c 2005-01-14 devnull (Note that unlike
421 78e51a8c 2005-01-14 devnull .IR make ,
423 78e51a8c 2005-01-14 devnull feeds the entire recipe to the shell rather than running each line
424 78e51a8c 2005-01-14 devnull of the recipe separately.)
425 78e51a8c 2005-01-14 devnull The environment is augmented by the following variables:
427 78e51a8c 2005-01-14 devnull .B $alltarget
428 78e51a8c 2005-01-14 devnull all the targets of this rule.
430 78e51a8c 2005-01-14 devnull .B $newprereq
431 78e51a8c 2005-01-14 devnull the prerequisites that caused this rule to execute.
433 78e51a8c 2005-01-14 devnull .B $newmember
434 78e51a8c 2005-01-14 devnull the prerequisites that are members of an aggregate
435 78e51a8c 2005-01-14 devnull that caused this rule to execute.
436 78e51a8c 2005-01-14 devnull When the prerequisites of a rule are members of an
437 78e51a8c 2005-01-14 devnull aggregate,
438 78e51a8c 2005-01-14 devnull .B $newprereq
439 78e51a8c 2005-01-14 devnull contains the name of the aggregate and out of date
440 78e51a8c 2005-01-14 devnull members, while
441 78e51a8c 2005-01-14 devnull .B $newmember
442 78e51a8c 2005-01-14 devnull contains only the name of the members.
444 78e51a8c 2005-01-14 devnull .B $nproc
445 78e51a8c 2005-01-14 devnull the process slot for this recipe.
446 78e51a8c 2005-01-14 devnull It satisfies
447 78e51a8c 2005-01-14 devnull .RB 0≤ $nproc < $NPROC .
450 78e51a8c 2005-01-14 devnull the process id for the
452 78e51a8c 2005-01-14 devnull executing the recipe.
454 78e51a8c 2005-01-14 devnull .B $prereq
455 78e51a8c 2005-01-14 devnull all the prerequisites for this rule.
457 78e51a8c 2005-01-14 devnull .B $stem
458 78e51a8c 2005-01-14 devnull if this is a meta-rule,
459 78e51a8c 2005-01-14 devnull .B $stem
460 78e51a8c 2005-01-14 devnull is the string that matched
464 78e51a8c 2005-01-14 devnull Otherwise, it is empty.
465 78e51a8c 2005-01-14 devnull For regular expression meta-rules (see below), the variables
466 78e51a8c 2005-01-14 devnull .LR stem0 ", ...,"
467 78e51a8c 2005-01-14 devnull .L stem9
468 78e51a8c 2005-01-14 devnull are set to the corresponding subexpressions.
470 78e51a8c 2005-01-14 devnull .B $target
471 78e51a8c 2005-01-14 devnull the targets for this rule that need to be remade.
473 78e51a8c 2005-01-14 devnull These variables are available only during the execution of a recipe,
474 78e51a8c 2005-01-14 devnull not while evaluating the
475 78e51a8c 2005-01-14 devnull .IR mkfile .
477 78e51a8c 2005-01-14 devnull Unless the rule has the
479 78e51a8c 2005-01-14 devnull attribute,
480 78e51a8c 2005-01-14 devnull the recipe is printed prior to execution
481 78e51a8c 2005-01-14 devnull with recognizable environment variables expanded.
482 78e51a8c 2005-01-14 devnull Commands returning error status
485 78e51a8c 2005-01-14 devnull to terminate.
487 78e51a8c 2005-01-14 devnull Recipes and backquoted
489 78e51a8c 2005-01-14 devnull commands in places such as assignments
490 78e51a8c 2005-01-14 devnull execute in a copy of
492 78e51a8c 2005-01-14 devnull environment; changes they make to
493 78e51a8c 2005-01-14 devnull environment variables are not visible from
494 78e51a8c 2005-01-14 devnull .IR mk .
496 78e51a8c 2005-01-14 devnull Variable substitution in a rule is done when
497 78e51a8c 2005-01-14 devnull the rule is read; variable substitution in the recipe is done
498 78e51a8c 2005-01-14 devnull when the recipe is executed. For example:
502 78e51a8c 2005-01-14 devnull foo: $bar
503 78e51a8c 2005-01-14 devnull $CC -o foo $bar
507 78e51a8c 2005-01-14 devnull will compile
510 78e51a8c 2005-01-14 devnull .BR foo ,
513 78e51a8c 2005-01-14 devnull is newer than
514 78e51a8c 2005-01-14 devnull .BR foo .
515 78e51a8c 2005-01-14 devnull .SS Aggregates
516 78e51a8c 2005-01-14 devnull Names of the form
517 78e51a8c 2005-01-14 devnull .IR a ( b )
518 78e51a8c 2005-01-14 devnull refer to member
520 78e51a8c 2005-01-14 devnull of the aggregate
522 78e51a8c 2005-01-14 devnull .SS Attributes
523 78e51a8c 2005-01-14 devnull The colon separating the target from the prerequisites
525 78e51a8c 2005-01-14 devnull immediately followed by
526 78e51a8c 2005-01-14 devnull .I attributes
527 78e51a8c 2005-01-14 devnull and another colon.
528 78e51a8c 2005-01-14 devnull The attributes are:
531 78e51a8c 2005-01-14 devnull If the recipe exits with a non-null status, the target is deleted.
534 78e51a8c 2005-01-14 devnull Continue execution if the recipe draws errors.
537 78e51a8c 2005-01-14 devnull If there is no recipe, the target has its time updated.
540 78e51a8c 2005-01-14 devnull The rule is a meta-rule that cannot be a target of a virtual rule.
541 78e51a8c 2005-01-14 devnull Only files match the pattern in the target.
544 78e51a8c 2005-01-14 devnull The characters after the
546 78e51a8c 2005-01-14 devnull until the terminating
548 78e51a8c 2005-01-14 devnull are taken as a program name.
549 78e51a8c 2005-01-14 devnull It will be invoked as
550 78e51a8c 2005-01-14 devnull .B "sh -c prog 'arg1' 'arg2'"
551 78e51a8c 2005-01-14 devnull and should return a zero exit status
552 78e51a8c 2005-01-14 devnull if and only if arg1 is up to date with respect to arg2.
553 78e51a8c 2005-01-14 devnull Date stamps are still propagated in the normal way.
556 78e51a8c 2005-01-14 devnull The recipe is not printed prior to execution.
559 78e51a8c 2005-01-14 devnull The rule is a meta-rule using regular expressions.
560 78e51a8c 2005-01-14 devnull In the rule,
562 78e51a8c 2005-01-14 devnull has no special meaning.
563 78e51a8c 2005-01-14 devnull The target is interpreted as a regular expression as defined in
564 78e51a8c 2005-01-14 devnull .IR regexp9 (7).
565 78e51a8c 2005-01-14 devnull The prerequisites may contain references
566 78e51a8c 2005-01-14 devnull to subexpressions in form
567 78e51a8c 2005-01-14 devnull .BI \e n\f1,
568 78e51a8c 2005-01-14 devnull as in the substitute command of
569 78e51a8c 2005-01-14 devnull .IR sed (1).
572 78e51a8c 2005-01-14 devnull The targets are considered to have been updated
573 78e51a8c 2005-01-14 devnull even if the recipe did not do so.
576 78e51a8c 2005-01-14 devnull The targets of this rule are marked as virtual.
577 78e51a8c 2005-01-14 devnull They are distinct from files of the same name.
579 78e51a8c 2005-01-14 devnull .SH EXAMPLES
580 78e51a8c 2005-01-14 devnull A simple mkfile to compile a program:
583 78e51a8c 2005-01-14 devnull .ta 8n +8n +8n +8n +8n +8n +8n
584 78e51a8c 2005-01-14 devnull </$objtype/mkfile
586 78e51a8c 2005-01-14 devnull prog: a.$O b.$O c.$O
587 78e51a8c 2005-01-14 devnull $LD $LDFLAGS -o $target $prereq
589 78e51a8c 2005-01-14 devnull %.$O: %.c
590 78e51a8c 2005-01-14 devnull $CC $CFLAGS $stem.c
593 78e51a8c 2005-01-14 devnull Override flag settings in the mkfile:
596 78e51a8c 2005-01-14 devnull % mk target 'CFLAGS=-S -w'
599 78e51a8c 2005-01-14 devnull Maintain a library:
602 78e51a8c 2005-01-14 devnull libc.a(%.$O):N: %.$O
603 78e51a8c 2005-01-14 devnull libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
604 78e51a8c 2005-01-14 devnull ar r libc.a $newmember
607 78e51a8c 2005-01-14 devnull String expression variables to derive names from a master list:
610 78e51a8c 2005-01-14 devnull NAMES=alloc arc bquote builtins expand main match mk var word
611 78e51a8c 2005-01-14 devnull OBJ=${NAMES:%=%.$O}
614 78e51a8c 2005-01-14 devnull Regular expression meta-rules:
617 78e51a8c 2005-01-14 devnull ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
618 78e51a8c 2005-01-14 devnull cd $stem1; $CC $CFLAGS $stem2.c
621 78e51a8c 2005-01-14 devnull A correct way to deal with
622 78e51a8c 2005-01-14 devnull .IR yacc (1)
623 78e51a8c 2005-01-14 devnull grammars.
624 78e51a8c 2005-01-14 devnull The file
625 78e51a8c 2005-01-14 devnull .B lex.c
626 78e51a8c 2005-01-14 devnull includes the file
627 78e51a8c 2005-01-14 devnull .B x.tab.h
628 78e51a8c 2005-01-14 devnull rather than
629 78e51a8c 2005-01-14 devnull .B y.tab.h
630 78e51a8c 2005-01-14 devnull in order to reflect changes in content, not just modification time.
633 78e51a8c 2005-01-14 devnull lex.$O: x.tab.h
634 78e51a8c 2005-01-14 devnull x.tab.h: y.tab.h
635 78e51a8c 2005-01-14 devnull cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
636 78e51a8c 2005-01-14 devnull y.tab.c y.tab.h: gram.y
637 78e51a8c 2005-01-14 devnull $YACC -d gram.y
640 78e51a8c 2005-01-14 devnull The above example could also use the
642 78e51a8c 2005-01-14 devnull attribute for the
643 78e51a8c 2005-01-14 devnull .B x.tab.h
647 78e51a8c 2005-01-14 devnull x.tab.h:Pcmp -s: y.tab.h
648 78e51a8c 2005-01-14 devnull cp y.tab.h x.tab.h
650 78e51a8c 2005-01-14 devnull .SH SOURCE
651 78e51a8c 2005-01-14 devnull .B http://swtch.com/plan9port/unix
652 78e51a8c 2005-01-14 devnull .SH SEE ALSO
653 78e51a8c 2005-01-14 devnull .IR sh (1),
654 78e51a8c 2005-01-14 devnull .IR regexp9 (7)
656 78e51a8c 2005-01-14 devnull A. Hume,
657 78e51a8c 2005-01-14 devnull ``Mk: a Successor to Make''
658 78e51a8c 2005-01-14 devnull (Tenth Edition Research Unix Manuals).
660 78e51a8c 2005-01-14 devnull Andrew G. Hume and Bob Flandrena,
661 78e51a8c 2005-01-14 devnull ``Maintaining Files on Plan 9 with Mk''.
662 d3a25066 2005-01-16 devnull .BR DOCPREFIX/doc/mk.pdf .
663 78e51a8c 2005-01-14 devnull .SH HISTORY
664 78e51a8c 2005-01-14 devnull Andrew Hume wrote
666 78e51a8c 2005-01-14 devnull for Tenth Edition Research Unix.
667 78e51a8c 2005-01-14 devnull It was later ported to Plan 9.
668 78e51a8c 2005-01-14 devnull This software is a port of the Plan 9 version back to Unix.
669 78e51a8c 2005-01-14 devnull .SH BUGS
670 78e51a8c 2005-01-14 devnull Identical recipes for regular expression meta-rules only have one target.
672 78e51a8c 2005-01-14 devnull Seemingly appropriate input like
673 78e51a8c 2005-01-14 devnull .B CFLAGS=-DHZ=60
674 78e51a8c 2005-01-14 devnull is parsed as an erroneous attribute; correct it by inserting
675 78e51a8c 2005-01-14 devnull a space after the first
678 78e51a8c 2005-01-14 devnull The recipes printed by
680 78e51a8c 2005-01-14 devnull before being passed to
681 78e51a8c 2005-01-14 devnull the shell
682 78e51a8c 2005-01-14 devnull for execution are sometimes erroneously expanded
683 78e51a8c 2005-01-14 devnull for printing. Don't trust what's printed; rely
684 78e51a8c 2005-01-14 devnull on what the shell