forsyth20121205-174063a80cc13 years agoHistory
586 lines · 11.9 KB · Text
RawDownload
.TH MK 1.SH NAMEmk \- maintain (make) related files.SH SYNOPSIS.B mk[.B -f.I mkfile] ...[.I option ...][.I target ...].SH DESCRIPTION.I Mkuses the dependency rules specified in.I mkfileto 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 rulefor each target that identifies the files and othertargets upon which it depends and a.IR sh (1)script, a.IR recipe ,to update the target.The script is run if the target does not existor if it is older than any of the files it depends on..I Mkfilemay also contain.I meta-rulesthat define actions for updating implicit targets.If no.I targetis specified, the target of the first rule (not meta-rule) in.I mkfileis updated..PPThe environment variable.B $NPROCdetermines how many targets may be updated simultaneously; the default value is 1..PPOptions are:.TP \w'\fL-d[egp]\ 'u.B -aAssume all targets to be out of date.Thus, everything is updated..PD 0.TP.BR -d [ egp ]Produce debugging output.RB ( pis for parsing,.B gfor graph building,.B efor execution)..TP.B -eExplain why each target is made..TP.B -iForce any missing intermediate targets to be made..TP.B -kDo as much work as possible in the face of errors..TP.B -nPrint, but do not execute, the commandsneeded to update the targets..TP.B -sMake the command line arguments sequentially rather than in parallel..TP.B -tTouch (update the modified date of) file targets, withoutexecuting any recipes..TP.BI -w target1 , target2,...Pretend the modify time for each.I targetis the current time; useful in conjunction with.B -nto learn what updates would be triggered bymodifying the.IR targets ..PD.SS The mkfileA.I mkfileconsists of.I assignments(described under `Environment') and.IR rules .A rule contains.I targetsand a.IR tail .A target is a literal stringand is normally a file name.The tail contains zero or more .I prerequisitesand an optional.IR recipe ,which is a.B shscript.Each line of the recipe must begin with white space.A rule takes the form.IP.EXtarget: prereq1 prereq2        sh \f2recipe using\fP prereq1, prereq2 \f2to build\fP target.EE.PPWhen the recipe is executed,the first character on every line is elided..PPAfter the colon on the target line, a rule may specify.IR attributes ,described below..PPA.I meta-rule has a target of the form.IB A % Bwhere.I Aand.I Bare (possibly empty) strings.A meta-rule acts as a rule for any potential target whosename matches.IB A % Bwith.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 $stemcontains the string matched by the.BR % .For example, a meta-rule to compile a limbo program anmd install itmight be:.IP.EX%.dis:    %.b        limbo $stem.b	cp $stem.dis /dis.EE.PPMeta-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 periodor slash..PPThe text of the.I mkfileis processed as follows.Lines beginning with.B <followed by a file name are replaced by the contents of the namedfile.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 mkfilemay be folded.Non-recipe lines are processed by substituting for.BI `{ command }the output of the.I commandwhen run by.IR sh .References to variables are replaced by the variables' values.Special characters may be quoted using single quotes.BR \&''as in.IR sh (1)..PPAssignments and rules are distinguished bythe first unquoted occurrence of.B :(rule)or.B =(assignment)..PPA later rule may modify or override an existing rule under thefollowing conditions:.TP\-If the targets of the rules exactly match and one rulecontains only a prerequisite clause and no recipe, theclause is added to the prerequisites of the other rule.If either or both targets are virtual, the recipe isalways executed..TP\-If the targets of the rules match exactly and theprerequisites do not match and both rulescontain recipes,.I mkreports an ``ambiguous recipe'' error..TP\-If the target and prerequisites of both rules match exactly,the second rule overrides the first..SS EnvironmentRules may make use of.B shenvironment variables.A legal reference of the form.B $OBJor.B ${name}is expanded as in.IR sh (1).A reference of the form.BI ${name: A % B = C\fL%\fID\fL}\fR,where.I A, B, C, Dare (possibly empty) strings,has the value formed by expanding.B $nameand substituting.I Cfor.I Aand.I Dfor.I Bin each word in.B $namethat matches pattern.IB A % B\f1..PPVariables can be set byassignments of the form.I        var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR.brBlanks in the.I valuebreak it into words, as in.I shbut without the surrounding parentheses.Such variables are exportedto the environment ofrecipes as they are executed, unless.BR U ,the only legal attribute.IR attr ,is present.The initial value of a variable istaken from (in increasing order of precedence)the default values below,.I mk'senvironment, 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 MKFLAGScontains all the option arguments (arguments starting with.L -or containing.LR = )and.B MKARGScontains all the targets in the call to.IR mk ..PPDynamic information may be included in the mkfile by using a line of the form.I        \fR<| \fIcommand\fR \fIargs\fR.brThis runs the command .I commandwith the given arguments.I argsand pipes its standard output to.I mkto be included as part of the mkfile. For instance, the file.B /os/sa1100/mkfileuses this techniqueto run a shell command with an awk script and a configuration file as arguments in order forthe.I awkscript to process the file and output a set of variables and their values..SS Execution.PPDuring execution,.I mkdetermines which targets must be updated, and in what order,to build the.I namesspecified on the command line.It then runs the associated recipes..PPA target is considered up to date if it has no prerequisites orif all its prerequisites are up to date and it is newerthan all its prerequisites.Once the recipe for a target has executed, the target isconsidered up to date..PPThe date stampused to determine if a target is up to date is computeddifferently for different types of targets.If a target is.I virtual(the target of a rule with the.B Vattribute),its date stamp is initially zero; when the target isupdated the date stamp is set tothe 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 andthe target's date stamp is always that file's modification date.The date stamp is computed when the target is needed inthe execution of a rule; it is not a static value..PPNonexistent targets that have prerequisitesand are themselves prerequisites are treated specially.Such a target.I tis given the date stamp of its most recent prerequisiteand if this causes all the targets which have.I tas a prerequisite to be up to date,.I tis considered up to date.Otherwise,.I tis made in the normal fashion.The.B -iflag overrides this special treatment..PPFiles may be made in any order that respectsthe preceding restrictions..PPA recipe is executed by supplying the recipe as standard input tothe command.B        $SHELL -e -I.brwhere the.I SHELLvariable is the appropriate shell on the current platform - typically.B /dis/sh.The appropriate value is automatically supplied in the Inferno build environment.The.B -eis omitted if the.B Eattribute is set. The environment is augmented by the following variables:.TP 14.B $alltargetall the targets of this rule..TP.B $newprereqthe prerequisites that caused this rule to execute..TP.B $nprocthe process slot for this recipe.It satisfies.RB 0≤ $nproc < $NPROC ..TP.B $pidthe process id for the.I mkexecuting the recipe..TP.B $prereqall the prerequisites for this rule..TP.B $stemif this is a meta-rule,.B $stemis the string that matched.B %or.BR & .Otherwise, it is empty.For regular expression meta-rules (see below), the variables.LR stem0 ", ...,".L stem9are set to the corresponding subexpressions..TP.B $targetthe targets for this rule that need to be remade..PPThese variables are available only during the execution of a recipe,not while evaluating the.IR mkfile ..PPUnless the rule has the.B Qattribute,the recipe is printed prior to executionwith recognizable environment variables expanded.Commands returning error statuscause.I mkto terminate..PPRecipes and backquoted.B shcommands in places such as assignmentsexecute in a copy of.I mk'senvironment; changes they make toenvironment variables are not visible from.IR mk ..PPVariable substitution in a rule is done whenthe rule is read; variable substitution in the recipe is donewhen the recipe is executed.  For example:.IP.EXbar=a.bfoo:    $bar        limbo -o foo $barbar=b.b.EE.PPwill compile.B b.binto.BR foo ,if.B a.bis newer than.BR foo ..SS AggregatesNames of the form.IR a ( b )refer to member.I bof the aggregate.IR a .Currently, there are no aggregates supported under Inferno..SS AttributesThe colon separating the target from the prerequisitesmay beimmediately followed by.I attributesand another colon.The attributes are:.TP.B <The standard output of the recipe is read by.I mkas an additional.IR mkfile ..PD 0.TP.B DIf the recipe exits with a non-null status, the target is deleted..TP.B EContinue execution if the recipe draws errors..TP.B NIf there is no recipe, the target has its time updated..TP.B nThe rule is a meta-rule that cannot be a target of a virtual rule.

Lines 1–500 of 586.