12 .if n .RB ` \\$1 '\\$2
20 mk, membername \- maintain (make) related files
39 uses the dependency rules specified in
41 to control the update (usually by compilation) of
44 from the source files upon which they depend.
51 for each target that identifies the files and other
52 targets upon which it depends and an
57 The script is run if the target does not exist
58 or if it is older than any of the files it depends on.
62 that define actions for updating implicit targets.
65 is specified, the target of the first rule (not meta-rule) in
69 The environment variable
71 determines how many targets may be updated simultaneously;
72 Some operating systems, e.g., Plan 9, set
74 automatically to the number of CPUs on the current machine.
79 Assume all targets to be out of date.
80 Thus, everything is updated.
84 Produce debugging output
93 Explain why each target is made.
96 Force any missing intermediate targets to be made.
99 Do as much work as possible in the face of errors.
102 Print, but do not execute, the commands
103 needed to update the targets.
106 Make the command line arguments sequentially rather than in parallel.
109 Touch (update the modified date of) file targets, without
110 executing any recipes.
112 .BI -w target1 , target2,...
113 Pretend the modify time for each
115 is the current time; useful in conjunction with
117 to learn what updates would be triggered by
126 (described under `Environment') and
132 A target is a literal string
133 and is normally a file name.
134 The tail contains zero or more
141 Each line of the recipe must begin with white space.
142 A rule takes the form
145 target: prereq1 prereq2
146 \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
149 When the recipe is executed,
150 the first character on every line is elided.
152 After the colon on the target line, a rule may specify
158 has a target of the form
164 are (possibly empty) strings.
165 A meta-rule acts as a rule for any potential target whose
170 replaced by an arbitrary string, called the
172 In interpreting a meta-rule,
173 the stem is substituted for all occurrences of
175 in the prerequisite names.
176 In the recipe of a meta-rule, the environment variable
178 contains the string matched by the
180 For example, a meta-rule to compile a C program using
190 Meta-rules may contain an ampersand
192 rather than a percent sign
196 matches a maximal length string of any characters;
199 matches a maximal length string of any characters except period
204 is processed as follows.
207 followed by a file name are replaced by the contents of the named
211 followed by a file name are replaced by the output
212 of the execution of the named
214 Blank lines and comments, which run from unquoted
216 characters to the following newline, are deleted.
217 The character sequence backslash-newline is deleted,
221 Non-recipe lines are processed by substituting for
227 References to variables are replaced by the variables' values.
228 Special characters may be quoted using single quotes
233 Assignments and rules are distinguished by
234 the first unquoted occurrence of
241 A later rule may modify or override an existing rule under the
242 following conditions:
245 If the targets of the rules exactly match and one rule
246 contains only a prerequisite clause and no recipe, the
247 clause is added to the prerequisites of the other rule.
248 If either or both targets are virtual, the recipe is
252 If the targets of the rules match exactly and the
253 prerequisites do not match and both rules
256 reports an ``ambiguous recipe'' error.
259 If the target and prerequisites of both rules match exactly,
260 the second rule overrides the first.
262 Rules may make use of
264 environment variables.
265 A legal reference of the form
271 A reference of the form
272 .BI ${name: A % B = C\fL%\fID\fL}\fR,
275 are (possibly empty) strings,
276 has the value formed by expanding
291 Variables can be set by
292 assignments of the form
294 var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
299 Such variables are exported
300 to the environment of
301 recipes as they are executed, unless
303 the only legal attribute
306 The initial value of a variable is
307 taken from (in increasing order of precedence)
308 the default values below,
312 and any command line assignment as an argument to
314 A variable assignment argument overrides the first (but not any subsequent)
315 assignment to that variable.
318 contains all the option arguments (arguments starting with
324 contains all the targets in the call to
327 Dynamic information may be included in the mkfile by using a line of the form
329 \fR<|\fIcommand\fR \fIargs\fR
331 This runs the command
333 with the given arguments
335 and pipes its standard output to
337 to be included as part of the mkfile. For instance, the Inferno kernels
339 to run a shell command with an awk script and a configuration
340 file as arguments in order for
343 script to process the file and output a set of variables and their values.
348 determines which targets must be updated, and in what order,
351 specified on the command line.
352 It then runs the associated recipes.
354 A target is considered up to date if it has no prerequisites or
355 if all its prerequisites are up to date and it is newer
356 than all its prerequisites.
357 Once the recipe for a target has executed, the target is
358 considered up to date.
361 used to determine if a target is up to date is computed
362 differently for different types of targets.
365 (the target of a rule with the
368 its date stamp is initially zero; when the target is
369 updated the date stamp is set to
370 the most recent date stamp of its prerequisites.
371 Otherwise, if a target does not exist as a file,
372 its date stamp is set to the most recent date stamp of its prerequisites,
373 or zero if it has no prerequisites.
374 Otherwise, the target is the name of a file and
375 the target's date stamp is always that file's modification date.
376 The date stamp is computed when the target is needed in
377 the execution of a rule; it is not a static value.
379 Nonexistent targets that have prerequisites
380 and are themselves prerequisites are treated specially.
383 is given the date stamp of its most recent prerequisite
384 and if this causes all the targets which have
386 as a prerequisite to be up to date,
388 is considered up to date.
391 is made in the normal fashion.
394 flag overrides this special treatment.
396 Files may be made in any order that respects
397 the preceding restrictions.
399 A recipe is executed by supplying the recipe as standard input to
405 feeds the entire recipe to the shell rather than running each line
406 of the recipe separately.)
407 The environment is augmented by the following variables:
410 all the targets of this rule.
413 the prerequisites that caused this rule to execute.
416 the prerequisites that are members of an aggregate
417 that caused this rule to execute.
418 When the prerequisites of a rule are members of an
421 contains the name of the aggregate and out of date
424 contains only the name of the members.
427 the process slot for this recipe.
429 .RB 0≤ $nproc < $NPROC .
432 the process id for the
434 executing the recipe.
437 all the prerequisites for this rule.
440 if this is a meta-rule,
442 is the string that matched
446 Otherwise, it is empty.
447 For regular expression meta-rules (see below), the variables
450 are set to the corresponding subexpressions.
453 the targets for this rule that need to be remade.
455 These variables are available only during the execution of a recipe,
456 not while evaluating the
459 Unless the rule has the
462 the recipe is printed prior to execution
463 with recognizable environment variables expanded.
464 Commands returning error status
469 Recipes and backquoted
471 commands in places such as assignments
474 environment; changes they make to
475 environment variables are not visible from
478 Variable substitution in a rule is done when
479 the rule is read; variable substitution in the recipe is done
480 when the recipe is executed. For example:
504 Currently, the only aggregates supported are
511 echoes just the member names of a list of aggregate names.
512 It is useful in recipes like:
516 libc.a: ${OFILES:%=libc.a(%)}
517 9ar rvc libc.a `membername $newprereq`
519 which re-archives only the new object files.
521 The colon separating the target from the prerequisites
523 immediately followed by
529 If the recipe exits with a non-null status, the target is deleted.
532 Continue execution if the recipe draws errors.
535 If there is no recipe, the target has its time updated.
538 The rule is a meta-rule that cannot be a target of a virtual rule.
539 Only files match the pattern in the target.
542 The characters after the
544 until the terminating
546 are taken as a program name.
547 It will be invoked as
548 .B "sh -c prog 'arg1' 'arg2'"
549 and should return a zero exit status
550 if and only if arg1 is up to date with respect to arg2.
551 Date stamps are still propagated in the normal way.
554 The recipe is not printed prior to execution.
557 The rule is a meta-rule using regular expressions.
560 has no special meaning.
561 The target is interpreted as a regular expression as defined in
563 The prerequisites may contain references
564 to subexpressions in form
566 as in the substitute command of
570 The targets are considered to have been updated
571 even if the recipe did not do so.
574 The targets of this rule are marked as virtual.
575 They are distinct from files of the same name.
578 A simple mkfile to compile a program:
581 .ta 8n +8n +8n +8n +8n +8n +8n
585 $LD $LDFLAGS -o $target $prereq
591 Override flag settings in the mkfile:
594 % mk target 'CFLAGS=-S -w'
601 libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
602 ar r libc.a $newmember
605 String expression variables to derive names from a master list:
608 NAMES=alloc arc bquote builtins expand main match mk var word
612 Regular expression meta-rules:
615 ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
616 cd $stem1; $CC $CFLAGS $stem2.c
619 A correct way to deal with
628 in order to reflect changes in content, not just modification time.
633 cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
634 y.tab.c y.tab.h: gram.y
638 The above example could also use the
645 x.tab.h:Pcmp -s: y.tab.h
653 ``Mk: a Successor to Make''
654 (Tenth Edition Research Unix Manuals).
656 Andrew G. Hume and Bob Flandrena,
657 ``Maintaining Files on Plan 9 with Mk''.
662 for Tenth Edition Research Unix.
663 It was later ported to Plan 9.
664 This software is a port of the Plan 9 version back to Unix.
666 Identical recipes for regular expression meta-rules only have one target.
668 Seemingly appropriate input like
670 is parsed as an erroneous attribute; correct it by inserting
671 a space after the first
674 The recipes printed by
676 before being passed to
678 for execution are sometimes erroneously expanded
679 for printing. Don't trust what's printed; rely