.TH MK 1 .SH NAME mk, membername \- maintain (make) related files .SH SYNOPSIS .B mk [ .B -f .I mkfile ] ... [ .I option ... ] [ .I target ... ] .PP .B membername .I aggregate ... .SH DESCRIPTION .I Mk uses the dependency rules specified in .I mkfile to control the update (usually by compilation) of .I targets (usually files) from the source files upon which they depend. The .I mkfile (default .LR mkfile ) contains a .I rule for each target that identifies the files and other targets upon which it depends and an .IR rc (1) script, a .IR recipe , to update the target. The script is run if the target does not exist or if it is older than any of the files it depends on. .I Mkfile may also contain .I meta-rules that define actions for updating implicit targets. If no .I target is specified, the target of the first rule (not meta-rule) in .I mkfile is updated. .PP The environment variable .B $NPROC determines how many targets may be updated simultaneously; Plan 9 sets .B $NPROC automatically to the number of CPUs on the current machine. The variable .B $MKFILE may be set to indicate which .B mkfile should be read if there is no one in the current directory. .PP Options are: .TP \w'\fL-d[egp]\ 'u .B -a Assume all targets to be out of date. Thus, everything is updated. .PD 0 .TP .BR -d [ egp ] Produce debugging output .RB ( p is for parsing, .B g for graph building, .B e for execution). .TP .B -e Explain why each target is made. .TP .B -i Force any missing intermediate targets to be made. .TP .B -k Do as much work as possible in the face of errors. .TP .B -n Print, but do not execute, the commands needed to update the targets. .TP .B -s Make the command line arguments sequentially rather than in parallel. .TP .B -t Touch (update the modified date of) file targets, without executing any recipes. .TP .BI -w target1 , target2,... Pretend the modify time for each .I target is the current time; useful in conjunction with .B -n to learn what updates would be triggered by modifying the .IR targets . .PD .PP The .IR rc (1) script .I membername extracts member names (see `Aggregates' below) from its arguments. .SS The \fLmkfile\fP A .I mkfile consists of .I assignments (described under `Environment') and .IR rules . A rule contains .I targets and a .IR tail . A target is a literal string and is normally a file name. The tail contains zero or more .I prerequisites and an optional .IR recipe , which is an .B rc script. Each line of the recipe must begin with white space. A rule takes the form .IP .EX target: prereq1 prereq2 rc \f2recipe using\fP prereq1, prereq2 \f2to build\fP target .EE .PP When the recipe is executed, the first character on every line is elided. .PP After the colon on the target line, a rule may specify .IR attributes , described below. .PP A .I meta-rule has a target of the form .IB A % B where .I A and .I B are (possibly empty) strings. A meta-rule acts as a rule for any potential target whose name matches .IB A % B with .B % replaced by an arbitrary string, called the .IR stem . In interpreting a meta-rule, the stem is substituted for all occurrences of .B % in the prerequisite names. In the recipe of a meta-rule, the environment variable .B $stem contains the string matched by the .BR % . For example, a meta-rule to compile a C program using .IR 2c (1) might be: .IP .EX %: %.c 2c $stem.c 2l -o $stem $stem.2 .EE .PP Meta-rules may contain an ampersand .B & rather than a percent sign .BR % . A .B % matches a maximal length string of any characters; an .B & matches a maximal length string of any characters except period or slash. .PP The text of the .I mkfile is processed as follows. Lines beginning with .B < followed by a file name are replaced by the contents of the named file. Lines beginning with .B "<|" followed by a file name are replaced by the output of the execution of the named file. Blank lines and comments, which run from unquoted .B # characters to the following newline, are deleted. The character sequence backslash-newline is deleted, so long lines in .I mkfile may be folded. Non-recipe lines are processed by substituting for .BI `{ command } the output of the .I command when run by .IR rc . References to variables are replaced by the variables' values. Special characters may be quoted using single quotes .BR \&'' as in .IR rc (1). .PP Assignments and rules are distinguished by the first unquoted occurrence of .B : (rule) or .B = (assignment). .PP A later rule may modify or override an existing rule under the following conditions: .TP \- If the targets of the rules exactly match and one rule contains only a prerequisite clause and no recipe, the clause is added to the prerequisites of the other rule. If either or both targets are virtual, the recipe is always executed. .TP \- If the targets of the rules match exactly and the prerequisites do not match and both rules contain recipes, .I mk reports an ``ambiguous recipe'' error. .TP \- If the target and prerequisites of both rules match exactly, the second rule overrides the first. .SS Environment Rules may make use of .B rc environment variables. A legal reference of the form .B $OBJ is expanded as in .IR rc (1). A reference of the form .BI ${name: A % B = C\fL%\fID\fL}\fR, where .I A, B, C, D are (possibly empty) strings, has the value formed by expanding .B $name and substituting .I C for .I A and .I D for .I B in each word in .B $name that matches pattern .IB A % B\f1. .PP Variables can be set by assignments of the form .I var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR .br Blanks in the .I value break it into words, as in .I rc but without the surrounding parentheses. Such variables are exported to the environment of recipes as they are executed, unless .BR U , the only legal attribute .IR attr , is present. The initial value of a variable is taken from (in increasing order of precedence) the default values below, .I mk's environment, the .IR mkfiles , and any command line assignment as an argument to .IR mk . A variable assignment argument overrides the first (but not any subsequent) assignment to that variable. The variable .B MKFLAGS contains all the option arguments (arguments starting with .L - or containing .LR = ) and .B MKARGS contains all the targets in the call to .IR mk . .PP It is recommended that mkfiles start with .IP .EX