3 mk, membername \- maintain (make) related files
21 uses the dependency rules specified in
23 to control the update (usually by compilation) of
26 from the source files upon which they depend.
33 for each target that identifies the files and other
34 targets upon which it depends and an
39 The script is run if the target does not exist
40 or if it is older than any of the files it depends on.
44 that define actions for updating implicit targets.
47 is specified, the target of the first rule (not meta-rule) in
51 The environment variable
53 determines how many targets may be updated simultaneously;
56 automatically to the number of CPUs on the current machine.
61 Assume all targets to be out of date.
62 Thus, everything is updated.
66 Produce debugging output
75 Explain why each target is made.
78 Force any missing intermediate targets to be made.
81 Do as much work as possible in the face of errors.
84 Print, but do not execute, the commands
85 needed to update the targets.
88 Make the command line arguments sequentially rather than in parallel.
91 Touch (update the modified date of) file targets, without
92 executing any recipes.
94 .BI -w target1 , target2,...
95 Pretend the modify time for each
97 is the current time; useful in conjunction with
99 to learn what updates would be triggered by
108 extracts member names
109 (see `Aggregates' below)
116 (described under `Environment') and
122 A target is a literal string
123 and is normally a file name.
124 The tail contains zero or more
131 Each line of the recipe must begin with white space.
132 A rule takes the form
135 target: prereq1 prereq2
136 rc \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
139 When the recipe is executed,
140 the first character on every line is elided.
142 After the colon on the target line, a rule may specify
148 has a target of the form
154 are (possibly empty) strings.
155 A meta-rule acts as a rule for any potential target whose
160 replaced by an arbitrary string, called the
162 In interpreting a meta-rule,
163 the stem is substituted for all occurrences of
165 in the prerequisite names.
166 In the recipe of a meta-rule, the environment variable
168 contains the string matched by the
170 For example, a meta-rule to compile a C program using
180 Meta-rules may contain an ampersand
182 rather than a percent sign
186 matches a maximal length string of any characters;
189 matches a maximal length string of any characters except period
194 is processed as follows.
197 followed by a file name are replaced by the contents of the named
201 followed by a file name are replaced by the output
202 of the execution of the named
204 Blank lines and comments, which run from unquoted
206 characters to the following newline, are deleted.
207 The character sequence backslash-newline is deleted,
211 Non-recipe lines are processed by substituting for
217 References to variables are replaced by the variables' values.
218 Special characters may be quoted using single quotes
223 Assignments and rules are distinguished by
224 the first unquoted occurrence of
231 A later rule may modify or override an existing rule under the
232 following conditions:
235 If the targets of the rules exactly match and one rule
236 contains only a prerequisite clause and no recipe, the
237 clause is added to the prerequisites of the other rule.
238 If either or both targets are virtual, the recipe is
242 If the targets of the rules match exactly and the
243 prerequisites do not match and both rules
246 reports an ``ambiguous recipe'' error.
249 If the target and prerequisites of both rules match exactly,
250 the second rule overrides the first.
252 Rules may make use of
254 environment variables.
255 A legal reference of the form
259 A reference of the form
260 .BI ${name: A % B = C\fL%\fID\fL}\fR,
263 are (possibly empty) strings,
264 has the value formed by expanding
279 Variables can be set by
280 assignments of the form
282 var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
286 break it into words, as in
288 but without the surrounding parentheses.
289 Such variables are exported
290 to the environment of
291 recipes as they are executed, unless
293 the only legal attribute
296 The initial value of a variable is
297 taken from (in increasing order of precedence)
298 the default values below,
302 and any command line assignment as an argument to
304 A variable assignment argument overrides the first (but not any subsequent)
305 assignment to that variable.
309 contains all the option arguments (arguments starting with
315 contains all the targets in the call to
318 It is recommended that mkfiles start with
332 to values appropriate to the target architecture (see the examples below).
337 determines which targets must be updated, and in what order,
340 specified on the command line.
341 It then runs the associated recipes.
343 A target is considered up to date if it has no prerequisites or
344 if all its prerequisites are up to date and it is newer
345 than all its prerequisites.
346 Once the recipe for a target has executed, the target is
347 considered up to date.
350 used to determine if a target is up to date is computed
351 differently for different types of targets.
354 (the target of a rule with the
357 its date stamp is initially zero; when the target is
358 updated the date stamp is set to
359 the most recent date stamp of its prerequisites.
360 Otherwise, if a target does not exist as a file,
361 its date stamp is set to the most recent date stamp of its prerequisites,
362 or zero if it has no prerequisites.
363 Otherwise, the target is the name of a file and
364 the target's date stamp is always that file's modification date.
365 The date stamp is computed when the target is needed in
366 the execution of a rule; it is not a static value.
368 Nonexistent targets that have prerequisites
369 and are themselves prerequisites are treated specially.
372 is given the date stamp of its most recent prerequisite
373 and if this causes all the targets which have
375 as a prerequisite to be up to date,
377 is considered up to date.
380 is made in the normal fashion.
383 flag overrides this special treatment.
385 Files may be made in any order that respects
386 the preceding restrictions.
388 A recipe is executed by supplying the recipe as standard input to
398 The environment is augmented by the following variables:
401 all the targets of this rule.
404 the prerequisites that caused this rule to execute.
407 the prerequisites that are members of an aggregate
408 that caused this rule to execute.
409 When the prerequisites of a rule are members of an
412 contains the name of the aggregate and out of date
415 contains only the name of the members.
418 the process slot for this recipe.
420 .RB 0≤ $nproc < $NPROC .
423 the process id for the
425 executing the recipe.
428 all the prerequisites for this rule.
431 if this is a meta-rule,
433 is the string that matched
437 Otherwise, it is empty.
438 For regular expression meta-rules (see below), the variables
441 are set to the corresponding subexpressions.
444 the targets for this rule that need to be remade.
446 These variables are available only during the execution of a recipe,
447 not while evaluating the
450 Unless the rule has the
453 the recipe is printed prior to execution
454 with recognizable environment variables expanded.
455 Commands returning nonempty status (see
461 Recipes and backquoted
463 commands in places such as assignments
466 environment; changes they make to
467 environment variables are not visible from
470 Variable substitution in a rule is done when
471 the rule is read; variable substitution in the recipe is done
472 when the recipe is executed. For example:
496 Currently, the only aggregates supported are
500 The colon separating the target from the prerequisites
502 immediately followed by
508 If the recipe exits with a non-null status, the target is deleted.
511 Continue execution if the recipe draws errors.
514 If there is no recipe, the target has its time updated.
517 The rule is a meta-rule that cannot be a target of a virtual rule.
518 Only files match the pattern in the target.
521 The characters after the
523 until the terminating
525 are taken as a program name.
526 It will be invoked as
527 .B "rc -c prog 'arg1' 'arg2'"
528 and should return a null exit status
529 if and only if arg1 is up to date with respect to arg2.
530 Date stamps are still propagated in the normal way.
533 The recipe is not printed prior to execution.
536 The rule is a meta-rule using regular expressions.
539 has no special meaning.
540 The target is interpreted as a regular expression as defined in
542 The prerequisites may contain references
543 to subexpressions in form
545 as in the substitute command of
549 The targets are considered to have been updated
550 even if the recipe did not do so.
553 The targets of this rule are marked as virtual.
554 They are distinct from files of the same name.
557 A simple mkfile to compile a program:
560 .ta 8n +8n +8n +8n +8n +8n +8n
564 $LD $LDFLAGS -o $target $prereq
570 Override flag settings in the mkfile:
573 % mk target 'CFLAGS=-S -w'
580 libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
581 ar r libc.a $newmember
584 String expression variables to derive names from a master list:
587 NAMES=alloc arc bquote builtins expand main match mk var word
591 Regular expression meta-rules:
594 ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
595 cd $stem1; $CC $CFLAGS $stem2.c
598 A correct way to deal with
607 in order to reflect changes in content, not just modification time.
612 cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
613 y.tab.c y.tab.h: gram.y
617 The above example could also use the
624 x.tab.h:Pcmp -s: y.tab.h
634 ``Mk: a Successor to Make''.
636 Andrew G. Hume and Bob Flandrena,
637 ``Maintaining Files on Plan 9 with Mk''.
639 Identical recipes for regular expression meta-rules only have one target.
641 Seemingly appropriate input like
643 is parsed as an erroneous attribute; correct it by inserting
644 a space after the first
647 The recipes printed by
649 before being passed to
651 for execution are sometimes erroneously expanded
652 for printing. Don't trust what's printed; rely