3
mk \- maintain (make) related files
18
uses the dependency rules specified in
20
to control the update (usually by compilation) of
23
from the source files upon which they depend.
30
for each target that identifies the files and other
31
targets upon which it depends and an
36
The script is run if the target does not exist
37
or if it is older than any of the files it depends on.
41
that define actions for updating implicit targets.
44
is specified, the target of the first rule (not meta-rule) in
48
The environment variable
50
determines how many targets may be updated simultaneously;
51
Some operating systems, e.g., Plan 9, set
53
automatically to the number of CPUs on the current machine.
58
Assume all targets to be out of date.
59
Thus, everything is updated.
63
Produce debugging output
72
Explain why each target is made.
75
Force any missing intermediate targets to be made.
78
Do as much work as possible in the face of errors.
81
Print, but do not execute, the commands
82
needed to update the targets.
85
Make the command line arguments sequentially rather than in parallel.
88
Touch (update the modified date of) file targets, without
89
executing any recipes.
91
.BI -w target1 , target2,...
92
Pretend the modify time for each
94
is the current time; useful in conjunction with
96
to learn what updates would be triggered by
105
(described under `Environment') and
111
A target is a literal string
112
and is normally a file name.
113
The tail contains zero or more
120
Each line of the recipe must begin with white space.
121
A rule takes the form
124
target: prereq1 prereq2
125
\f2recipe using\fP prereq1, prereq2 \f2to build\fP target
128
When the recipe is executed,
129
the first character on every line is elided.
131
After the colon on the target line, a rule may specify
137
has a target of the form
143
are (possibly empty) strings.
144
A meta-rule acts as a rule for any potential target whose
149
replaced by an arbitrary string, called the
151
In interpreting a meta-rule,
152
the stem is substituted for all occurrences of
154
in the prerequisite names.
155
In the recipe of a meta-rule, the environment variable
157
contains the string matched by the
159
For example, a meta-rule to compile a C program using
169
Meta-rules may contain an ampersand
171
rather than a percent sign
175
matches a maximal length string of any characters;
178
matches a maximal length string of any characters except period
183
is processed as follows.
186
followed by a file name are replaced by the contents of the named
190
followed by a file name are replaced by the output
191
of the execution of the named
193
Blank lines and comments, which run from unquoted
195
characters to the following newline, are deleted.
196
The character sequence backslash-newline is deleted,
200
Non-recipe lines are processed by substituting for
206
References to variables are replaced by the variables' values.
207
Special characters may be quoted using single quotes
212
Assignments and rules are distinguished by
213
the first unquoted occurrence of
220
A later rule may modify or override an existing rule under the
221
following conditions:
224
If the targets of the rules exactly match and one rule
225
contains only a prerequisite clause and no recipe, the
226
clause is added to the prerequisites of the other rule.
227
If either or both targets are virtual, the recipe is
231
If the targets of the rules match exactly and the
232
prerequisites do not match and both rules
235
reports an ``ambiguous recipe'' error.
238
If the target and prerequisites of both rules match exactly,
239
the second rule overrides the first.
241
Rules may make use of
243
environment variables.
244
A legal reference of the form
250
A reference of the form
251
.BI ${name: A % B = C\fL%\fID\fL}\fR,
254
are (possibly empty) strings,
255
has the value formed by expanding
270
Variables can be set by
271
assignments of the form
273
var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
278
Such variables are exported
279
to the environment of
280
recipes as they are executed, unless
282
the only legal attribute
285
The initial value of a variable is
286
taken from (in increasing order of precedence)
287
the default values below,
291
and any command line assignment as an argument to
293
A variable assignment argument overrides the first (but not any subsequent)
294
assignment to that variable.
298
contains all the option arguments (arguments starting with
304
contains all the targets in the call to
309
contains the shell command line
312
If the first word of the command ends in
319
quoting rules; otherwise it uses
323
variable is consulted when the mkfile is read, not when it is executed,
324
so that different shells can be used within a single mkfile:
327
MKSHELL=$PLAN9/bin/rc
329
for(i in a b c) echo $i
333
for i in a b c; do echo $i; done
341
see their own private copy of
343
which always starts set to
346
Dynamic information may be included in the mkfile by using a line of the form
348
\fR<|\fIcommand\fR \fIargs\fR
350
This runs the command
352
with the given arguments
354
and pipes its standard output to
356
to be included as part of the mkfile. For instance, the Inferno kernels
358
to run a shell command with an awk script and a configuration
359
file as arguments in order for
362
script to process the file and output a set of variables and their values.
367
determines which targets must be updated, and in what order,
370
specified on the command line.
371
It then runs the associated recipes.
373
A target is considered up to date if it has no prerequisites or
374
if all its prerequisites are up to date and it is newer
375
than all its prerequisites.
376
Once the recipe for a target has executed, the target is
377
considered up to date.
380
used to determine if a target is up to date is computed
381
differently for different types of targets.
384
(the target of a rule with the
387
its date stamp is initially zero; when the target is
388
updated the date stamp is set to
389
the most recent date stamp of its prerequisites.
390
Otherwise, if a target does not exist as a file,
391
its date stamp is set to the most recent date stamp of its prerequisites,
392
or zero if it has no prerequisites.
393
Otherwise, the target is the name of a file and
394
the target's date stamp is always that file's modification date.
395
The date stamp is computed when the target is needed in
396
the execution of a rule; it is not a static value.
398
Nonexistent targets that have prerequisites
399
and are themselves prerequisites are treated specially.
402
is given the date stamp of its most recent prerequisite
403
and if this causes all the targets which have
405
as a prerequisite to be up to date,
407
is considered up to date.
410
is made in the normal fashion.
413
flag overrides this special treatment.
415
Files may be made in any order that respects
416
the preceding restrictions.
418
A recipe is executed by supplying the recipe as standard input to
424
feeds the entire recipe to the shell rather than running each line
425
of the recipe separately.)
426
The environment is augmented by the following variables:
429
all the targets of this rule.
432
the prerequisites that caused this rule to execute.
435
the prerequisites that are members of an aggregate
436
that caused this rule to execute.
437
When the prerequisites of a rule are members of an
440
contains the name of the aggregate and out of date
443
contains only the name of the members.
446
the process slot for this recipe.
448
.RB 0≤ $nproc < $NPROC .
451
the process id for the
453
executing the recipe.
456
all the prerequisites for this rule.
459
if this is a meta-rule,
461
is the string that matched
465
Otherwise, it is empty.
466
For regular expression meta-rules (see below), the variables
469
are set to the corresponding subexpressions.
472
the targets for this rule that need to be remade.
474
These variables are available only during the execution of a recipe,
475
not while evaluating the
478
Unless the rule has the
481
the recipe is printed prior to execution
482
with recognizable environment variables expanded.
483
Commands returning error status
488
Recipes and backquoted
490
commands in places such as assignments
493
environment; changes they make to
494
environment variables are not visible from
497
Variable substitution in a rule is done when
498
the rule is read; variable substitution in the recipe is done
499
when the recipe is executed. For example:
523
Currently, the only aggregates supported are
529
The colon separating the target from the prerequisites
531
immediately followed by
537
If the recipe exits with a non-null status, the target is deleted.
540
Continue execution if the recipe draws errors.
543
If there is no recipe, the target has its time updated.
546
The rule is a meta-rule that cannot be a target of a virtual rule.
547
Only files match the pattern in the target.
550
The characters after the
552
until the terminating
554
are taken as a program name.
555
It will be invoked as
556
.B "sh -c prog 'arg1' 'arg2'"
557
and should return a zero exit status
558
if and only if arg1 is up to date with respect to arg2.
559
Date stamps are still propagated in the normal way.
562
The recipe is not printed prior to execution.
565
The rule is a meta-rule using regular expressions.
568
has no special meaning.
569
The target is interpreted as a regular expression as defined in
571
The prerequisites may contain references
572
to subexpressions in form
574
as in the substitute command of
578
The targets are considered to have been updated
579
even if the recipe did not do so.
582
The targets of this rule are marked as virtual.
583
They are distinct from files of the same name.
586
A simple mkfile to compile a program:
589
.ta 8n +8n +8n +8n +8n +8n +8n
593
$LD $LDFLAGS -o $target $prereq
599
Override flag settings in the mkfile:
602
% mk target 'CFLAGS=-S -w'
609
libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
610
ar r libc.a $newmember
613
String expression variables to derive names from a master list:
616
NAMES=alloc arc bquote builtins expand main match mk var word
620
Regular expression meta-rules:
623
([^/]*)/(.*)\e.$O:R: \e1/\e2.c
624
cd $stem1; $CC $CFLAGS $stem2.c
627
A correct way to deal with
636
in order to reflect changes in content, not just modification time.
641
cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
642
y.tab.c y.tab.h: gram.y
646
The above example could also use the
653
x.tab.h:Pcmp -s: y.tab.h
663
``Mk: a Successor to Make''
664
(Tenth Edition Research Unix Manuals).
666
Andrew G. Hume and Bob Flandrena,
667
``Maintaining Files on Plan 9 with Mk''.
672
for Tenth Edition Research Unix.
673
It was later ported to Plan 9.
674
This software is a port of the Plan 9 version back to Unix.
676
Identical recipes for regular expression meta-rules only have one target.
678
Seemingly appropriate input like
680
is parsed as an erroneous attribute; correct it by inserting
681
a space after the first
684
The recipes printed by
686
before being passed to
688
for execution are sometimes erroneously expanded
689
for printing. Don't trust what's printed; rely