3 93aa30a8 2005-01-14 devnull mk \- maintain (make) related files
4 058b0118 2005-01-03 devnull .SH SYNOPSIS
11 058b0118 2005-01-03 devnull .I option ...
14 058b0118 2005-01-03 devnull .I target ...
16 058b0118 2005-01-03 devnull .SH DESCRIPTION
18 058b0118 2005-01-03 devnull uses the dependency rules specified in
19 058b0118 2005-01-03 devnull .I mkfile
20 058b0118 2005-01-03 devnull to control the update (usually by compilation) of
21 058b0118 2005-01-03 devnull .I targets
22 058b0118 2005-01-03 devnull (usually files)
23 058b0118 2005-01-03 devnull from the source files upon which they depend.
25 058b0118 2005-01-03 devnull .I mkfile
27 058b0118 2005-01-03 devnull .LR mkfile )
28 058b0118 2005-01-03 devnull contains a
30 058b0118 2005-01-03 devnull for each target that identifies the files and other
31 058b0118 2005-01-03 devnull targets upon which it depends and an
32 058b0118 2005-01-03 devnull .IR sh (1)
33 058b0118 2005-01-03 devnull script, a
34 058b0118 2005-01-03 devnull .IR recipe ,
35 058b0118 2005-01-03 devnull to update the target.
36 058b0118 2005-01-03 devnull The script is run if the target does not exist
37 058b0118 2005-01-03 devnull or if it is older than any of the files it depends on.
38 058b0118 2005-01-03 devnull .I Mkfile
39 058b0118 2005-01-03 devnull may also contain
40 058b0118 2005-01-03 devnull .I meta-rules
41 058b0118 2005-01-03 devnull that define actions for updating implicit targets.
43 058b0118 2005-01-03 devnull .I target
44 058b0118 2005-01-03 devnull is specified, the target of the first rule (not meta-rule) in
45 058b0118 2005-01-03 devnull .I mkfile
46 058b0118 2005-01-03 devnull is updated.
48 058b0118 2005-01-03 devnull The environment variable
49 058b0118 2005-01-03 devnull .B $NPROC
50 058b0118 2005-01-03 devnull determines how many targets may be updated simultaneously;
51 058b0118 2005-01-03 devnull Some operating systems, e.g., Plan 9, set
52 058b0118 2005-01-03 devnull .B $NPROC
53 058b0118 2005-01-03 devnull automatically to the number of CPUs on the current machine.
55 058b0118 2005-01-03 devnull Options are:
56 058b0118 2005-01-03 devnull .TP \w'\fL-d[egp]\ 'u
58 058b0118 2005-01-03 devnull Assume all targets to be out of date.
59 058b0118 2005-01-03 devnull Thus, everything is updated.
62 058b0118 2005-01-03 devnull .BR -d [ egp ]
63 058b0118 2005-01-03 devnull Produce debugging output
65 058b0118 2005-01-03 devnull is for parsing,
67 058b0118 2005-01-03 devnull for graph building,
69 058b0118 2005-01-03 devnull for execution).
72 058b0118 2005-01-03 devnull Explain why each target is made.
75 058b0118 2005-01-03 devnull Force any missing intermediate targets to be made.
78 058b0118 2005-01-03 devnull Do as much work as possible in the face of errors.
81 058b0118 2005-01-03 devnull Print, but do not execute, the commands
82 058b0118 2005-01-03 devnull needed to update the targets.
85 058b0118 2005-01-03 devnull Make the command line arguments sequentially rather than in parallel.
88 058b0118 2005-01-03 devnull Touch (update the modified date of) file targets, without
89 058b0118 2005-01-03 devnull executing any recipes.
91 058b0118 2005-01-03 devnull .BI -w target1 , target2,...
92 058b0118 2005-01-03 devnull Pretend the modify time for each
93 058b0118 2005-01-03 devnull .I target
94 058b0118 2005-01-03 devnull is the current time; useful in conjunction with
96 058b0118 2005-01-03 devnull to learn what updates would be triggered by
97 058b0118 2005-01-03 devnull modifying the
98 058b0118 2005-01-03 devnull .IR targets .
100 058b0118 2005-01-03 devnull .SS The \fLmkfile\fP
102 058b0118 2005-01-03 devnull .I mkfile
103 058b0118 2005-01-03 devnull consists of
104 058b0118 2005-01-03 devnull .I assignments
105 058b0118 2005-01-03 devnull (described under `Environment') and
106 058b0118 2005-01-03 devnull .IR rules .
107 058b0118 2005-01-03 devnull A rule contains
108 058b0118 2005-01-03 devnull .I targets
110 058b0118 2005-01-03 devnull .IR tail .
111 058b0118 2005-01-03 devnull A target is a literal string
112 058b0118 2005-01-03 devnull and is normally a file name.
113 058b0118 2005-01-03 devnull The tail contains zero or more
114 058b0118 2005-01-03 devnull .I prerequisites
115 058b0118 2005-01-03 devnull and an optional
116 058b0118 2005-01-03 devnull .IR recipe ,
117 058b0118 2005-01-03 devnull which is an
118 058b0118 2005-01-03 devnull .B shell
120 058b0118 2005-01-03 devnull Each line of the recipe must begin with white space.
121 058b0118 2005-01-03 devnull A rule takes the form
124 058b0118 2005-01-03 devnull target: prereq1 prereq2
125 058b0118 2005-01-03 devnull \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
128 058b0118 2005-01-03 devnull When the recipe is executed,
129 058b0118 2005-01-03 devnull the first character on every line is elided.
131 058b0118 2005-01-03 devnull After the colon on the target line, a rule may specify
132 058b0118 2005-01-03 devnull .IR attributes ,
133 058b0118 2005-01-03 devnull described below.
136 058b0118 2005-01-03 devnull .I meta-rule
137 058b0118 2005-01-03 devnull has a target of the form
138 058b0118 2005-01-03 devnull .IB A % B
143 058b0118 2005-01-03 devnull are (possibly empty) strings.
144 058b0118 2005-01-03 devnull A meta-rule acts as a rule for any potential target whose
145 058b0118 2005-01-03 devnull name matches
146 058b0118 2005-01-03 devnull .IB A % B
149 058b0118 2005-01-03 devnull replaced by an arbitrary string, called the
150 058b0118 2005-01-03 devnull .IR stem .
151 058b0118 2005-01-03 devnull In interpreting a meta-rule,
152 058b0118 2005-01-03 devnull the stem is substituted for all occurrences of
154 058b0118 2005-01-03 devnull in the prerequisite names.
155 058b0118 2005-01-03 devnull In the recipe of a meta-rule, the environment variable
156 058b0118 2005-01-03 devnull .B $stem
157 058b0118 2005-01-03 devnull contains the string matched by the
159 058b0118 2005-01-03 devnull For example, a meta-rule to compile a C program using
160 058b0118 2005-01-03 devnull .IR 9c (1)
161 058b0118 2005-01-03 devnull might be:
165 058b0118 2005-01-03 devnull 9c -c $stem.c
166 058b0118 2005-01-03 devnull 9l -o $stem $stem.o
169 058b0118 2005-01-03 devnull Meta-rules may contain an ampersand
171 058b0118 2005-01-03 devnull rather than a percent sign
175 058b0118 2005-01-03 devnull matches a maximal length string of any characters;
178 058b0118 2005-01-03 devnull matches a maximal length string of any characters except period
179 058b0118 2005-01-03 devnull or slash.
181 058b0118 2005-01-03 devnull The text of the
182 058b0118 2005-01-03 devnull .I mkfile
183 058b0118 2005-01-03 devnull is processed as follows.
184 058b0118 2005-01-03 devnull Lines beginning with
186 058b0118 2005-01-03 devnull followed by a file name are replaced by the contents of the named
188 058b0118 2005-01-03 devnull Lines beginning with
190 058b0118 2005-01-03 devnull followed by a file name are replaced by the output
191 058b0118 2005-01-03 devnull of the execution of the named
193 058b0118 2005-01-03 devnull Blank lines and comments, which run from unquoted
195 058b0118 2005-01-03 devnull characters to the following newline, are deleted.
196 058b0118 2005-01-03 devnull The character sequence backslash-newline is deleted,
197 058b0118 2005-01-03 devnull so long lines in
198 058b0118 2005-01-03 devnull .I mkfile
199 058b0118 2005-01-03 devnull may be folded.
200 058b0118 2005-01-03 devnull Non-recipe lines are processed by substituting for
201 058b0118 2005-01-03 devnull .BI `{ command }
202 058b0118 2005-01-03 devnull the output of the
203 058b0118 2005-01-03 devnull .I command
204 058b0118 2005-01-03 devnull when run by
205 058b0118 2005-01-03 devnull .IR sh .
206 058b0118 2005-01-03 devnull References to variables are replaced by the variables' values.
207 058b0118 2005-01-03 devnull Special characters may be quoted using single quotes
208 058b0118 2005-01-03 devnull .BR \&''
210 058b0118 2005-01-03 devnull .IR sh (1).
212 058b0118 2005-01-03 devnull Assignments and rules are distinguished by
213 058b0118 2005-01-03 devnull the first unquoted occurrence of
218 058b0118 2005-01-03 devnull (assignment).
220 058b0118 2005-01-03 devnull A later rule may modify or override an existing rule under the
221 058b0118 2005-01-03 devnull following conditions:
224 058b0118 2005-01-03 devnull If the targets of the rules exactly match and one rule
225 058b0118 2005-01-03 devnull contains only a prerequisite clause and no recipe, the
226 058b0118 2005-01-03 devnull clause is added to the prerequisites of the other rule.
227 058b0118 2005-01-03 devnull If either or both targets are virtual, the recipe is
228 058b0118 2005-01-03 devnull always executed.
231 058b0118 2005-01-03 devnull If the targets of the rules match exactly and the
232 058b0118 2005-01-03 devnull prerequisites do not match and both rules
233 058b0118 2005-01-03 devnull contain recipes,
235 058b0118 2005-01-03 devnull reports an ``ambiguous recipe'' error.
238 058b0118 2005-01-03 devnull If the target and prerequisites of both rules match exactly,
239 058b0118 2005-01-03 devnull the second rule overrides the first.
240 058b0118 2005-01-03 devnull .SS Environment
241 058b0118 2005-01-03 devnull Rules may make use of
243 058b0118 2005-01-03 devnull environment variables.
244 058b0118 2005-01-03 devnull A legal reference of the form
247 058b0118 2005-01-03 devnull .B ${name}
248 058b0118 2005-01-03 devnull is expanded as in
249 058b0118 2005-01-03 devnull .IR sh (1).
250 058b0118 2005-01-03 devnull A reference of the form
251 058b0118 2005-01-03 devnull .BI ${name: A % B = C\fL%\fID\fL}\fR,
253 058b0118 2005-01-03 devnull .I A, B, C, D
254 058b0118 2005-01-03 devnull are (possibly empty) strings,
255 058b0118 2005-01-03 devnull has the value formed by expanding
256 058b0118 2005-01-03 devnull .B $name
257 058b0118 2005-01-03 devnull and substituting
265 058b0118 2005-01-03 devnull in each word in
266 058b0118 2005-01-03 devnull .B $name
267 058b0118 2005-01-03 devnull that matches pattern
268 058b0118 2005-01-03 devnull .IB A % B\f1.
270 058b0118 2005-01-03 devnull Variables can be set by
271 058b0118 2005-01-03 devnull assignments of the form
273 058b0118 2005-01-03 devnull var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
275 058b0118 2005-01-03 devnull Blanks in the
276 058b0118 2005-01-03 devnull .I value
277 058b0118 2005-01-03 devnull break it into words.
278 058b0118 2005-01-03 devnull Such variables are exported
279 058b0118 2005-01-03 devnull to the environment of
280 058b0118 2005-01-03 devnull recipes as they are executed, unless
282 058b0118 2005-01-03 devnull the only legal attribute
283 058b0118 2005-01-03 devnull .IR attr ,
284 058b0118 2005-01-03 devnull is present.
285 058b0118 2005-01-03 devnull The initial value of a variable is
286 058b0118 2005-01-03 devnull taken from (in increasing order of precedence)
287 058b0118 2005-01-03 devnull the default values below,
289 058b0118 2005-01-03 devnull environment, the
290 058b0118 2005-01-03 devnull .IR mkfiles ,
291 058b0118 2005-01-03 devnull and any command line assignment as an argument to
292 058b0118 2005-01-03 devnull .IR mk .
293 058b0118 2005-01-03 devnull A variable assignment argument overrides the first (but not any subsequent)
294 058b0118 2005-01-03 devnull assignment to that variable.
296 058b0118 2005-01-03 devnull The variable
297 058b0118 2005-01-03 devnull .B MKFLAGS
298 058b0118 2005-01-03 devnull contains all the option arguments (arguments starting with
300 058b0118 2005-01-03 devnull or containing
303 058b0118 2005-01-03 devnull .B MKARGS
304 058b0118 2005-01-03 devnull contains all the targets in the call to
305 058b0118 2005-01-03 devnull .IR mk .
307 c8b6342d 2005-01-13 devnull The variable
308 c8b6342d 2005-01-13 devnull .B MKSHELL
309 c8b6342d 2005-01-13 devnull contains the shell command line
311 c8b6342d 2005-01-13 devnull uses to run recipes.
312 c8b6342d 2005-01-13 devnull If the first word of the command ends in
315 c8b6342d 2005-01-13 devnull .BR rcsh ,
318 c8b6342d 2005-01-13 devnull .IR rc (1)'s
319 c8b6342d 2005-01-13 devnull quoting rules; otherwise it uses
320 c8b6342d 2005-01-13 devnull .IR sh (1)'s.
322 c8b6342d 2005-01-13 devnull .B MKSHELL
323 c8b6342d 2005-01-13 devnull variable is consulted when the mkfile is read, not when it is executed,
324 c8b6342d 2005-01-13 devnull so that different shells can be used within a single mkfile:
327 c8b6342d 2005-01-13 devnull MKSHELL=$PLAN9/bin/rc
328 c8b6342d 2005-01-13 devnull use-rc:V:
329 c8b6342d 2005-01-13 devnull for(i in a b c) echo $i
331 c8b6342d 2005-01-13 devnull MKSHELL=sh
332 c8b6342d 2005-01-13 devnull use-sh:V:
333 c8b6342d 2005-01-13 devnull for i in a b c; do echo $i; done
336 c8b6342d 2005-01-13 devnull Mkfiles included via
340 c8b6342d 2005-01-13 devnull .RI ( q.v. )
341 c8b6342d 2005-01-13 devnull see their own private copy of
342 c8b6342d 2005-01-13 devnull .BR MKSHELL ,
343 c8b6342d 2005-01-13 devnull which always starts set to
346 058b0118 2005-01-03 devnull Dynamic information may be included in the mkfile by using a line of the form
348 058b0118 2005-01-03 devnull \fR<|\fIcommand\fR \fIargs\fR
350 058b0118 2005-01-03 devnull This runs the command
351 058b0118 2005-01-03 devnull .I command
352 058b0118 2005-01-03 devnull with the given arguments
354 058b0118 2005-01-03 devnull and pipes its standard output to
356 058b0118 2005-01-03 devnull to be included as part of the mkfile. For instance, the Inferno kernels
357 058b0118 2005-01-03 devnull use this technique
358 058b0118 2005-01-03 devnull to run a shell command with an awk script and a configuration
359 058b0118 2005-01-03 devnull file as arguments in order for
362 058b0118 2005-01-03 devnull script to process the file and output a set of variables and their values.
363 058b0118 2005-01-03 devnull .SS Execution
365 058b0118 2005-01-03 devnull During execution,
367 058b0118 2005-01-03 devnull determines which targets must be updated, and in what order,
368 058b0118 2005-01-03 devnull to build the
369 058b0118 2005-01-03 devnull .I names
370 058b0118 2005-01-03 devnull specified on the command line.
371 058b0118 2005-01-03 devnull It then runs the associated recipes.
373 058b0118 2005-01-03 devnull A target is considered up to date if it has no prerequisites or
374 058b0118 2005-01-03 devnull if all its prerequisites are up to date and it is newer
375 058b0118 2005-01-03 devnull than all its prerequisites.
376 058b0118 2005-01-03 devnull Once the recipe for a target has executed, the target is
377 058b0118 2005-01-03 devnull considered up to date.
379 058b0118 2005-01-03 devnull The date stamp
380 058b0118 2005-01-03 devnull used to determine if a target is up to date is computed
381 058b0118 2005-01-03 devnull differently for different types of targets.
382 058b0118 2005-01-03 devnull If a target is
383 058b0118 2005-01-03 devnull .I virtual
384 058b0118 2005-01-03 devnull (the target of a rule with the
386 058b0118 2005-01-03 devnull attribute),
387 058b0118 2005-01-03 devnull its date stamp is initially zero; when the target is
388 058b0118 2005-01-03 devnull updated the date stamp is set to
389 058b0118 2005-01-03 devnull the most recent date stamp of its prerequisites.
390 058b0118 2005-01-03 devnull Otherwise, if a target does not exist as a file,
391 058b0118 2005-01-03 devnull its date stamp is set to the most recent date stamp of its prerequisites,
392 058b0118 2005-01-03 devnull or zero if it has no prerequisites.
393 058b0118 2005-01-03 devnull Otherwise, the target is the name of a file and
394 058b0118 2005-01-03 devnull the target's date stamp is always that file's modification date.
395 058b0118 2005-01-03 devnull The date stamp is computed when the target is needed in
396 058b0118 2005-01-03 devnull the execution of a rule; it is not a static value.
398 058b0118 2005-01-03 devnull Nonexistent targets that have prerequisites
399 058b0118 2005-01-03 devnull and are themselves prerequisites are treated specially.
400 058b0118 2005-01-03 devnull Such a target
402 058b0118 2005-01-03 devnull is given the date stamp of its most recent prerequisite
403 058b0118 2005-01-03 devnull and if this causes all the targets which have
405 058b0118 2005-01-03 devnull as a prerequisite to be up to date,
407 058b0118 2005-01-03 devnull is considered up to date.
408 058b0118 2005-01-03 devnull Otherwise,
410 058b0118 2005-01-03 devnull is made in the normal fashion.
413 058b0118 2005-01-03 devnull flag overrides this special treatment.
415 058b0118 2005-01-03 devnull Files may be made in any order that respects
416 058b0118 2005-01-03 devnull the preceding restrictions.
418 058b0118 2005-01-03 devnull A recipe is executed by supplying the recipe as standard input to
419 058b0118 2005-01-03 devnull the command
420 058b0118 2005-01-03 devnull .BR /bin/sh .
421 058b0118 2005-01-03 devnull (Note that unlike
422 058b0118 2005-01-03 devnull .IR make ,
424 058b0118 2005-01-03 devnull feeds the entire recipe to the shell rather than running each line
425 058b0118 2005-01-03 devnull of the recipe separately.)
426 058b0118 2005-01-03 devnull The environment is augmented by the following variables:
428 058b0118 2005-01-03 devnull .B $alltarget
429 058b0118 2005-01-03 devnull all the targets of this rule.
431 058b0118 2005-01-03 devnull .B $newprereq
432 058b0118 2005-01-03 devnull the prerequisites that caused this rule to execute.
434 058b0118 2005-01-03 devnull .B $newmember
435 058b0118 2005-01-03 devnull the prerequisites that are members of an aggregate
436 058b0118 2005-01-03 devnull that caused this rule to execute.
437 058b0118 2005-01-03 devnull When the prerequisites of a rule are members of an
438 058b0118 2005-01-03 devnull aggregate,
439 058b0118 2005-01-03 devnull .B $newprereq
440 058b0118 2005-01-03 devnull contains the name of the aggregate and out of date
441 058b0118 2005-01-03 devnull members, while
442 058b0118 2005-01-03 devnull .B $newmember
443 058b0118 2005-01-03 devnull contains only the name of the members.
445 058b0118 2005-01-03 devnull .B $nproc
446 058b0118 2005-01-03 devnull the process slot for this recipe.
447 058b0118 2005-01-03 devnull It satisfies
448 058b0118 2005-01-03 devnull .RB 0≤ $nproc < $NPROC .
451 058b0118 2005-01-03 devnull the process id for the
453 058b0118 2005-01-03 devnull executing the recipe.
455 058b0118 2005-01-03 devnull .B $prereq
456 058b0118 2005-01-03 devnull all the prerequisites for this rule.
458 058b0118 2005-01-03 devnull .B $stem
459 058b0118 2005-01-03 devnull if this is a meta-rule,
460 058b0118 2005-01-03 devnull .B $stem
461 058b0118 2005-01-03 devnull is the string that matched
465 058b0118 2005-01-03 devnull Otherwise, it is empty.
466 058b0118 2005-01-03 devnull For regular expression meta-rules (see below), the variables
467 058b0118 2005-01-03 devnull .LR stem0 ", ...,"
468 058b0118 2005-01-03 devnull .L stem9
469 058b0118 2005-01-03 devnull are set to the corresponding subexpressions.
471 058b0118 2005-01-03 devnull .B $target
472 058b0118 2005-01-03 devnull the targets for this rule that need to be remade.
474 058b0118 2005-01-03 devnull These variables are available only during the execution of a recipe,
475 058b0118 2005-01-03 devnull not while evaluating the
476 058b0118 2005-01-03 devnull .IR mkfile .
478 058b0118 2005-01-03 devnull Unless the rule has the
480 058b0118 2005-01-03 devnull attribute,
481 058b0118 2005-01-03 devnull the recipe is printed prior to execution
482 058b0118 2005-01-03 devnull with recognizable environment variables expanded.
483 058b0118 2005-01-03 devnull Commands returning error status
486 058b0118 2005-01-03 devnull to terminate.
488 058b0118 2005-01-03 devnull Recipes and backquoted
490 058b0118 2005-01-03 devnull commands in places such as assignments
491 058b0118 2005-01-03 devnull execute in a copy of
493 058b0118 2005-01-03 devnull environment; changes they make to
494 058b0118 2005-01-03 devnull environment variables are not visible from
495 058b0118 2005-01-03 devnull .IR mk .
497 058b0118 2005-01-03 devnull Variable substitution in a rule is done when
498 058b0118 2005-01-03 devnull the rule is read; variable substitution in the recipe is done
499 058b0118 2005-01-03 devnull when the recipe is executed. For example:
503 058b0118 2005-01-03 devnull foo: $bar
504 058b0118 2005-01-03 devnull $CC -o foo $bar
508 058b0118 2005-01-03 devnull will compile
511 058b0118 2005-01-03 devnull .BR foo ,
514 058b0118 2005-01-03 devnull is newer than
515 058b0118 2005-01-03 devnull .BR foo .
516 058b0118 2005-01-03 devnull .SS Aggregates
517 058b0118 2005-01-03 devnull Names of the form
518 058b0118 2005-01-03 devnull .IR a ( b )
519 058b0118 2005-01-03 devnull refer to member
521 058b0118 2005-01-03 devnull of the aggregate
523 058b0118 2005-01-03 devnull Currently, the only aggregates supported are
526 058b0118 2005-01-03 devnull .IR 9c (1))
527 058b0118 2005-01-03 devnull archives.
528 058b0118 2005-01-03 devnull .SS Attributes
529 058b0118 2005-01-03 devnull The colon separating the target from the prerequisites
531 058b0118 2005-01-03 devnull immediately followed by
532 058b0118 2005-01-03 devnull .I attributes
533 058b0118 2005-01-03 devnull and another colon.
534 058b0118 2005-01-03 devnull The attributes are:
537 058b0118 2005-01-03 devnull If the recipe exits with a non-null status, the target is deleted.
540 058b0118 2005-01-03 devnull Continue execution if the recipe draws errors.
543 058b0118 2005-01-03 devnull If there is no recipe, the target has its time updated.
546 058b0118 2005-01-03 devnull The rule is a meta-rule that cannot be a target of a virtual rule.
547 058b0118 2005-01-03 devnull Only files match the pattern in the target.
550 058b0118 2005-01-03 devnull The characters after the
552 058b0118 2005-01-03 devnull until the terminating
554 058b0118 2005-01-03 devnull are taken as a program name.
555 058b0118 2005-01-03 devnull It will be invoked as
556 058b0118 2005-01-03 devnull .B "sh -c prog 'arg1' 'arg2'"
557 058b0118 2005-01-03 devnull and should return a zero exit status
558 058b0118 2005-01-03 devnull if and only if arg1 is up to date with respect to arg2.
559 058b0118 2005-01-03 devnull Date stamps are still propagated in the normal way.
562 058b0118 2005-01-03 devnull The recipe is not printed prior to execution.
565 058b0118 2005-01-03 devnull The rule is a meta-rule using regular expressions.
566 058b0118 2005-01-03 devnull In the rule,
568 058b0118 2005-01-03 devnull has no special meaning.
569 058b0118 2005-01-03 devnull The target is interpreted as a regular expression as defined in
570 058b0118 2005-01-03 devnull .IR regexp (7).
571 058b0118 2005-01-03 devnull The prerequisites may contain references
572 058b0118 2005-01-03 devnull to subexpressions in form
573 058b0118 2005-01-03 devnull .BI \e n\f1,
574 058b0118 2005-01-03 devnull as in the substitute command of
575 058b0118 2005-01-03 devnull .IR sed (1).
578 058b0118 2005-01-03 devnull The targets are considered to have been updated
579 058b0118 2005-01-03 devnull even if the recipe did not do so.
582 058b0118 2005-01-03 devnull The targets of this rule are marked as virtual.
583 058b0118 2005-01-03 devnull They are distinct from files of the same name.
585 058b0118 2005-01-03 devnull .SH EXAMPLES
586 058b0118 2005-01-03 devnull A simple mkfile to compile a program:
589 058b0118 2005-01-03 devnull .ta 8n +8n +8n +8n +8n +8n +8n
590 058b0118 2005-01-03 devnull </$objtype/mkfile
592 058b0118 2005-01-03 devnull prog: a.$O b.$O c.$O
593 058b0118 2005-01-03 devnull $LD $LDFLAGS -o $target $prereq
595 058b0118 2005-01-03 devnull %.$O: %.c
596 058b0118 2005-01-03 devnull $CC $CFLAGS $stem.c
599 058b0118 2005-01-03 devnull Override flag settings in the mkfile:
602 058b0118 2005-01-03 devnull % mk target 'CFLAGS=-S -w'
605 058b0118 2005-01-03 devnull Maintain a library:
608 058b0118 2005-01-03 devnull libc.a(%.$O):N: %.$O
609 058b0118 2005-01-03 devnull libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
610 058b0118 2005-01-03 devnull ar r libc.a $newmember
613 058b0118 2005-01-03 devnull String expression variables to derive names from a master list:
616 058b0118 2005-01-03 devnull NAMES=alloc arc bquote builtins expand main match mk var word
617 058b0118 2005-01-03 devnull OBJ=${NAMES:%=%.$O}
620 058b0118 2005-01-03 devnull Regular expression meta-rules:
623 058b0118 2005-01-03 devnull ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
624 058b0118 2005-01-03 devnull cd $stem1; $CC $CFLAGS $stem2.c
627 058b0118 2005-01-03 devnull A correct way to deal with
628 058b0118 2005-01-03 devnull .IR yacc (1)
629 058b0118 2005-01-03 devnull grammars.
630 058b0118 2005-01-03 devnull The file
631 058b0118 2005-01-03 devnull .B lex.c
632 058b0118 2005-01-03 devnull includes the file
633 058b0118 2005-01-03 devnull .B x.tab.h
634 058b0118 2005-01-03 devnull rather than
635 058b0118 2005-01-03 devnull .B y.tab.h
636 058b0118 2005-01-03 devnull in order to reflect changes in content, not just modification time.
639 058b0118 2005-01-03 devnull lex.$O: x.tab.h
640 058b0118 2005-01-03 devnull x.tab.h: y.tab.h
641 058b0118 2005-01-03 devnull cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
642 058b0118 2005-01-03 devnull y.tab.c y.tab.h: gram.y
643 058b0118 2005-01-03 devnull $YACC -d gram.y
646 058b0118 2005-01-03 devnull The above example could also use the
648 058b0118 2005-01-03 devnull attribute for the
649 058b0118 2005-01-03 devnull .B x.tab.h
653 058b0118 2005-01-03 devnull x.tab.h:Pcmp -s: y.tab.h
654 058b0118 2005-01-03 devnull cp y.tab.h x.tab.h
656 93aa30a8 2005-01-14 devnull .SH SOURCE
657 adc93f60 2005-01-14 devnull .B \*9/src/cmd/mk
658 058b0118 2005-01-03 devnull .SH SEE ALSO
659 058b0118 2005-01-03 devnull .IR sh (1),
660 c8b6342d 2005-01-13 devnull .IR regexp (7)
662 058b0118 2005-01-03 devnull A. Hume,
663 058b0118 2005-01-03 devnull ``Mk: a Successor to Make''
664 058b0118 2005-01-03 devnull (Tenth Edition Research Unix Manuals).
666 058b0118 2005-01-03 devnull Andrew G. Hume and Bob Flandrena,
667 058b0118 2005-01-03 devnull ``Maintaining Files on Plan 9 with Mk''.
668 058b0118 2005-01-03 devnull DOCPREFIX/doc/mk.pdf
669 058b0118 2005-01-03 devnull .SH HISTORY
670 058b0118 2005-01-03 devnull Andrew Hume wrote
672 058b0118 2005-01-03 devnull for Tenth Edition Research Unix.
673 058b0118 2005-01-03 devnull It was later ported to Plan 9.
674 058b0118 2005-01-03 devnull This software is a port of the Plan 9 version back to Unix.
675 058b0118 2005-01-03 devnull .SH BUGS
676 058b0118 2005-01-03 devnull Identical recipes for regular expression meta-rules only have one target.
678 058b0118 2005-01-03 devnull Seemingly appropriate input like
679 058b0118 2005-01-03 devnull .B CFLAGS=-DHZ=60
680 058b0118 2005-01-03 devnull is parsed as an erroneous attribute; correct it by inserting
681 058b0118 2005-01-03 devnull a space after the first
684 058b0118 2005-01-03 devnull The recipes printed by
686 058b0118 2005-01-03 devnull before being passed to
687 c8b6342d 2005-01-13 devnull the shell
688 058b0118 2005-01-03 devnull for execution are sometimes erroneously expanded
689 058b0118 2005-01-03 devnull for printing. Don't trust what's printed; rely
690 c8b6342d 2005-01-13 devnull on what the shell