12 .if n .RB ` \\$1 '\\$2
20 mk \- maintain (make) related files
35 uses the dependency rules specified in
37 to control the update (usually by compilation) of
40 from the source files upon which they depend.
47 for each target that identifies the files and other
48 targets upon which it depends and an
53 The script is run if the target does not exist
54 or if it is older than any of the files it depends on.
58 that define actions for updating implicit targets.
61 is specified, the target of the first rule (not meta-rule) in
65 The environment variable
67 determines how many targets may be updated simultaneously;
68 Some operating systems, e.g., Plan 9, set
70 automatically to the number of CPUs on the current machine.
75 Assume all targets to be out of date.
76 Thus, everything is updated.
80 Produce debugging output
89 Explain why each target is made.
92 Force any missing intermediate targets to be made.
95 Do as much work as possible in the face of errors.
98 Print, but do not execute, the commands
99 needed to update the targets.
102 Make the command line arguments sequentially rather than in parallel.
105 Touch (update the modified date of) file targets, without
106 executing any recipes.
108 .BI -w target1 , target2,...
109 Pretend the modify time for each
111 is the current time; useful in conjunction with
113 to learn what updates would be triggered by
122 (described under `Environment') and
128 A target is a literal string
129 and is normally a file name.
130 The tail contains zero or more
137 Each line of the recipe must begin with white space.
138 A rule takes the form
141 target: prereq1 prereq2
142 \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
145 When the recipe is executed,
146 the first character on every line is elided.
148 After the colon on the target line, a rule may specify
154 has a target of the form
160 are (possibly empty) strings.
161 A meta-rule acts as a rule for any potential target whose
166 replaced by an arbitrary string, called the
168 In interpreting a meta-rule,
169 the stem is substituted for all occurrences of
171 in the prerequisite names.
172 In the recipe of a meta-rule, the environment variable
174 contains the string matched by the
176 For example, a meta-rule to compile a C program using
186 Meta-rules may contain an ampersand
188 rather than a percent sign
192 matches a maximal length string of any characters;
195 matches a maximal length string of any characters except period
200 is processed as follows.
203 followed by a file name are replaced by the contents of the named
207 followed by a file name are replaced by the output
208 of the execution of the named
210 Blank lines and comments, which run from unquoted
212 characters to the following newline, are deleted.
213 The character sequence backslash-newline is deleted,
217 Non-recipe lines are processed by substituting for
223 References to variables are replaced by the variables' values.
224 Special characters may be quoted using single quotes
229 Assignments and rules are distinguished by
230 the first unquoted occurrence of
237 A later rule may modify or override an existing rule under the
238 following conditions:
241 If the targets of the rules exactly match and one rule
242 contains only a prerequisite clause and no recipe, the
243 clause is added to the prerequisites of the other rule.
244 If either or both targets are virtual, the recipe is
248 If the targets of the rules match exactly and the
249 prerequisites do not match and both rules
252 reports an ``ambiguous recipe'' error.
255 If the target and prerequisites of both rules match exactly,
256 the second rule overrides the first.
258 Rules may make use of
260 environment variables.
261 A legal reference of the form
267 A reference of the form
268 .BI ${name: A % B = C\fL%\fID\fL}\fR,
271 are (possibly empty) strings,
272 has the value formed by expanding
287 Variables can be set by
288 assignments of the form
290 var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
295 Such variables are exported
296 to the environment of
297 recipes as they are executed, unless
299 the only legal attribute
302 The initial value of a variable is
303 taken from (in increasing order of precedence)
304 the default values below,
308 and any command line assignment as an argument to
310 A variable assignment argument overrides the first (but not any subsequent)
311 assignment to that variable.
314 contains all the option arguments (arguments starting with
320 contains all the targets in the call to
323 Dynamic information may be included in the mkfile by using a line of the form
325 \fR<|\fIcommand\fR \fIargs\fR
327 This runs the command
329 with the given arguments
331 and pipes its standard output to
333 to be included as part of the mkfile. For instance, the Inferno kernels
335 to run a shell command with an awk script and a configuration
336 file as arguments in order for
339 script to process the file and output a set of variables and their values.
344 determines which targets must be updated, and in what order,
347 specified on the command line.
348 It then runs the associated recipes.
350 A target is considered up to date if it has no prerequisites or
351 if all its prerequisites are up to date and it is newer
352 than all its prerequisites.
353 Once the recipe for a target has executed, the target is
354 considered up to date.
357 used to determine if a target is up to date is computed
358 differently for different types of targets.
361 (the target of a rule with the
364 its date stamp is initially zero; when the target is
365 updated the date stamp is set to
366 the most recent date stamp of its prerequisites.
367 Otherwise, if a target does not exist as a file,
368 its date stamp is set to the most recent date stamp of its prerequisites,
369 or zero if it has no prerequisites.
370 Otherwise, the target is the name of a file and
371 the target's date stamp is always that file's modification date.
372 The date stamp is computed when the target is needed in
373 the execution of a rule; it is not a static value.
375 Nonexistent targets that have prerequisites
376 and are themselves prerequisites are treated specially.
379 is given the date stamp of its most recent prerequisite
380 and if this causes all the targets which have
382 as a prerequisite to be up to date,
384 is considered up to date.
387 is made in the normal fashion.
390 flag overrides this special treatment.
392 Files may be made in any order that respects
393 the preceding restrictions.
395 A recipe is executed by supplying the recipe as standard input to
401 feeds the entire recipe to the shell rather than running each line
402 of the recipe separately.)
403 The environment is augmented by the following variables:
406 all the targets of this rule.
409 the prerequisites that caused this rule to execute.
412 the prerequisites that are members of an aggregate
413 that caused this rule to execute.
414 When the prerequisites of a rule are members of an
417 contains the name of the aggregate and out of date
420 contains only the name of the members.
423 the process slot for this recipe.
425 .RB 0≤ $nproc < $NPROC .
428 the process id for the
430 executing the recipe.
433 all the prerequisites for this rule.
436 if this is a meta-rule,
438 is the string that matched
442 Otherwise, it is empty.
443 For regular expression meta-rules (see below), the variables
446 are set to the corresponding subexpressions.
449 the targets for this rule that need to be remade.
451 These variables are available only during the execution of a recipe,
452 not while evaluating the
455 Unless the rule has the
458 the recipe is printed prior to execution
459 with recognizable environment variables expanded.
460 Commands returning error status
465 Recipes and backquoted
467 commands in places such as assignments
470 environment; changes they make to
471 environment variables are not visible from
474 Variable substitution in a rule is done when
475 the rule is read; variable substitution in the recipe is done
476 when the recipe is executed. For example:
500 Currently, the only aggregates supported are
504 The colon separating the target from the prerequisites
506 immediately followed by
512 If the recipe exits with a non-null status, the target is deleted.
515 Continue execution if the recipe draws errors.
518 If there is no recipe, the target has its time updated.
521 The rule is a meta-rule that cannot be a target of a virtual rule.
522 Only files match the pattern in the target.
525 The characters after the
527 until the terminating
529 are taken as a program name.
530 It will be invoked as
531 .B "sh -c prog 'arg1' 'arg2'"
532 and should return a zero exit status
533 if and only if arg1 is up to date with respect to arg2.
534 Date stamps are still propagated in the normal way.
537 The recipe is not printed prior to execution.
540 The rule is a meta-rule using regular expressions.
543 has no special meaning.
544 The target is interpreted as a regular expression as defined in
546 The prerequisites may contain references
547 to subexpressions in form
549 as in the substitute command of
553 The targets are considered to have been updated
554 even if the recipe did not do so.
557 The targets of this rule are marked as virtual.
558 They are distinct from files of the same name.
561 A simple mkfile to compile a program:
564 .ta 8n +8n +8n +8n +8n +8n +8n
568 $LD $LDFLAGS -o $target $prereq
574 Override flag settings in the mkfile:
577 % mk target 'CFLAGS=-S -w'
584 libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
585 ar r libc.a $newmember
588 String expression variables to derive names from a master list:
591 NAMES=alloc arc bquote builtins expand main match mk var word
595 Regular expression meta-rules:
598 ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
599 cd $stem1; $CC $CFLAGS $stem2.c
602 A correct way to deal with
611 in order to reflect changes in content, not just modification time.
616 cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
617 y.tab.c y.tab.h: gram.y
621 The above example could also use the
628 x.tab.h:Pcmp -s: y.tab.h
636 ``Mk: a Successor to Make''
637 (Tenth Edition Research Unix Manuals).
639 Andrew G. Hume and Bob Flandrena,
640 ``Maintaining Files on Plan 9 with Mk''.
645 for Tenth Edition Research Unix.
646 It was later ported to Plan 9.
647 This software is a port of the Plan 9 version back to Unix.
649 Identical recipes for regular expression meta-rules only have one target.
651 Seemingly appropriate input like
653 is parsed as an erroneous attribute; correct it by inserting
654 a space after the first
657 The recipes printed by
659 before being passed to
661 for execution are sometimes erroneously expanded
662 for printing. Don't trust what's printed; rely