Blame


1 058b0118 2005-01-03 devnull .TH MK 1
2 058b0118 2005-01-03 devnull .SH NAME
3 93aa30a8 2005-01-14 devnull mk \- maintain (make) related files
4 058b0118 2005-01-03 devnull .SH SYNOPSIS
5 058b0118 2005-01-03 devnull .B mk
6 058b0118 2005-01-03 devnull [
7 058b0118 2005-01-03 devnull .B -f
8 058b0118 2005-01-03 devnull .I mkfile
9 058b0118 2005-01-03 devnull ] ...
10 058b0118 2005-01-03 devnull [
11 058b0118 2005-01-03 devnull .I option ...
12 058b0118 2005-01-03 devnull ]
13 058b0118 2005-01-03 devnull [
14 058b0118 2005-01-03 devnull .I target ...
15 058b0118 2005-01-03 devnull ]
16 058b0118 2005-01-03 devnull .SH DESCRIPTION
17 058b0118 2005-01-03 devnull .I Mk
18 058b0118 2005-01-03 devnull uses the dependency rules specified in
19 058b0118 2005-01-03 devnull .I mkfile
20 058b0118 2005-01-03 devnull to control the update (usually by compilation) of
21 058b0118 2005-01-03 devnull .I targets
22 058b0118 2005-01-03 devnull (usually files)
23 058b0118 2005-01-03 devnull from the source files upon which they depend.
24 058b0118 2005-01-03 devnull The
25 058b0118 2005-01-03 devnull .I mkfile
26 058b0118 2005-01-03 devnull (default
27 058b0118 2005-01-03 devnull .LR mkfile )
28 058b0118 2005-01-03 devnull contains a
29 058b0118 2005-01-03 devnull .I rule
30 058b0118 2005-01-03 devnull for each target that identifies the files and other
31 058b0118 2005-01-03 devnull targets upon which it depends and an
32 d32deab1 2020-08-16 rsc .MR sh (1)
33 058b0118 2005-01-03 devnull script, a
34 058b0118 2005-01-03 devnull .IR recipe ,
35 058b0118 2005-01-03 devnull to update the target.
36 058b0118 2005-01-03 devnull The script is run if the target does not exist
37 058b0118 2005-01-03 devnull or if it is older than any of the files it depends on.
38 058b0118 2005-01-03 devnull .I Mkfile
39 058b0118 2005-01-03 devnull may also contain
40 058b0118 2005-01-03 devnull .I meta-rules
41 058b0118 2005-01-03 devnull that define actions for updating implicit targets.
42 058b0118 2005-01-03 devnull If no
43 058b0118 2005-01-03 devnull .I target
44 058b0118 2005-01-03 devnull is specified, the target of the first rule (not meta-rule) in
45 058b0118 2005-01-03 devnull .I mkfile
46 058b0118 2005-01-03 devnull is updated.
47 058b0118 2005-01-03 devnull .PP
48 058b0118 2005-01-03 devnull The environment variable
49 058b0118 2005-01-03 devnull .B $NPROC
50 058b0118 2005-01-03 devnull determines how many targets may be updated simultaneously;
51 058b0118 2005-01-03 devnull Some operating systems, e.g., Plan 9, set
52 058b0118 2005-01-03 devnull .B $NPROC
53 058b0118 2005-01-03 devnull automatically to the number of CPUs on the current machine.
54 058b0118 2005-01-03 devnull .PP
55 058b0118 2005-01-03 devnull Options are:
56 058b0118 2005-01-03 devnull .TP \w'\fL-d[egp]\ 'u
57 058b0118 2005-01-03 devnull .B -a
58 058b0118 2005-01-03 devnull Assume all targets to be out of date.
59 058b0118 2005-01-03 devnull Thus, everything is updated.
60 058b0118 2005-01-03 devnull .PD 0
61 058b0118 2005-01-03 devnull .TP
62 058b0118 2005-01-03 devnull .BR -d [ egp ]
63 058b0118 2005-01-03 devnull Produce debugging output
64 058b0118 2005-01-03 devnull .RB ( p
65 058b0118 2005-01-03 devnull is for parsing,
66 058b0118 2005-01-03 devnull .B g
67 058b0118 2005-01-03 devnull for graph building,
68 058b0118 2005-01-03 devnull .B e
69 058b0118 2005-01-03 devnull for execution).
70 058b0118 2005-01-03 devnull .TP
71 058b0118 2005-01-03 devnull .B -e
72 058b0118 2005-01-03 devnull Explain why each target is made.
73 058b0118 2005-01-03 devnull .TP
74 058b0118 2005-01-03 devnull .B -i
75 058b0118 2005-01-03 devnull Force any missing intermediate targets to be made.
76 058b0118 2005-01-03 devnull .TP
77 058b0118 2005-01-03 devnull .B -k
78 058b0118 2005-01-03 devnull Do as much work as possible in the face of errors.
79 058b0118 2005-01-03 devnull .TP
80 058b0118 2005-01-03 devnull .B -n
81 058b0118 2005-01-03 devnull Print, but do not execute, the commands
82 058b0118 2005-01-03 devnull needed to update the targets.
83 058b0118 2005-01-03 devnull .TP
84 058b0118 2005-01-03 devnull .B -s
85 058b0118 2005-01-03 devnull Make the command line arguments sequentially rather than in parallel.
86 058b0118 2005-01-03 devnull .TP
87 058b0118 2005-01-03 devnull .B -t
88 058b0118 2005-01-03 devnull Touch (update the modified date of) file targets, without
89 058b0118 2005-01-03 devnull executing any recipes.
90 058b0118 2005-01-03 devnull .TP
91 058b0118 2005-01-03 devnull .BI -w target1 , target2,...
92 058b0118 2005-01-03 devnull Pretend the modify time for each
93 058b0118 2005-01-03 devnull .I target
94 058b0118 2005-01-03 devnull is the current time; useful in conjunction with
95 058b0118 2005-01-03 devnull .B -n
96 058b0118 2005-01-03 devnull to learn what updates would be triggered by
97 058b0118 2005-01-03 devnull modifying the
98 058b0118 2005-01-03 devnull .IR targets .
99 058b0118 2005-01-03 devnull .PD
100 058b0118 2005-01-03 devnull .SS The \fLmkfile\fP
101 058b0118 2005-01-03 devnull A
102 058b0118 2005-01-03 devnull .I mkfile
103 058b0118 2005-01-03 devnull consists of
104 058b0118 2005-01-03 devnull .I assignments
105 058b0118 2005-01-03 devnull (described under `Environment') and
106 058b0118 2005-01-03 devnull .IR rules .
107 058b0118 2005-01-03 devnull A rule contains
108 058b0118 2005-01-03 devnull .I targets
109 058b0118 2005-01-03 devnull and a
110 058b0118 2005-01-03 devnull .IR tail .
111 058b0118 2005-01-03 devnull A target is a literal string
112 058b0118 2005-01-03 devnull and is normally a file name.
113 058b0118 2005-01-03 devnull The tail contains zero or more
114 058b0118 2005-01-03 devnull .I prerequisites
115 058b0118 2005-01-03 devnull and an optional
116 058b0118 2005-01-03 devnull .IR recipe ,
117 058b0118 2005-01-03 devnull which is an
118 058b0118 2005-01-03 devnull .B shell
119 058b0118 2005-01-03 devnull script.
120 058b0118 2005-01-03 devnull Each line of the recipe must begin with white space.
121 058b0118 2005-01-03 devnull A rule takes the form
122 058b0118 2005-01-03 devnull .IP
123 058b0118 2005-01-03 devnull .EX
124 058b0118 2005-01-03 devnull target: prereq1 prereq2
125 058b0118 2005-01-03 devnull \f2recipe using\fP prereq1, prereq2 \f2to build\fP target
126 058b0118 2005-01-03 devnull .EE
127 058b0118 2005-01-03 devnull .PP
128 058b0118 2005-01-03 devnull When the recipe is executed,
129 058b0118 2005-01-03 devnull the first character on every line is elided.
130 058b0118 2005-01-03 devnull .PP
131 058b0118 2005-01-03 devnull After the colon on the target line, a rule may specify
132 058b0118 2005-01-03 devnull .IR attributes ,
133 058b0118 2005-01-03 devnull described below.
134 058b0118 2005-01-03 devnull .PP
135 058b0118 2005-01-03 devnull A
136 058b0118 2005-01-03 devnull .I meta-rule
137 058b0118 2005-01-03 devnull has a target of the form
138 058b0118 2005-01-03 devnull .IB A % B
139 058b0118 2005-01-03 devnull where
140 058b0118 2005-01-03 devnull .I A
141 058b0118 2005-01-03 devnull and
142 058b0118 2005-01-03 devnull .I B
143 058b0118 2005-01-03 devnull are (possibly empty) strings.
144 058b0118 2005-01-03 devnull A meta-rule acts as a rule for any potential target whose
145 058b0118 2005-01-03 devnull name matches
146 058b0118 2005-01-03 devnull .IB A % B
147 058b0118 2005-01-03 devnull with
148 058b0118 2005-01-03 devnull .B %
149 058b0118 2005-01-03 devnull replaced by an arbitrary string, called the
150 058b0118 2005-01-03 devnull .IR stem .
151 058b0118 2005-01-03 devnull In interpreting a meta-rule,
152 058b0118 2005-01-03 devnull the stem is substituted for all occurrences of
153 058b0118 2005-01-03 devnull .B %
154 058b0118 2005-01-03 devnull in the prerequisite names.
155 058b0118 2005-01-03 devnull In the recipe of a meta-rule, the environment variable
156 058b0118 2005-01-03 devnull .B $stem
157 058b0118 2005-01-03 devnull contains the string matched by the
158 058b0118 2005-01-03 devnull .BR % .
159 058b0118 2005-01-03 devnull For example, a meta-rule to compile a C program using
160 d32deab1 2020-08-16 rsc .MR 9c (1)
161 058b0118 2005-01-03 devnull might be:
162 058b0118 2005-01-03 devnull .IP
163 058b0118 2005-01-03 devnull .EX
164 058b0118 2005-01-03 devnull %: %.c
165 058b0118 2005-01-03 devnull 9c -c $stem.c
166 058b0118 2005-01-03 devnull 9l -o $stem $stem.o
167 058b0118 2005-01-03 devnull .EE
168 058b0118 2005-01-03 devnull .PP
169 058b0118 2005-01-03 devnull Meta-rules may contain an ampersand
170 058b0118 2005-01-03 devnull .B &
171 058b0118 2005-01-03 devnull rather than a percent sign
172 058b0118 2005-01-03 devnull .BR % .
173 058b0118 2005-01-03 devnull A
174 058b0118 2005-01-03 devnull .B %
175 058b0118 2005-01-03 devnull matches a maximal length string of any characters;
176 058b0118 2005-01-03 devnull an
177 058b0118 2005-01-03 devnull .B &
178 058b0118 2005-01-03 devnull matches a maximal length string of any characters except period
179 058b0118 2005-01-03 devnull or slash.
180 058b0118 2005-01-03 devnull .PP
181 058b0118 2005-01-03 devnull The text of the
182 058b0118 2005-01-03 devnull .I mkfile
183 058b0118 2005-01-03 devnull is processed as follows.
184 058b0118 2005-01-03 devnull Lines beginning with
185 058b0118 2005-01-03 devnull .B <
186 058b0118 2005-01-03 devnull followed by a file name are replaced by the contents of the named
187 058b0118 2005-01-03 devnull file.
188 058b0118 2005-01-03 devnull Lines beginning with
189 058b0118 2005-01-03 devnull .B "<|"
190 058b0118 2005-01-03 devnull followed by a file name are replaced by the output
191 058b0118 2005-01-03 devnull of the execution of the named
192 058b0118 2005-01-03 devnull file.
193 058b0118 2005-01-03 devnull Blank lines and comments, which run from unquoted
194 058b0118 2005-01-03 devnull .B #
195 058b0118 2005-01-03 devnull characters to the following newline, are deleted.
196 058b0118 2005-01-03 devnull The character sequence backslash-newline is deleted,
197 058b0118 2005-01-03 devnull so long lines in
198 058b0118 2005-01-03 devnull .I mkfile
199 058b0118 2005-01-03 devnull may be folded.
200 058b0118 2005-01-03 devnull Non-recipe lines are processed by substituting for
201 058b0118 2005-01-03 devnull .BI `{ command }
202 058b0118 2005-01-03 devnull the output of the
203 058b0118 2005-01-03 devnull .I command
204 058b0118 2005-01-03 devnull when run by
205 058b0118 2005-01-03 devnull .IR sh .
206 058b0118 2005-01-03 devnull References to variables are replaced by the variables' values.
207 058b0118 2005-01-03 devnull Special characters may be quoted using single quotes
208 058b0118 2005-01-03 devnull .BR \&''
209 058b0118 2005-01-03 devnull as in
210 d32deab1 2020-08-16 rsc .MR sh (1) .
211 058b0118 2005-01-03 devnull .PP
212 058b0118 2005-01-03 devnull Assignments and rules are distinguished by
213 058b0118 2005-01-03 devnull the first unquoted occurrence of
214 058b0118 2005-01-03 devnull .B :
215 058b0118 2005-01-03 devnull (rule)
216 058b0118 2005-01-03 devnull or
217 058b0118 2005-01-03 devnull .B =
218 058b0118 2005-01-03 devnull (assignment).
219 058b0118 2005-01-03 devnull .PP
220 058b0118 2005-01-03 devnull A later rule may modify or override an existing rule under the
221 058b0118 2005-01-03 devnull following conditions:
222 058b0118 2005-01-03 devnull .TP
223 058b0118 2005-01-03 devnull \-
224 058b0118 2005-01-03 devnull If the targets of the rules exactly match and one rule
225 058b0118 2005-01-03 devnull contains only a prerequisite clause and no recipe, the
226 058b0118 2005-01-03 devnull clause is added to the prerequisites of the other rule.
227 058b0118 2005-01-03 devnull If either or both targets are virtual, the recipe is
228 058b0118 2005-01-03 devnull always executed.
229 058b0118 2005-01-03 devnull .TP
230 058b0118 2005-01-03 devnull \-
231 058b0118 2005-01-03 devnull If the targets of the rules match exactly and the
232 058b0118 2005-01-03 devnull prerequisites do not match and both rules
233 058b0118 2005-01-03 devnull contain recipes,
234 058b0118 2005-01-03 devnull .I mk
235 058b0118 2005-01-03 devnull reports an ``ambiguous recipe'' error.
236 058b0118 2005-01-03 devnull .TP
237 058b0118 2005-01-03 devnull \-
238 058b0118 2005-01-03 devnull If the target and prerequisites of both rules match exactly,
239 058b0118 2005-01-03 devnull the second rule overrides the first.
240 058b0118 2005-01-03 devnull .SS Environment
241 058b0118 2005-01-03 devnull Rules may make use of
242 058b0118 2005-01-03 devnull shell
243 058b0118 2005-01-03 devnull environment variables.
244 058b0118 2005-01-03 devnull A legal reference of the form
245 058b0118 2005-01-03 devnull .B $OBJ
246 058b0118 2005-01-03 devnull or
247 058b0118 2005-01-03 devnull .B ${name}
248 058b0118 2005-01-03 devnull is expanded as in
249 d32deab1 2020-08-16 rsc .MR sh (1) .
250 058b0118 2005-01-03 devnull A reference of the form
251 058b0118 2005-01-03 devnull .BI ${name: A % B = C\fL%\fID\fL}\fR,
252 058b0118 2005-01-03 devnull where
253 058b0118 2005-01-03 devnull .I A, B, C, D
254 058b0118 2005-01-03 devnull are (possibly empty) strings,
255 058b0118 2005-01-03 devnull has the value formed by expanding
256 058b0118 2005-01-03 devnull .B $name
257 058b0118 2005-01-03 devnull and substituting
258 058b0118 2005-01-03 devnull .I C
259 058b0118 2005-01-03 devnull for
260 058b0118 2005-01-03 devnull .I A
261 058b0118 2005-01-03 devnull and
262 058b0118 2005-01-03 devnull .I D
263 058b0118 2005-01-03 devnull for
264 058b0118 2005-01-03 devnull .I B
265 058b0118 2005-01-03 devnull in each word in
266 058b0118 2005-01-03 devnull .B $name
267 058b0118 2005-01-03 devnull that matches pattern
268 058b0118 2005-01-03 devnull .IB A % B\f1.
269 058b0118 2005-01-03 devnull .PP
270 058b0118 2005-01-03 devnull Variables can be set by
271 058b0118 2005-01-03 devnull assignments of the form
272 058b0118 2005-01-03 devnull .I
273 058b0118 2005-01-03 devnull var\fL=\fR[\fIattr\fL=\fR]\fIvalue\fR
274 058b0118 2005-01-03 devnull .br
275 058b0118 2005-01-03 devnull Blanks in the
276 058b0118 2005-01-03 devnull .I value
277 058b0118 2005-01-03 devnull break it into words.
278 058b0118 2005-01-03 devnull Such variables are exported
279 058b0118 2005-01-03 devnull to the environment of
280 058b0118 2005-01-03 devnull recipes as they are executed, unless
281 058b0118 2005-01-03 devnull .BR U ,
282 058b0118 2005-01-03 devnull the only legal attribute
283 058b0118 2005-01-03 devnull .IR attr ,
284 058b0118 2005-01-03 devnull is present.
285 058b0118 2005-01-03 devnull The initial value of a variable is
286 058b0118 2005-01-03 devnull taken from (in increasing order of precedence)
287 058b0118 2005-01-03 devnull the default values below,
288 058b0118 2005-01-03 devnull .I mk's
289 058b0118 2005-01-03 devnull environment, the
290 058b0118 2005-01-03 devnull .IR mkfiles ,
291 058b0118 2005-01-03 devnull and any command line assignment as an argument to
292 058b0118 2005-01-03 devnull .IR mk .
293 058b0118 2005-01-03 devnull A variable assignment argument overrides the first (but not any subsequent)
294 058b0118 2005-01-03 devnull assignment to that variable.
295 c8b6342d 2005-01-13 devnull .PP
296 058b0118 2005-01-03 devnull The variable
297 058b0118 2005-01-03 devnull .B MKFLAGS
298 058b0118 2005-01-03 devnull contains all the option arguments (arguments starting with
299 058b0118 2005-01-03 devnull .L -
300 058b0118 2005-01-03 devnull or containing
301 058b0118 2005-01-03 devnull .LR = )
302 058b0118 2005-01-03 devnull and
303 058b0118 2005-01-03 devnull .B MKARGS
304 058b0118 2005-01-03 devnull contains all the targets in the call to
305 058b0118 2005-01-03 devnull .IR mk .
306 058b0118 2005-01-03 devnull .PP
307 c8b6342d 2005-01-13 devnull The variable
308 c8b6342d 2005-01-13 devnull .B MKSHELL
309 c8b6342d 2005-01-13 devnull contains the shell command line
310 c8b6342d 2005-01-13 devnull .I mk
311 c8b6342d 2005-01-13 devnull uses to run recipes.
312 c8b6342d 2005-01-13 devnull If the first word of the command ends in
313 c8b6342d 2005-01-13 devnull .B rc
314 c8b6342d 2005-01-13 devnull or
315 c8b6342d 2005-01-13 devnull .BR rcsh ,
316 c8b6342d 2005-01-13 devnull .I mk
317 c8b6342d 2005-01-13 devnull uses
318 d32deab1 2020-08-16 rsc .MR rc (1) 's
319 c8b6342d 2005-01-13 devnull quoting rules; otherwise it uses
320 d32deab1 2020-08-16 rsc .MR sh (1) 's.
321 c8b6342d 2005-01-13 devnull The
322 c8b6342d 2005-01-13 devnull .B MKSHELL
323 c8b6342d 2005-01-13 devnull variable is consulted when the mkfile is read, not when it is executed,
324 c8b6342d 2005-01-13 devnull so that different shells can be used within a single mkfile:
325 c8b6342d 2005-01-13 devnull .IP
326 c8b6342d 2005-01-13 devnull .EX
327 c8b6342d 2005-01-13 devnull MKSHELL=$PLAN9/bin/rc
328 c8b6342d 2005-01-13 devnull use-rc:V:
329 c8b6342d 2005-01-13 devnull for(i in a b c) echo $i
330 c8b6342d 2005-01-13 devnull
331 c8b6342d 2005-01-13 devnull MKSHELL=sh
332 c8b6342d 2005-01-13 devnull use-sh:V:
333 c8b6342d 2005-01-13 devnull for i in a b c; do echo $i; done
334 c8b6342d 2005-01-13 devnull .EE
335 c8b6342d 2005-01-13 devnull .LP
336 c8b6342d 2005-01-13 devnull Mkfiles included via
337 c8b6342d 2005-01-13 devnull .B <
338 c8b6342d 2005-01-13 devnull or
339 c8b6342d 2005-01-13 devnull .B <|
340 c8b6342d 2005-01-13 devnull .RI ( q.v. )
341 c8b6342d 2005-01-13 devnull see their own private copy of
342 c8b6342d 2005-01-13 devnull .BR MKSHELL ,
343 c8b6342d 2005-01-13 devnull which always starts set to
344 c8b6342d 2005-01-13 devnull .B sh .
345 c8b6342d 2005-01-13 devnull .PP
346 058b0118 2005-01-03 devnull Dynamic information may be included in the mkfile by using a line of the form
347 058b0118 2005-01-03 devnull .IP
348 058b0118 2005-01-03 devnull \fR<|\fIcommand\fR \fIargs\fR
349 058b0118 2005-01-03 devnull .LP
350 058b0118 2005-01-03 devnull This runs the command
351 058b0118 2005-01-03 devnull .I command
352 058b0118 2005-01-03 devnull with the given arguments
353 058b0118 2005-01-03 devnull .I args
354 058b0118 2005-01-03 devnull and pipes its standard output to
355 058b0118 2005-01-03 devnull .I mk
356 058b0118 2005-01-03 devnull to be included as part of the mkfile. For instance, the Inferno kernels
357 058b0118 2005-01-03 devnull use this technique
358 058b0118 2005-01-03 devnull to run a shell command with an awk script and a configuration
359 058b0118 2005-01-03 devnull file as arguments in order for
360 058b0118 2005-01-03 devnull the
361 058b0118 2005-01-03 devnull .I awk
362 058b0118 2005-01-03 devnull script to process the file and output a set of variables and their values.
363 058b0118 2005-01-03 devnull .SS Execution
364 058b0118 2005-01-03 devnull .PP
365 058b0118 2005-01-03 devnull During execution,
366 058b0118 2005-01-03 devnull .I mk
367 058b0118 2005-01-03 devnull determines which targets must be updated, and in what order,
368 058b0118 2005-01-03 devnull to build the
369 058b0118 2005-01-03 devnull .I names
370 058b0118 2005-01-03 devnull specified on the command line.
371 058b0118 2005-01-03 devnull It then runs the associated recipes.
372 058b0118 2005-01-03 devnull .PP
373 058b0118 2005-01-03 devnull A target is considered up to date if it has no prerequisites or
374 058b0118 2005-01-03 devnull if all its prerequisites are up to date and it is newer
375 058b0118 2005-01-03 devnull than all its prerequisites.
376 058b0118 2005-01-03 devnull Once the recipe for a target has executed, the target is
377 058b0118 2005-01-03 devnull considered up to date.
378 058b0118 2005-01-03 devnull .PP
379 058b0118 2005-01-03 devnull The date stamp
380 058b0118 2005-01-03 devnull used to determine if a target is up to date is computed
381 058b0118 2005-01-03 devnull differently for different types of targets.
382 058b0118 2005-01-03 devnull If a target is
383 058b0118 2005-01-03 devnull .I virtual
384 058b0118 2005-01-03 devnull (the target of a rule with the
385 058b0118 2005-01-03 devnull .B V
386 058b0118 2005-01-03 devnull attribute),
387 058b0118 2005-01-03 devnull its date stamp is initially zero; when the target is
388 058b0118 2005-01-03 devnull updated the date stamp is set to
389 058b0118 2005-01-03 devnull the most recent date stamp of its prerequisites.
390 058b0118 2005-01-03 devnull Otherwise, if a target does not exist as a file,
391 058b0118 2005-01-03 devnull its date stamp is set to the most recent date stamp of its prerequisites,
392 058b0118 2005-01-03 devnull or zero if it has no prerequisites.
393 058b0118 2005-01-03 devnull Otherwise, the target is the name of a file and
394 058b0118 2005-01-03 devnull the target's date stamp is always that file's modification date.
395 058b0118 2005-01-03 devnull The date stamp is computed when the target is needed in
396 058b0118 2005-01-03 devnull the execution of a rule; it is not a static value.
397 058b0118 2005-01-03 devnull .PP
398 058b0118 2005-01-03 devnull Nonexistent targets that have prerequisites
399 058b0118 2005-01-03 devnull and are themselves prerequisites are treated specially.
400 058b0118 2005-01-03 devnull Such a target
401 058b0118 2005-01-03 devnull .I t
402 058b0118 2005-01-03 devnull is given the date stamp of its most recent prerequisite
403 058b0118 2005-01-03 devnull and if this causes all the targets which have
404 058b0118 2005-01-03 devnull .I t
405 058b0118 2005-01-03 devnull as a prerequisite to be up to date,
406 058b0118 2005-01-03 devnull .I t
407 058b0118 2005-01-03 devnull is considered up to date.
408 058b0118 2005-01-03 devnull Otherwise,
409 058b0118 2005-01-03 devnull .I t
410 058b0118 2005-01-03 devnull is made in the normal fashion.
411 058b0118 2005-01-03 devnull The
412 058b0118 2005-01-03 devnull .B -i
413 058b0118 2005-01-03 devnull flag overrides this special treatment.
414 058b0118 2005-01-03 devnull .PP
415 058b0118 2005-01-03 devnull Files may be made in any order that respects
416 058b0118 2005-01-03 devnull the preceding restrictions.
417 058b0118 2005-01-03 devnull .PP
418 058b0118 2005-01-03 devnull A recipe is executed by supplying the recipe as standard input to
419 058b0118 2005-01-03 devnull the command
420 058b0118 2005-01-03 devnull .BR /bin/sh .
421 058b0118 2005-01-03 devnull (Note that unlike
422 058b0118 2005-01-03 devnull .IR make ,
423 058b0118 2005-01-03 devnull .I mk
424 058b0118 2005-01-03 devnull feeds the entire recipe to the shell rather than running each line
425 058b0118 2005-01-03 devnull of the recipe separately.)
426 058b0118 2005-01-03 devnull The environment is augmented by the following variables:
427 058b0118 2005-01-03 devnull .TP 14
428 058b0118 2005-01-03 devnull .B $alltarget
429 058b0118 2005-01-03 devnull all the targets of this rule.
430 058b0118 2005-01-03 devnull .TP
431 058b0118 2005-01-03 devnull .B $newprereq
432 058b0118 2005-01-03 devnull the prerequisites that caused this rule to execute.
433 058b0118 2005-01-03 devnull .TP
434 058b0118 2005-01-03 devnull .B $newmember
435 058b0118 2005-01-03 devnull the prerequisites that are members of an aggregate
436 058b0118 2005-01-03 devnull that caused this rule to execute.
437 058b0118 2005-01-03 devnull When the prerequisites of a rule are members of an
438 058b0118 2005-01-03 devnull aggregate,
439 058b0118 2005-01-03 devnull .B $newprereq
440 058b0118 2005-01-03 devnull contains the name of the aggregate and out of date
441 058b0118 2005-01-03 devnull members, while
442 058b0118 2005-01-03 devnull .B $newmember
443 058b0118 2005-01-03 devnull contains only the name of the members.
444 058b0118 2005-01-03 devnull .TP
445 058b0118 2005-01-03 devnull .B $nproc
446 058b0118 2005-01-03 devnull the process slot for this recipe.
447 058b0118 2005-01-03 devnull It satisfies
448 058b0118 2005-01-03 devnull .RB 0≤ $nproc < $NPROC .
449 058b0118 2005-01-03 devnull .TP
450 058b0118 2005-01-03 devnull .B $pid
451 058b0118 2005-01-03 devnull the process id for the
452 058b0118 2005-01-03 devnull .I mk
453 058b0118 2005-01-03 devnull executing the recipe.
454 058b0118 2005-01-03 devnull .TP
455 058b0118 2005-01-03 devnull .B $prereq
456 058b0118 2005-01-03 devnull all the prerequisites for this rule.
457 058b0118 2005-01-03 devnull .TP
458 058b0118 2005-01-03 devnull .B $stem
459 058b0118 2005-01-03 devnull if this is a meta-rule,
460 058b0118 2005-01-03 devnull .B $stem
461 058b0118 2005-01-03 devnull is the string that matched
462 058b0118 2005-01-03 devnull .B %
463 058b0118 2005-01-03 devnull or
464 058b0118 2005-01-03 devnull .BR & .
465 058b0118 2005-01-03 devnull Otherwise, it is empty.
466 058b0118 2005-01-03 devnull For regular expression meta-rules (see below), the variables
467 058b0118 2005-01-03 devnull .LR stem0 ", ...,"
468 058b0118 2005-01-03 devnull .L stem9
469 058b0118 2005-01-03 devnull are set to the corresponding subexpressions.
470 058b0118 2005-01-03 devnull .TP
471 058b0118 2005-01-03 devnull .B $target
472 058b0118 2005-01-03 devnull the targets for this rule that need to be remade.
473 058b0118 2005-01-03 devnull .PP
474 058b0118 2005-01-03 devnull These variables are available only during the execution of a recipe,
475 058b0118 2005-01-03 devnull not while evaluating the
476 058b0118 2005-01-03 devnull .IR mkfile .
477 058b0118 2005-01-03 devnull .PP
478 058b0118 2005-01-03 devnull Unless the rule has the
479 058b0118 2005-01-03 devnull .B Q
480 058b0118 2005-01-03 devnull attribute,
481 058b0118 2005-01-03 devnull the recipe is printed prior to execution
482 058b0118 2005-01-03 devnull with recognizable environment variables expanded.
483 058b0118 2005-01-03 devnull Commands returning error status
484 058b0118 2005-01-03 devnull cause
485 058b0118 2005-01-03 devnull .I mk
486 058b0118 2005-01-03 devnull to terminate.
487 058b0118 2005-01-03 devnull .PP
488 058b0118 2005-01-03 devnull Recipes and backquoted
489 058b0118 2005-01-03 devnull .B rc
490 058b0118 2005-01-03 devnull commands in places such as assignments
491 058b0118 2005-01-03 devnull execute in a copy of
492 058b0118 2005-01-03 devnull .I mk's
493 058b0118 2005-01-03 devnull environment; changes they make to
494 058b0118 2005-01-03 devnull environment variables are not visible from
495 058b0118 2005-01-03 devnull .IR mk .
496 058b0118 2005-01-03 devnull .PP
497 058b0118 2005-01-03 devnull Variable substitution in a rule is done when
498 058b0118 2005-01-03 devnull the rule is read; variable substitution in the recipe is done
499 058b0118 2005-01-03 devnull when the recipe is executed. For example:
500 058b0118 2005-01-03 devnull .IP
501 058b0118 2005-01-03 devnull .EX
502 058b0118 2005-01-03 devnull bar=a.c
503 058b0118 2005-01-03 devnull foo: $bar
504 058b0118 2005-01-03 devnull $CC -o foo $bar
505 058b0118 2005-01-03 devnull bar=b.c
506 058b0118 2005-01-03 devnull .EE
507 058b0118 2005-01-03 devnull .PP
508 058b0118 2005-01-03 devnull will compile
509 058b0118 2005-01-03 devnull .B b.c
510 058b0118 2005-01-03 devnull into
511 058b0118 2005-01-03 devnull .BR foo ,
512 058b0118 2005-01-03 devnull if
513 058b0118 2005-01-03 devnull .B a.c
514 058b0118 2005-01-03 devnull is newer than
515 058b0118 2005-01-03 devnull .BR foo .
516 058b0118 2005-01-03 devnull .SS Aggregates
517 058b0118 2005-01-03 devnull Names of the form
518 058b0118 2005-01-03 devnull .IR a ( b )
519 058b0118 2005-01-03 devnull refer to member
520 058b0118 2005-01-03 devnull .I b
521 058b0118 2005-01-03 devnull of the aggregate
522 058b0118 2005-01-03 devnull .IR a .
523 058b0118 2005-01-03 devnull Currently, the only aggregates supported are
524 058b0118 2005-01-03 devnull .I 9ar
525 058b0118 2005-01-03 devnull (see
526 d32deab1 2020-08-16 rsc .MR 9c (1) )
527 058b0118 2005-01-03 devnull archives.
528 058b0118 2005-01-03 devnull .SS Attributes
529 058b0118 2005-01-03 devnull The colon separating the target from the prerequisites
530 058b0118 2005-01-03 devnull may be
531 058b0118 2005-01-03 devnull immediately followed by
532 058b0118 2005-01-03 devnull .I attributes
533 058b0118 2005-01-03 devnull and another colon.
534 058b0118 2005-01-03 devnull The attributes are:
535 058b0118 2005-01-03 devnull .TP
536 058b0118 2005-01-03 devnull .B D
537 058b0118 2005-01-03 devnull If the recipe exits with a non-null status, the target is deleted.
538 058b0118 2005-01-03 devnull .TP
539 058b0118 2005-01-03 devnull .B E
540 058b0118 2005-01-03 devnull Continue execution if the recipe draws errors.
541 058b0118 2005-01-03 devnull .TP
542 058b0118 2005-01-03 devnull .B N
543 058b0118 2005-01-03 devnull If there is no recipe, the target has its time updated.
544 058b0118 2005-01-03 devnull .TP
545 058b0118 2005-01-03 devnull .B n
546 058b0118 2005-01-03 devnull The rule is a meta-rule that cannot be a target of a virtual rule.
547 058b0118 2005-01-03 devnull Only files match the pattern in the target.
548 058b0118 2005-01-03 devnull .TP
549 058b0118 2005-01-03 devnull .B P
550 058b0118 2005-01-03 devnull The characters after the
551 058b0118 2005-01-03 devnull .B P
552 058b0118 2005-01-03 devnull until the terminating
553 058b0118 2005-01-03 devnull .B :
554 058b0118 2005-01-03 devnull are taken as a program name.
555 058b0118 2005-01-03 devnull It will be invoked as
556 058b0118 2005-01-03 devnull .B "sh -c prog 'arg1' 'arg2'"
557 058b0118 2005-01-03 devnull and should return a zero exit status
558 058b0118 2005-01-03 devnull if and only if arg1 is up to date with respect to arg2.
559 058b0118 2005-01-03 devnull Date stamps are still propagated in the normal way.
560 058b0118 2005-01-03 devnull .TP
561 058b0118 2005-01-03 devnull .B Q
562 058b0118 2005-01-03 devnull The recipe is not printed prior to execution.
563 058b0118 2005-01-03 devnull .TP
564 058b0118 2005-01-03 devnull .B R
565 058b0118 2005-01-03 devnull The rule is a meta-rule using regular expressions.
566 058b0118 2005-01-03 devnull In the rule,
567 058b0118 2005-01-03 devnull .B %
568 058b0118 2005-01-03 devnull has no special meaning.
569 058b0118 2005-01-03 devnull The target is interpreted as a regular expression as defined in
570 d32deab1 2020-08-16 rsc .MR regexp (7) .
571 058b0118 2005-01-03 devnull The prerequisites may contain references
572 058b0118 2005-01-03 devnull to subexpressions in form
573 058b0118 2005-01-03 devnull .BI \e n\f1,
574 058b0118 2005-01-03 devnull as in the substitute command of
575 d32deab1 2020-08-16 rsc .MR sed (1) .
576 058b0118 2005-01-03 devnull .TP
577 058b0118 2005-01-03 devnull .B U
578 058b0118 2005-01-03 devnull The targets are considered to have been updated
579 058b0118 2005-01-03 devnull even if the recipe did not do so.
580 058b0118 2005-01-03 devnull .TP
581 058b0118 2005-01-03 devnull .B V
582 058b0118 2005-01-03 devnull The targets of this rule are marked as virtual.
583 058b0118 2005-01-03 devnull They are distinct from files of the same name.
584 058b0118 2005-01-03 devnull .PD
585 058b0118 2005-01-03 devnull .SH EXAMPLES
586 058b0118 2005-01-03 devnull A simple mkfile to compile a program:
587 058b0118 2005-01-03 devnull .IP
588 058b0118 2005-01-03 devnull .EX
589 058b0118 2005-01-03 devnull .ta 8n +8n +8n +8n +8n +8n +8n
590 058b0118 2005-01-03 devnull </$objtype/mkfile
591 058b0118 2005-01-03 devnull
592 058b0118 2005-01-03 devnull prog: a.$O b.$O c.$O
593 058b0118 2005-01-03 devnull $LD $LDFLAGS -o $target $prereq
594 058b0118 2005-01-03 devnull
595 058b0118 2005-01-03 devnull %.$O: %.c
596 058b0118 2005-01-03 devnull $CC $CFLAGS $stem.c
597 058b0118 2005-01-03 devnull .EE
598 058b0118 2005-01-03 devnull .PP
599 058b0118 2005-01-03 devnull Override flag settings in the mkfile:
600 058b0118 2005-01-03 devnull .IP
601 058b0118 2005-01-03 devnull .EX
602 058b0118 2005-01-03 devnull % mk target 'CFLAGS=-S -w'
603 058b0118 2005-01-03 devnull .EE
604 058b0118 2005-01-03 devnull .PP
605 058b0118 2005-01-03 devnull Maintain a library:
606 058b0118 2005-01-03 devnull .IP
607 058b0118 2005-01-03 devnull .EX
608 058b0118 2005-01-03 devnull libc.a(%.$O):N: %.$O
609 058b0118 2005-01-03 devnull libc.a: libc.a(abs.$O) libc.a(access.$O) libc.a(alarm.$O) ...
610 058b0118 2005-01-03 devnull ar r libc.a $newmember
611 058b0118 2005-01-03 devnull .EE
612 058b0118 2005-01-03 devnull .PP
613 058b0118 2005-01-03 devnull String expression variables to derive names from a master list:
614 058b0118 2005-01-03 devnull .IP
615 058b0118 2005-01-03 devnull .EX
616 058b0118 2005-01-03 devnull NAMES=alloc arc bquote builtins expand main match mk var word
617 058b0118 2005-01-03 devnull OBJ=${NAMES:%=%.$O}
618 058b0118 2005-01-03 devnull .EE
619 058b0118 2005-01-03 devnull .PP
620 058b0118 2005-01-03 devnull Regular expression meta-rules:
621 058b0118 2005-01-03 devnull .IP
622 058b0118 2005-01-03 devnull .EX
623 058b0118 2005-01-03 devnull ([^/]*)/(.*)\e.$O:R: \e1/\e2.c
624 058b0118 2005-01-03 devnull cd $stem1; $CC $CFLAGS $stem2.c
625 058b0118 2005-01-03 devnull .EE
626 058b0118 2005-01-03 devnull .PP
627 058b0118 2005-01-03 devnull A correct way to deal with
628 d32deab1 2020-08-16 rsc .MR yacc (1)
629 058b0118 2005-01-03 devnull grammars.
630 058b0118 2005-01-03 devnull The file
631 058b0118 2005-01-03 devnull .B lex.c
632 058b0118 2005-01-03 devnull includes the file
633 058b0118 2005-01-03 devnull .B x.tab.h
634 058b0118 2005-01-03 devnull rather than
635 058b0118 2005-01-03 devnull .B y.tab.h
636 058b0118 2005-01-03 devnull in order to reflect changes in content, not just modification time.
637 058b0118 2005-01-03 devnull .IP
638 058b0118 2005-01-03 devnull .EX
639 058b0118 2005-01-03 devnull lex.$O: x.tab.h
640 058b0118 2005-01-03 devnull x.tab.h: y.tab.h
641 058b0118 2005-01-03 devnull cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
642 058b0118 2005-01-03 devnull y.tab.c y.tab.h: gram.y
643 058b0118 2005-01-03 devnull $YACC -d gram.y
644 058b0118 2005-01-03 devnull .EE
645 058b0118 2005-01-03 devnull .PP
646 058b0118 2005-01-03 devnull The above example could also use the
647 058b0118 2005-01-03 devnull .B P
648 058b0118 2005-01-03 devnull attribute for the
649 058b0118 2005-01-03 devnull .B x.tab.h
650 058b0118 2005-01-03 devnull rule:
651 058b0118 2005-01-03 devnull .IP
652 058b0118 2005-01-03 devnull .EX
653 058b0118 2005-01-03 devnull x.tab.h:Pcmp -s: y.tab.h
654 058b0118 2005-01-03 devnull cp y.tab.h x.tab.h
655 058b0118 2005-01-03 devnull .EE
656 93aa30a8 2005-01-14 devnull .SH SOURCE
657 adc93f60 2005-01-14 devnull .B \*9/src/cmd/mk
658 058b0118 2005-01-03 devnull .SH SEE ALSO
659 d32deab1 2020-08-16 rsc .MR sh (1) ,
660 d32deab1 2020-08-16 rsc .MR regexp (7)
661 058b0118 2005-01-03 devnull .PP
662 058b0118 2005-01-03 devnull A. Hume,
663 058b0118 2005-01-03 devnull ``Mk: a Successor to Make''
664 058b0118 2005-01-03 devnull (Tenth Edition Research Unix Manuals).
665 058b0118 2005-01-03 devnull .PP
666 058b0118 2005-01-03 devnull Andrew G. Hume and Bob Flandrena,
667 058b0118 2005-01-03 devnull ``Maintaining Files on Plan 9 with Mk''.
668 058b0118 2005-01-03 devnull DOCPREFIX/doc/mk.pdf
669 058b0118 2005-01-03 devnull .SH HISTORY
670 058b0118 2005-01-03 devnull Andrew Hume wrote
671 058b0118 2005-01-03 devnull .I mk
672 058b0118 2005-01-03 devnull for Tenth Edition Research Unix.
673 058b0118 2005-01-03 devnull It was later ported to Plan 9.
674 058b0118 2005-01-03 devnull This software is a port of the Plan 9 version back to Unix.
675 058b0118 2005-01-03 devnull .SH BUGS
676 058b0118 2005-01-03 devnull Identical recipes for regular expression meta-rules only have one target.
677 c8b6342d 2005-01-13 devnull .PP
678 058b0118 2005-01-03 devnull Seemingly appropriate input like
679 058b0118 2005-01-03 devnull .B CFLAGS=-DHZ=60
680 058b0118 2005-01-03 devnull is parsed as an erroneous attribute; correct it by inserting
681 058b0118 2005-01-03 devnull a space after the first
682 058b0118 2005-01-03 devnull .LR = .
683 c8b6342d 2005-01-13 devnull .PP
684 058b0118 2005-01-03 devnull The recipes printed by
685 058b0118 2005-01-03 devnull .I mk
686 058b0118 2005-01-03 devnull before being passed to
687 c8b6342d 2005-01-13 devnull the shell
688 058b0118 2005-01-03 devnull for execution are sometimes erroneously expanded
689 058b0118 2005-01-03 devnull for printing. Don't trust what's printed; rely
690 c8b6342d 2005-01-13 devnull on what the shell
691 058b0118 2005-01-03 devnull does.