The environment variable $NPROC determines how many targets may be updated simultaneously; Plan 9 sets $NPROC automatically to the number of CPUs on the current machine.
Options are:
target: prereq1 prereq2 rc recipe using prereq1, prereq2 to build target
When the recipe is executed, the first character on every line is elided.
After the colon on the target line, a rule may specify attributes, described below.
A meta-rule has a target of the form A%B where A and B are (possibly empty) strings. A meta-rule acts as a rule for any potential target whose name matches A%B with % replaced by an arbitrary string, called the stem. In interpreting a meta-rule, the stem is substituted for all occurrences of % in the prerequisite names. In the recipe of a meta-rule, the environment variable $stem contains the string matched by the %. For example, a meta-rule to compile a C program using 2c(10.1) might be:
%.2: %.c 2c $stem.c 2l -o $stem $stem.2
Meta-rules may contain an ampersand & rather than a percent sign %. A % matches a maximal length string of any characters; an & matches a maximal length string of any characters except period or slash.
The text of the mkfile is processed as follows. Lines beginning with < followed by a file name are replaced by the contents of the named file. Blank lines and comments, which run from unquoted # characters to the following newline, are deleted. The character sequence backslash-newline is deleted, so long lines in mkfile may be folded. Non-recipe lines are processed by substituting for `{command} the output of the command when run by rc. References to variables are replaced by the variables' values. Special characters may be quoted using single quotes '' as in rc(10.1).
Assignments and rules are distinguished by the first unquoted occurrence of : (rule) or = (assignment).
A later rule may modify or override an existing rule under the following conditions:
Variables can be set by
assignments of the form
var=[attr=]value
Blanks in the
value
break it into words, as in
rc
but without the surrounding parentheses.
Such variables are exported
to the environment of
recipes as they are executed, unless
U,
the only legal attribute
attr,
is present.
The initial value of a variable is
taken from (in increasing order of precedence)
the default values below,
mk's
environment, the
mkfiles,
and any command line assignment as an argument to
mk.
A variable assignment argument overrides the first (but not any subsequent)
assignment to that variable.
The variable
MKFLAGS
contains all the option arguments (arguments starting with
-
or containing
=)
and
MKARGS
contains all the targets in the call to
mk.
It is recommended that mkfiles start with
</$objtype/mkfile
to set CC, LD, AS, O, ALEF, YACC, and MK to values appropriate to the target architecture (see the examples below).
Dynamic information may be included in the mkfile by using a line of the form
<| command args
This runs the command
command
with the given arguments
args
and pipes its standard output to
mk
to be included as part of the mkfile. For instance, the file
/os/sa1100/mkfile
uses this technique
to run a shell command with an awk script and a configuration file as arguments in order for
the
awk
script to process the file and output a set of variables and their values.
A target is considered up to date if it has no prerequisites or if all its prerequisites are up to date and it is newer than all its prerequisites. Once the recipe for a target has executed, the target is considered up to date.
The date stamp used to determine if a target is up to date is computed differently for different types of targets. If a target is virtual (the target of a rule with the V attribute), its date stamp is initially zero; when the target is updated the date stamp is set to the most recent date stamp of its prerequisites. Otherwise, if a target does not exist as a file, its date stamp is set to the most recent date stamp of its prerequisites, or zero if it has no prerequisites. Otherwise, the target is the name of a file and the target's date stamp is always that file's modification date. The date stamp is computed when the target is needed in the execution of a rule; it is not a static value.
Nonexistent targets that have prerequisites and are themselves prerequisites are treated specially. Such a target t is given the date stamp of its most recent prerequisite and if this causes all the targets which have t as a prerequisite to be up to date, t is considered up to date. Otherwise, t is made in the normal fashion. The -i flag overrides this special treatment.
Files may be made in any order that respects the preceding restrictions.
A recipe is executed by supplying the recipe as standard input to
the command
$SHELL -e -I
where the
SHELL
variable is the appropriate shell on the current platform - typically
/bin/sh
or
/bin/rc.
The appropriate value is automatically supplied in the Inferno build environment.
The
-e
is omitted if the
E
attribute is set.
The environment is augmented by the following variables:
These variables are available only during the execution of a recipe, not while evaluating the mkfile.
Unless the rule has the Q attribute, the recipe is printed prior to execution with recognizable environment variables expanded. Commands returning error status cause mk to terminate.
Recipes and backquoted rc commands in places such as assignments execute in a copy of mk's environment; changes they make to environment variables are not visible from mk.
Variable substitution in a rule is done when the rule is read; variable substitution in the recipe is done when the recipe is executed. For example:
bar=a.c foo: $bar $CC -o foo $bar bar=b.c
will compile b.c into foo, if a.c is newer than foo.
</$objtype/mkfile prog: a.$O b.$O c.$O $LD $CFLAGS -o $target $prereq %.$O: %.c $CC $stem.c
Override flag settings in the mkfile:
% mk target 'CFLAGS=-S -w'
To get the prerequisites for an aggregate:
% membername 'libc.a(read.2)' 'libc.a(write.2)' read.2 write.2
Maintain a library:
libc.a(%.$O):N: %.$O libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ... names=`{membername $newprereq} ar r libc.a $names && rm $names
String expression variables to derive names from a master list:
NAMES=alloc arc bquote builtins expand main match mk var word OBJ=${NAMES:%=%.$O}
Regular expression meta-rules:
([^/]*)/(.*)\.o:R: \1/\2.c cd $stem1; $CC $CFLAGS $stem2.c
A correct way to deal with yacc(10.1) grammars. The file lex.c includes the file x.tab.h rather than y.tab.h in order to reflect changes in content, not just modification time.
lex.o: x.tab.h x.tab.h: y.tab.h cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h y.tab.c y.tab.h: gram.y $YACC -d gram.y
The above example could also use the P attribute for the x.tab.h rule:
x.tab.h:Pcmp -s: y.tab.h cp y.tab.h x.tab.h
MK(10.1 ) | Rev: Thu Feb 15 14:42:59 GMT 2007 |