Commit | Line | Data |
---|---|---|
f55d5308 C |
1 | .....TR 57 |
2 | .ND August 15, 1978 | |
3 | .RP | |
4 | .de IT | |
5 | .if n .ul | |
6 | \&\\$3\f2\\$1\fR\^\&\\$2 | |
7 | .. | |
8 | .TL | |
9 | Make \(em A Program for Maintaining Computer Programs | |
10 | .AU | |
11 | S. I. Feldman | |
12 | .AI | |
13 | .MH | |
14 | .AB | |
15 | .PP | |
16 | In a programming project, it is easy to lose track of which files need | |
17 | to be reprocessed or recompiled after a change is made in some part of the source. | |
18 | .I Make | |
19 | provides a simple mechanism for maintaining up-to-date versions of programs that result | |
20 | from many operations on a number of files. | |
21 | It is possible to tell | |
22 | .I Make | |
23 | the sequence of commands that create certain files, | |
24 | and the list of files that require other files to be current before the operations can be done. | |
25 | Whenever a change is made in any part of the program, | |
26 | the | |
27 | .I Make | |
28 | command will create the proper files simply, correctly, | |
29 | and with a minimum amount of effort. | |
30 | .PP | |
31 | The basic operation of | |
32 | .I Make | |
33 | is to find the name of a needed target in the description, ensure that all of the files on which it depends exist and | |
34 | are up to date, and then create the target if it has not been modified since its generators were. | |
35 | The description file really defines the graph of dependencies; | |
36 | .I Make | |
37 | does a depth-first search of this graph | |
38 | to determine what work is really necessary. | |
39 | .PP | |
40 | .I Make | |
41 | also provides a simple macro substitution facility | |
42 | and the ability to encapsulate commands in a single file | |
43 | for convenient administration. | |
44 | .AE | |
45 | .SH | |
46 | Introduction | |
47 | .PP | |
48 | It is common practice to divide large programs into smaller, more manageable pieces. | |
49 | The pieces may require quite different treatments: | |
50 | some may need to be run through a macro processor, some may need to be processed by | |
51 | a sophisticated program generator (e.g., Yacc[1] or Lex[2]). | |
52 | The outputs of these generators may then have to be compiled with special options and with | |
53 | certain definitions and declarations. | |
54 | The code resulting from these transformations may then need to be loaded together with | |
55 | certain libraries under the control of special options. | |
56 | Related maintenance activities involve running complicated test scripts | |
57 | and installing validated modules. | |
58 | Unfortunately, it is very easy for a programmer to forget which files depend on which others, | |
59 | which files have been modified recently, and the exact sequence of operations | |
60 | needed to make or exercise a new version of the program. | |
61 | After a long editing session, one may easily lose track of which files have been changed | |
62 | and which object modules are still valid, | |
63 | since a change to a declaration can obsolete a dozen other files. | |
64 | Forgetting to compile a routine that has been changed or that uses changed declarations will result in | |
65 | a program that will not work, and a bug that can be very hard to track down. | |
66 | On the other hand, recompiling everything in sight just to be safe is very wasteful. | |
67 | .PP | |
68 | The program described in this report mechanizes many of the activities of program development | |
69 | and maintenance. | |
70 | If the information on inter-file dependences and command sequences is stored in a file, the simple command | |
71 | .DS | |
72 | make | |
73 | .DE | |
74 | is frequently sufficient to update the interesting files, | |
75 | regardless of the number that have been edited since the last ``make''. | |
76 | In most cases, the description file is easy to write and changes infrequently. | |
77 | It is usually easier to type the | |
78 | .IT make | |
79 | command than to issue even one of the needed operations, so the typical cycle of program development operations becomes | |
80 | .DS | |
81 | think \(em edit \(em \fImake\fR \(em test . . . | |
82 | .DE | |
83 | .PP | |
84 | .IT Make | |
85 | is most useful for medium-sized programming projects; | |
86 | it does not solve the problems of maintaining multiple source versions | |
87 | or of describing huge programs. | |
88 | .IT Make | |
89 | was designed for use on Unix, but a version runs on GCOS. | |
90 | .SH | |
91 | Basic Features | |
92 | .PP | |
93 | The basic operation of | |
94 | .IT make | |
95 | is to update a target file by ensuring | |
96 | that all of the files on which it depends exist and are up to date, | |
97 | then creating the target if it has not been modified since its dependents were. | |
98 | .IT Make | |
99 | does a depth-first search of the graph of dependences. | |
100 | The operation of the command depends on the ability to find the date and time | |
101 | that a file was last modified. | |
102 | .PP | |
103 | To illustrate, let us consider a simple example: | |
104 | A program named | |
105 | .IT prog | |
106 | is made by compiling and loading three C-language files | |
107 | .IT x.c , | |
108 | .IT y.c , | |
109 | and | |
110 | .IT z.c | |
111 | with the | |
112 | .IT lS | |
113 | library. | |
114 | By convention, the output of the C compilations will be found in files named | |
115 | .IT x.o , | |
116 | .IT y.o , | |
117 | and | |
118 | .IT z.o . | |
119 | Assume that the files | |
120 | .IT x.c | |
121 | and | |
122 | .IT y.c | |
123 | share some declarations in a file named | |
124 | .IT defs , | |
125 | but that | |
126 | .IT z.c | |
127 | does not. | |
128 | That is, | |
129 | .IT x.c | |
130 | and | |
131 | .IT y.c | |
132 | have the line | |
133 | .DS | |
134 | #include "defs" | |
135 | .DE | |
136 | The following text describes the relationships and operations: | |
137 | .DS | |
138 | prog : x.o y.o z.o | |
139 | cc x.o y.o z.o \-lS \-o prog | |
140 | .sp .5 | |
141 | x.o y.o : defs | |
142 | .DE | |
143 | If this information were stored in a file named | |
144 | .IT makefile , | |
145 | the command | |
146 | .DS | |
147 | make | |
148 | .DE | |
149 | would perform the operations needed to recreate | |
150 | .IT prog | |
151 | after any changes had been made to any of the four source files | |
152 | .IT x.c , | |
153 | .IT y.c , | |
154 | .IT z.c , | |
155 | or | |
156 | .IT defs . | |
157 | .PP | |
158 | .IT Make | |
159 | operates using three sources of information: | |
160 | a user-supplied description file (as above), | |
161 | file names and ``last-modified'' times from the file system, | |
162 | and built-in rules to bridge some of the gaps. | |
163 | In our example, the first line says that | |
164 | .IT prog | |
165 | depends on three ``\fI.o\fR'' files. | |
166 | Once these object files are current, the second line describes how to load them to create | |
167 | .IT prog . | |
168 | The third line says that | |
169 | .IT x.o | |
170 | and | |
171 | .IT y.o | |
172 | depend on the file | |
173 | .IT defs . | |
174 | From the file system, | |
175 | .IT make | |
176 | discovers that there are three ``\fI.c\fR'' files corresponding to the needed ``\fI.o\fR'' files, | |
177 | and uses built-in information on how to generate an object from a source file | |
178 | (\fIi.e.,\fR issue a ``cc\ \-c'' command). | |
179 | .PP | |
180 | The following long-winded description file is equivalent to the one above, but | |
181 | takes no advantage of | |
182 | .IT make 's | |
183 | innate knowledge: | |
184 | .DS | |
185 | prog : x.o y.o z.o | |
186 | cc x.o y.o z.o \-lS \-o prog | |
187 | .sp .3 | |
188 | x.o : x.c defs | |
189 | cc \-c x.c | |
190 | y.o : y.c defs | |
191 | cc \-c y.c | |
192 | z.o : z.c | |
193 | cc \-c z.c | |
194 | .DE | |
195 | .PP | |
196 | If none of the source or object files had changed since the last time | |
197 | .IT prog | |
198 | was made, all of the files would be current, and | |
199 | the command | |
200 | .DS | |
201 | make | |
202 | .DE | |
203 | would just announce this fact and stop. | |
204 | If, however, the | |
205 | .IT defs | |
206 | file had been edited, | |
207 | .IT x.c | |
208 | and | |
209 | .IT y.c | |
210 | (but not | |
211 | .IT z.c ) | |
212 | would be recompiled, and then | |
213 | .IT prog | |
214 | would be created from the new ``\fI.o\fR'' files. | |
215 | If only the file | |
216 | .IT y.c | |
217 | had changed, only it would be recompiled, but it would still be necessary to reload | |
218 | .IT prog . | |
219 | .PP | |
220 | If no target name is given on the | |
221 | .IT make | |
222 | command line, the first target mentioned in the description is created; | |
223 | otherwise the specified targets are made. | |
224 | The command | |
225 | .DS | |
226 | make x.o | |
227 | .DE | |
228 | would recompile | |
229 | .IT x.o | |
230 | if | |
231 | .IT x.c | |
232 | or | |
233 | .IT defs | |
234 | had changed. | |
235 | .PP | |
236 | If the file exists after the commands are executed, | |
237 | its time of last modification is used in further decisions; | |
238 | otherwise the current time is used. | |
239 | It is often quite useful to include rules with mnemonic names and commands that do not | |
240 | actually produce a file with that name. | |
241 | These entries can take advantage of | |
242 | .IT make 's | |
243 | ability to generate files and substitute macros. | |
244 | Thus, an entry | |
245 | ``save'' | |
246 | might be included to copy a certain set of files, or an entry | |
247 | ``cleanup'' | |
248 | might be used to throw away unneeded intermediate files. | |
249 | In other cases one may maintain a zero-length file purely to keep track | |
250 | of the time at which certain actions were performed. | |
251 | This technique is useful for maintaining remote archives and listings. | |
252 | .PP | |
253 | .IT Make | |
254 | has a simple macro mechanism for substituting in dependency lines and command strings. | |
255 | Macros are defined by command arguments or description file lines with embedded equal signs. | |
256 | A macro is invoked by preceding the name by a dollar sign; | |
257 | macro names longer than one character must be parenthesized. | |
258 | The name of the macro is either the single character after the dollar sign or a name inside parentheses. | |
259 | The following are valid macro invocations: | |
260 | .DS | |
261 | $(CFLAGS) | |
262 | $2 | |
263 | $(xy) | |
264 | $Z | |
265 | $(Z) | |
266 | .DE | |
267 | The last two invocations are identical. | |
268 | $$ is a dollar sign. | |
269 | All of these macros are assigned values during input, as shown below. | |
270 | Four special macros change values during the execution of the command: | |
271 | $\(**, $@, $?, and $<. | |
272 | They will be discussed later. | |
273 | The following fragment shows the use: | |
274 | .DS | |
275 | OBJECTS = x.o y.o z.o | |
276 | LIBES = \-lS | |
277 | prog: $(OBJECTS) | |
278 | cc $(OBJECTS) $(LIBES) \-o prog | |
279 | . . . | |
280 | .DE | |
281 | The command | |
282 | .DS | |
283 | make | |
284 | .DE | |
285 | loads the three object files with the | |
286 | .IT lS | |
287 | library. The command | |
288 | .DS | |
289 | make "LIBES= \-ll \-lS" | |
290 | .DE | |
291 | loads them with both the Lex (``\-ll'') and the Standard (``\-lS'') libraries, | |
292 | since macro definitions on the command line override definitions in the description. | |
293 | (It is necessary to quote arguments with embedded blanks in | |
294 | .UX | |
295 | commands.) | |
296 | .PP | |
297 | The following sections detail the form of description files and the command line, | |
298 | and discuss options and built-in rules in more detail. | |
299 | .SH | |
300 | Description Files and Substitutions | |
301 | .PP | |
302 | A description file contains three types of information: | |
303 | macro definitions, | |
304 | dependency information, | |
305 | and executable commands. | |
306 | There is also a comment convention: | |
307 | all characters after a sharp (#) are ignored, as is the sharp itself. | |
308 | Blank lines and lines beginning with a sharp are totally ignored. | |
309 | If a non-comment line is too long, it can be continued using a backslash. | |
310 | If the last character of a line is a backslash, the backslash, newline, | |
311 | and following blanks and tabs are replaced by a single blank. | |
312 | .PP | |
313 | A macro definition is a line containing an equal sign not preceded by a colon or a tab. | |
314 | The name (string of letters and digits) to the left of the equal sign | |
315 | (trailing blanks and tabs are stripped) is assigned the string of characters following the equal sign | |
316 | (leading blanks and tabs are stripped.) | |
317 | The following are valid macro definitions: | |
318 | .DS | |
319 | 2 = xyz | |
320 | abc = \-ll \-ly \-lS | |
321 | LIBES = | |
322 | .DE | |
323 | The last definition assigns LIBES the null string. | |
324 | A macro that is never explicitly defined has the null string as value. | |
325 | Macro definitions may also appear on the | |
326 | .IT make | |
327 | command line (see below). | |
328 | .PP | |
329 | Other lines give information about target files. | |
330 | The general form of an entry is: | |
331 | .DS | |
332 | target1 [target2 . . .] :[:] [dependent1 . . .] [; commands] [# . . .] | |
333 | [\fI(tab)\fR commands] [# . . .] | |
334 | . . . | |
335 | .DE | |
336 | Items inside brackets may be omitted. | |
337 | Targets and dependents are strings of letters, digits, periods, and slashes. | |
338 | (Shell metacharacters ``\(**'' and ``?'' are expanded.) | |
339 | A command is any string of characters not including a sharp (except in quotes) | |
340 | or newline. | |
341 | Commands may appear either after a semicolon on a dependency line | |
342 | or on lines beginning with a tab immediately following a dependency line. | |
343 | .PP | |
344 | A dependency line may have either a single or a double colon. | |
345 | A target name may appear on more than one dependency line, but all of those lines must be of the | |
346 | same (single or double colon) type. | |
347 | .IP 1. | |
348 | For the usual single-colon case, | |
349 | at most one of these dependency lines may have a command sequence associated with it. | |
350 | If the target is out of date with any of the dependents on any of the lines, | |
351 | and a command sequence is specified (even a null one following a semicolon or tab), | |
352 | it is executed; otherwise a default creation rule may be invoked. | |
353 | .IP 2. | |
354 | In the double-colon case, a command sequence may be associated with each dependency line; | |
355 | if the target is out of date with any of the files on a particular line, the associated | |
356 | commands are executed. | |
357 | A built-in rule may also be executed. | |
358 | This detailed form is of particular value in updating archive-type files. | |
359 | .PP | |
360 | If a target must be created, the sequence of commands is executed. | |
361 | Normally, each command line is printed and then | |
362 | passed to a separate invocation of the Shell after substituting for macros. | |
363 | (The printing is suppressed in silent mode or if the command line begins with an @ sign). | |
364 | .IT Make | |
365 | normally stops if any command signals an error by returning a non-zero error code. | |
366 | (Errors are ignored if the ``\-i'' flags has been specified on the | |
367 | .IT make | |
368 | command line, | |
369 | if the fake target name ``.IGNORE'' appears in the description file, | |
370 | or if the command string in the description file begins with a hyphen. | |
371 | Some | |
372 | .UX | |
373 | commands return meaningless status). | |
374 | Because each command line is passed to a separate invocation of the Shell, | |
375 | care must be taken with certain commands (e.g., \fIcd\fR and Shell control commands) that have meaning only | |
376 | within a single Shell process; | |
377 | the results are forgotten before the next line is executed. | |
378 | .PP | |
379 | Before issuing any command, certain macros are set. | |
380 | $@ is set to the name of the file to be ``made''. | |
381 | $? is set to the string of names that were found to be younger than the target. | |
382 | If the command was generated by an implicit rule (see below), | |
383 | $< is the name of the related file that caused the action, and | |
384 | $\(** is the prefix shared by the current and the dependent file names. | |
385 | .PP | |
386 | If a file must be made but there are no explicit commands or relevant | |
387 | built-in rules, | |
388 | the commands associated with the name ``.DEFAULT'' are used. | |
389 | If there is no such name, | |
390 | .IT make | |
391 | prints a message and stops. | |
392 | .SH | |
393 | Command Usage | |
394 | .PP | |
395 | The | |
396 | .IT make | |
397 | command takes four kinds of arguments: | |
398 | macro definitions, flags, description file names, and target file names. | |
399 | .DS | |
400 | make [ flags ] [ macro definitions ] [ targets ] | |
401 | .DE | |
402 | The following summary of the operation of the command explains how these arguments are interpreted. | |
403 | .PP | |
404 | First, all macro definition arguments (arguments with embedded equal signs) are analyzed | |
405 | and the assignments made. | |
406 | Command-line macros override corresponding definitions found in the description files. | |
407 | .PP | |
408 | Next, the flag arguments are examined. | |
409 | The permissible flags are | |
410 | .IP \-i | |
411 | Ignore error codes returned by invoked commands. | |
412 | This mode is entered if the fake target name ``.IGNORE'' appears in the description file. | |
413 | .IP \-s | |
414 | Silent mode. Do not print command lines before executing. | |
415 | This mode is also entered if the fake target name ``.SILENT'' appears in the description file. | |
416 | .IP \-r | |
417 | Do not use the built-in rules. | |
418 | .IP \-n | |
419 | No execute mode. Print commands, but do not execute them. | |
420 | Even lines beginning with an ``@'' sign are printed. | |
421 | .IP \-t | |
422 | Touch the target files (causing them to be up to date) rather than issue the usual commands. | |
423 | .IP \-q | |
424 | Question. | |
425 | The | |
426 | .IT make | |
427 | command returns a zero or non-zero status code depending on whether the target file | |
428 | is or is not up to date. | |
429 | .IP \-p | |
430 | Print out the complete set of macro definitions and target descriptions | |
431 | .IP \-d | |
432 | Debug mode. Print out detailed information on files and times examined. | |
433 | .IP \-f | |
434 | Description file name. The next argument is assumed to be the name of a description file. | |
435 | A file name of ``\-'' denotes the standard input. | |
436 | If there are no ``\-f\|'' arguments, the file named | |
437 | .IT makefile | |
438 | or | |
439 | .IT Makefile | |
440 | in the current directory is read. | |
441 | The contents of the description files override the built-in rules if they are present). | |
442 | .PP | |
443 | Finally, the remaining arguments are assumed to be the names of targets to be made; | |
444 | they are done in left to right order. | |
445 | If there are no such arguments, the first name in the description files that does not | |
446 | begin with a period is ``made''. | |
447 | .SH | |
448 | Implicit Rules | |
449 | .PP | |
450 | The | |
451 | .ul | |
452 | make | |
453 | program uses a table of interesting suffixes and a set | |
454 | of transformation rules to supply default dependency | |
455 | information and implied commands. | |
456 | (The Appendix describes these tables and means of overriding | |
457 | them.) | |
458 | The default suffix list is: | |
459 | .KS | |
460 | .sp | |
461 | .nf | |
462 | .ta 0.5i 1.5i | |
463 | \fI.o\fR Object file | |
464 | \fI.c\fR C source file | |
465 | \fI.e\fR Efl source file | |
466 | \fI.r\fR Ratfor source file | |
467 | \fI.f\fR Fortran source file | |
468 | \fI.s\fR Assembler source file | |
469 | \fI.y\fR Yacc-C source grammar | |
470 | \fI.yr\fR Yacc-Ratfor source grammar | |
471 | \fI.ye\fR Yacc-Efl source grammar | |
472 | \fI.l\fR Lex source grammar | |
473 | .fi | |
474 | .sp | |
475 | .KE | |
476 | The following diagram summarizes the default transformation paths. | |
477 | If there are two paths connecting a pair of suffixes, the longer | |
478 | one is used only if the intermediate file exists or is | |
479 | named in the description. | |
480 | .KS | |
481 | .sp | |
482 | .ft I | |
483 | .ta 2i | |
484 | .o | |
485 | .sp 2 | |
486 | .ta 0.75i 1.25i 1.6i 2.1i | |
487 | .c .r .e .f .s .y .yr .ye .l .d | |
488 | .sp 2 | |
489 | .ta 0.6i 1.25i 1.6i | |
490 | .y .l .yr .ye | |
491 | .ft R | |
492 | .sp | |
493 | .KE | |
494 | .PP | |
495 | If the file | |
496 | .ul | |
497 | x.o | |
498 | were needed and there were an | |
499 | .ul | |
500 | x.c | |
501 | in the description or directory, it would be compiled. | |
502 | If there were also an | |
503 | .IT x.l , | |
504 | that grammar would be run through Lex before compiling the result. | |
505 | However, if there were no | |
506 | .ul | |
507 | x.c | |
508 | but there were an | |
509 | .IT x.l , | |
510 | .IT make | |
511 | would discard the intermediate C-language file and use the | |
512 | direct link in the graph above. | |
513 | .PP | |
514 | It is possible to change the names of some of the compilers used in the | |
515 | default, or the flag arguments with which they are invoked by knowing | |
516 | the macro names used. | |
517 | The compiler names are the macros AS, CC, RC, EC, YACC, YACCR, YACCE, and LEX. | |
518 | The command | |
519 | .DS | |
520 | make CC=newcc | |
521 | .DE | |
522 | will cause the ``newcc'' command to be used instead of the | |
523 | usual C compiler. | |
524 | The macros CFLAGS, RFLAGS, EFLAGS, YFLAGS, and LFLAGS may be set to | |
525 | cause these commands to be issued with optional flags. | |
526 | Thus, | |
527 | .DS | |
528 | make "CFLAGS=\|\(miO" | |
529 | .DE | |
530 | causes the optimizing C compiler to be used. | |
531 | .SH | |
532 | Example | |
533 | .PP | |
534 | As an example of the use of | |
535 | .ul | |
536 | make, | |
537 | we will present the description file used to maintain | |
538 | the | |
539 | .ul | |
540 | make | |
541 | command itself. | |
542 | The code for | |
543 | .ul | |
544 | make | |
545 | is spread over a number of C source files and a Yacc grammar. | |
546 | The description file contains: | |
547 | .DS | |
548 | # Description file for the Make command | |
549 | .sp .3 | |
550 | P = und \-3 | opr \-r2 # send to GCOS to be printed | |
551 | FILES = Makefile version.c defs main.c doname.c misc.c files.c dosys.c\ | |
552 | gram.y lex.c gcos.c | |
553 | OBJECTS = version.o main.o doname.o misc.o files.o dosys.o gram.o | |
554 | LIBES= \-lS | |
555 | LINT = lint \-p | |
556 | CFLAGS = \-O | |
557 | .sp .3 | |
558 | make: $(OBJECTS) | |
559 | cc $(CFLAGS) $(OBJECTS) $(LIBES) \-o make | |
560 | size make | |
561 | .sp .3 | |
562 | $(OBJECTS): defs | |
563 | gram.o: lex.c | |
564 | .sp .3 | |
565 | cleanup: | |
566 | -rm *.o gram.c | |
567 | -du | |
568 | .sp .3 | |
569 | install: | |
570 | @size make /usr/bin/make | |
571 | cp make /usr/bin/make ; rm make | |
572 | .sp .3 | |
573 | print: $(FILES) # print recently changed files | |
574 | pr $? | $P | |
575 | touch print | |
576 | .sp .3 | |
577 | test: | |
578 | make \-dp | grep \-v TIME >1zap | |
579 | /usr/bin/make \-dp | grep \-v TIME >2zap | |
580 | diff 1zap 2zap | |
581 | rm 1zap 2zap | |
582 | .sp .3 | |
583 | lint : dosys.c doname.c files.c main.c misc.c version.c gram.c | |
584 | $(LINT) dosys.c doname.c files.c main.c misc.c version.c gram.c | |
585 | rm gram.c | |
586 | .sp .3 | |
587 | arch: | |
588 | ar uv /sys/source/s2/make.a $(FILES) | |
589 | .DE | |
590 | .IT Make | |
591 | usually prints out each command before issuing it. | |
592 | The following output results from typing the simple command | |
593 | .DS | |
594 | make | |
595 | .DE | |
596 | in a directory containing only the source and description file: | |
597 | .DS | |
598 | cc \-c version.c | |
599 | cc \-c main.c | |
600 | cc \-c doname.c | |
601 | cc \-c misc.c | |
602 | cc \-c files.c | |
603 | cc \-c dosys.c | |
604 | yacc gram.y | |
605 | mv y.tab.c gram.c | |
606 | cc \-c gram.c | |
607 | cc version.o main.o doname.o misc.o files.o dosys.o gram.o \-lS \-o make | |
608 | 13188+3348+3044 = 19580b = 046174b | |
609 | .DE | |
610 | Although none of the source files or grammars were mentioned | |
611 | by name in the description file, | |
612 | .IT make | |
613 | found them using its suffix rules and issued the needed commands. | |
614 | The string of digits results from the ``size make'' | |
615 | command; the printing of the command line itself was | |
616 | suppressed by an @ sign. | |
617 | The @ sign on the | |
618 | .IT size | |
619 | command in the description file suppressed the printing of the command, | |
620 | so only the sizes are written. | |
621 | .PP | |
622 | The last few entries in the description file are useful maintenance sequences. | |
623 | The ``print'' entry prints only the files that have been changed since the last | |
624 | ``make print'' command. | |
625 | A zero-length file | |
626 | .IT print | |
627 | is maintained to keep track of the time of the printing; | |
628 | the $? macro in the command line then picks up only the names of the files | |
629 | changed since | |
630 | .IT print | |
631 | was touched. | |
632 | The printed output can be sent to a different printer or to a file by changing the definition of the | |
633 | .IT P | |
634 | macro: | |
635 | .DS | |
636 | make print "P = opr \-sp" | |
637 | \fIor\fR | |
638 | make print "P= cat >zap" | |
639 | .DE | |
640 | .SH | |
641 | Suggestions and Warnings | |
642 | .PP | |
643 | The most common difficulties arise from | |
644 | .IT make 's | |
645 | specific meaning of dependency. | |
646 | If file | |
647 | .IT x.c | |
648 | has a ``#include "defs"'' | |
649 | line, then the object file | |
650 | .IT x.o | |
651 | depends on | |
652 | .IT defs ; | |
653 | the source file | |
654 | .IT x.c | |
655 | does not. | |
656 | (If | |
657 | .IT defs | |
658 | is changed, it is not necessary to do anything | |
659 | to the file | |
660 | .IT x.c , | |
661 | while it is necessary to recreate | |
662 | .IT x.o .) | |
663 | .PP | |
664 | To discover what | |
665 | .IT make | |
666 | would do, the ``\-n'' option is very useful. | |
667 | The command | |
668 | .DS | |
669 | make \-n | |
670 | .DE | |
671 | orders | |
672 | .IT make | |
673 | to print out the commands it would issue without actually taking the time to execute them. | |
674 | If a change to a file is absolutely certain to be benign | |
675 | (e.g., adding a new definition to an include file), | |
676 | the ``\-t'' (touch) option | |
677 | can save a lot of time: | |
678 | instead of issuing a large number of superfluous recompilations, | |
679 | .IT make | |
680 | updates the modification times on the affected file. | |
681 | Thus, the command | |
682 | .DS | |
683 | make \-ts | |
684 | .DE | |
685 | (``touch silently'') causes the relevant files to appear up to date. | |
686 | Obvious care is necessary, since this mode of operation subverts | |
687 | the intention of | |
688 | .IT make | |
689 | and destroys all memory of the previous relationships. | |
690 | .PP | |
691 | The debugging flag (``\-d'') causes | |
692 | .IT make | |
693 | to print out a very detailed description of what it is doing, including the | |
694 | file times. The output is verbose, and recommended only as a last resort. | |
695 | .SH | |
696 | Acknowledgments | |
697 | .PP | |
698 | I would like to thank S. C. Johnson for suggesting this approach | |
699 | to program maintenance control. | |
700 | I would like to thank S. C. Johnson and H. Gajewska for being | |
701 | the prime guinea pigs during development of | |
702 | .IT make . | |
703 | .SH | |
704 | References | |
705 | .IP 1. | |
706 | S. C. Johnson, | |
707 | ``Yacc \(em Yet Another Compiler-Compiler'', | |
708 | Bell Laboratories | |
709 | Computing Science Technical Report #32, | |
710 | July 1978. | |
711 | .IP 2. | |
712 | M. E. Lesk, | |
713 | ``Lex \(em A Lexical Analyzer Generator'', | |
714 | Computing Science Technical Report #39, | |
715 | October 1975. | |
716 | .bp | |
717 | .SH | |
718 | Appendix. Suffixes and Transformation Rules | |
719 | .PP | |
720 | The | |
721 | .ul | |
722 | make | |
723 | program itself does not know what file name suffixes are interesting | |
724 | or how to transform a file with one suffix into a file with another | |
725 | suffix. | |
726 | This information is stored in an internal table that has the form of a description file. | |
727 | If the ``\-r'' flag is used, this table is not used. | |
728 | .PP | |
729 | The list of suffixes is actually the dependency list for the name | |
730 | ``.SUFFIXES''; | |
731 | .ul | |
732 | make | |
733 | looks for a file with any of the suffixes on the list. | |
734 | If such a file exists, and if there is a transformation | |
735 | rule for that combination, | |
736 | .ul | |
737 | make | |
738 | acts as described earlier. | |
739 | The transformation rule names are the concatenation of the | |
740 | two suffixes. | |
741 | The name of the rule to transform a ``\fI.r\fR'' file to a ``\fI.o\fR'' file | |
742 | is thus ``\fI.r.o\fR''. | |
743 | If the rule is present and no explicit command sequence | |
744 | has been given in the user's description files, the command | |
745 | sequence for the rule ``.r.o'' is used. | |
746 | If a command is generated by using one of these suffixing rules, | |
747 | the macro $\(** is given the value of the stem | |
748 | (everything but the suffix) of the name of the file to be made, | |
749 | and the macro $< is the name of the dependent that caused the action. | |
750 | .PP | |
751 | The order of the suffix list is significant, since it is scanned from | |
752 | left to right, and the first name that is formed that has both a file | |
753 | and a rule associated with it is used. | |
754 | If new names are to be appended, the user can just add an entry for | |
755 | ``.SUFFIXES'' in his own description file; the dependents will be added to the usual list. | |
756 | A ``.SUFFIXES'' line without any dependents deletes the current list. | |
757 | (It is necessary to clear the current list if the order of names is to be changed). | |
758 | .PP | |
759 | The following is an excerpt from the default rules file: | |
760 | .DS | |
761 | .ta .5i 1i | |
762 | .SUFFIXES : .o .c .e .r .f .y .yr .ye .l .s | |
763 | YACC=yacc | |
764 | YACCR=yacc \-r | |
765 | YACCE=yacc \-e | |
766 | YFLAGS= | |
767 | LEX=lex | |
768 | LFLAGS= | |
769 | CC=cc | |
770 | AS=as \- | |
771 | CFLAGS= | |
772 | RC=ec | |
773 | RFLAGS= | |
774 | EC=ec | |
775 | EFLAGS= | |
776 | FFLAGS= | |
777 | .c.o : | |
778 | $(CC) $(CFLAGS) \-c $< | |
779 | .e.o .r.o .f.o : | |
780 | $(EC) $(RFLAGS) $(EFLAGS) $(FFLAGS) \-c $< | |
781 | .s.o : | |
782 | $(AS) \-o $@ $< | |
783 | .y.o : | |
784 | $(YACC) $(YFLAGS) $< | |
785 | $(CC) $(CFLAGS) \-c y.tab.c | |
786 | rm y.tab.c | |
787 | mv y.tab.o $@ | |
788 | .y.c : | |
789 | $(YACC) $(YFLAGS) $< | |
790 | mv y.tab.c $@ | |
791 | .DE |