📄 make
字号:
command takes four kinds of arguments:macro definitions, flags, description file names, and target file names..DSmake [ flags ] [ macro definitions ] [ targets ].DEThe following summary of the operation of the command explains how these arguments are interpreted..PPFirst, all macro definition arguments (arguments with embedded equal signs) are analyzedand the assignments made.Command-line macros override corresponding definitions found in the description files..PPNext, the flag arguments are examined.The permissible flags are.IP \-iIgnore error codes returned by invoked commands.This mode is entered if the fake target name ``.IGNORE'' appears in the description file..IP \-sSilent mode. Do not print command lines before executing.This mode is also entered if the fake target name ``.SILENT'' appears in the description file..IP \-rDo not use the built-in rules..IP \-nNo execute mode. Print commands, but do not execute them.Even lines beginning with an ``@'' sign are printed..IP \-tTouch the target files (causing them to be up to date) rather than issue the usual commands..IP \-qQuestion.The.IT makecommand returns a zero or non-zero status code depending on whether the target fileis or is not up to date..IP \-pPrint out the complete set of macro definitions and target descriptions.IP \-dDebug mode. Print out detailed information on files and times examined..IP \-fDescription file name. The next argument is assumed to be the name of a description file.A file name of ``\-'' denotes the standard input.If there are no ``\-f\|'' arguments, the file named.IT makefileor.IT Makefilein the current directory is read.The contents of the description files override the built-in rules if they are present)..PPFinally, the remaining arguments are assumed to be the names of targets to be made;they are done in left to right order.If there are no such arguments, the first name in the description files that does notbegin with a period is ``made''..SHImplicit Rules.PPThe.ulmakeprogram uses a table of interesting suffixes and a setof transformation rules to supply default dependencyinformation and implied commands.(The Appendix describes these tables and means of overridingthem.)The default suffix list is:.KS.sp.nf.ta 0.5i 1.5i \fI.o\fR Object file \fI.c\fR C source file \fI.e\fR Efl source file \fI.r\fR Ratfor source file \fI.f\fR Fortran source file \fI.s\fR Assembler source file \fI.y\fR Yacc-C source grammar \fI.yr\fR Yacc-Ratfor source grammar \fI.ye\fR Yacc-Efl source grammar \fI.l\fR Lex source grammar.fi.sp.KEThe following diagram summarizes the default transformation paths.If there are two paths connecting a pair of suffixes, the longerone is used only if the intermediate file exists or isnamed in the description..KS.sp.ft I.ta 2i .o.sp 2.ta 0.75i 1.25i 1.6i 2.1i .c .r .e .f .s .y .yr .ye .l .d.sp 2.ta 0.6i 1.25i 1.6i .y .l .yr .ye.ft R.sp.KE.PPIf the file.ulx.owere needed and there were an.ulx.cin the description or directory, it would be compiled.If there were also an.IT x.l ,that grammar would be run through Lex before compiling the result.However, if there were no.ulx.cbut there were an.IT x.l ,.IT makewould discard the intermediate C-language file and use thedirect link in the graph above..PPIt is possible to change the names of some of the compilers used in thedefault, or the flag arguments with which they are invoked by knowingthe macro names used.The compiler names are the macros AS, CC, RC, EC, YACC, YACCR, YACCE, and LEX.The command.DSmake CC=newcc.DEwill cause the ``newcc'' command to be used instead of theusual C compiler.The macros CFLAGS, RFLAGS, EFLAGS, YFLAGS, and LFLAGS may be set tocause these commands to be issued with optional flags.Thus,.DSmake "CFLAGS=\|\(miO".DEcauses the optimizing C compiler to be used..SHExample.PPAs an example of the use of.ulmake,we will present the description file used to maintainthe.ulmakecommand itself.The code for.ulmakeis spread over a number of C source files and a Yacc grammar.The description file contains:.DS# Description file for the Make command.sp .3P = und \-3 | opr \-r2 # send to GCOS to be printedFILES = Makefile version.c defs main.c doname.c misc.c files.c dosys.c\ gram.y lex.c gcos.cOBJECTS = version.o main.o doname.o misc.o files.o dosys.o gram.oLIBES= \-lSLINT = lint \-pCFLAGS = \-O.sp .3make: $(OBJECTS) cc $(CFLAGS) $(OBJECTS) $(LIBES) \-o make size make.sp .3$(OBJECTS): defsgram.o: lex.c.sp .3cleanup: -rm *.o gram.c -du.sp .3install: @size make /usr/bin/make cp make /usr/bin/make ; rm make.sp .3print: $(FILES) # print recently changed files pr $? | $P touch print.sp .3test: make \-dp | grep \-v TIME >1zap /usr/bin/make \-dp | grep \-v TIME >2zap diff 1zap 2zap rm 1zap 2zap.sp .3lint : dosys.c doname.c files.c main.c misc.c version.c gram.c $(LINT) dosys.c doname.c files.c main.c misc.c version.c gram.c rm gram.c.sp .3arch: ar uv /sys/source/s2/make.a $(FILES).DE.IT Makeusually prints out each command before issuing it.The following output results from typing the simple command.DSmake.DEin a directory containing only the source and description file:.DS cc \-c version.c cc \-c main.c cc \-c doname.c cc \-c misc.c cc \-c files.c cc \-c dosys.c yacc gram.y mv y.tab.c gram.c cc \-c gram.c cc version.o main.o doname.o misc.o files.o dosys.o gram.o \-lS \-o make 13188+3348+3044 = 19580b = 046174b.DEAlthough none of the source files or grammars were mentionedby name in the description file,.IT makefound them using its suffix rules and issued the needed commands.The string of digits results from the ``size make''command; the printing of the command line itself wassuppressed by an @ sign.The @ sign on the.IT sizecommand in the description file suppressed the printing of the command,so only the sizes are written..PPThe last few entries in the description file are useful maintenance sequences.The ``print'' entry prints only the files that have been changed since the last``make print'' command.A zero-length file.IT printis maintained to keep track of the time of the printing;the $? macro in the command line then picks up only the names of the fileschanged since.IT printwas touched.The printed output can be sent to a different printer or to a file by changing the definition of the.IT Pmacro:.DSmake print "P = opr \-sp" \fIor\fRmake print "P= cat >zap".DE.SHSuggestions and Warnings.PPThe most common difficulties arise from.IT make 'sspecific meaning of dependency.If file.IT x.chas a ``#include "defs"''line, then the object file.IT x.odepends on.IT defs ;the source file.IT x.cdoes not.(If.IT defsis changed, it is not necessary to do anythingto the file.IT x.c ,while it is necessary to recreate.IT x.o .).PPTo discover what.IT makewould do, the ``\-n'' option is very useful.The command.DSmake \-n.DEorders.IT maketo print out the commands it would issue without actually taking the time to execute them.If a change to a file is absolutely certain to be benign(e.g., adding a new definition to an include file),the ``\-t'' (touch) optioncan save a lot of time:instead of issuing a large number of superfluous recompilations,.IT makeupdates the modification times on the affected file.Thus, the command.DSmake \-ts.DE(``touch silently'') causes the relevant files to appear up to date.Obvious care is necessary, since this mode of operation subvertsthe intention of.IT makeand destroys all memory of the previous relationships..PPThe debugging flag (``\-d'') causes.IT maketo print out a very detailed description of what it is doing, including thefile times. The output is verbose, and recommended only as a last resort..SHAcknowledgments.PPI would like to thank S. C. Johnson for suggesting this approachto program maintenance control.I would like to thank S. C. Johnson and H. Gajewska for beingthe prime guinea pigs during development of.IT make ..SHReferences.IP 1.S. C. Johnson,``Yacc \(em Yet Another Compiler-Compiler'',Bell LaboratoriesComputing Science Technical Report #32,July 1978..IP 2.M. E. Lesk,``Lex \(em A Lexical Analyzer Generator'',Computing Science Technical Report #39,October 1975..bp.SHAppendix. Suffixes and Transformation Rules.PPThe.ulmakeprogram itself does not know what file name suffixes are interestingor how to transform a file with one suffix into a file with anothersuffix.This information is stored in an internal table that has the form of a description file.If the ``\-r'' flag is used, this table is not used..PPThe list of suffixes is actually the dependency list for the name``.SUFFIXES'';.ulmakelooks for a file with any of the suffixes on the list.If such a file exists, and if there is a transformationrule for that combination,.ulmakeacts as described earlier.The transformation rule names are the concatenation of thetwo suffixes.The name of the rule to transform a ``\fI.r\fR'' file to a ``\fI.o\fR'' fileis thus ``\fI.r.o\fR''.If the rule is present and no explicit command sequencehas been given in the user's description files, the commandsequence for the rule ``.r.o'' is used.If a command is generated by using one of these suffixing rules,the macro $\(** is given the value of the stem(everything but the suffix) of the name of the file to be made,and the macro $< is the name of the dependent that caused the action..PPThe order of the suffix list is significant, since it is scanned fromleft to right, and the first name that is formed that has both a fileand a rule associated with it is used.If new names are to be appended, the user can just add an entry for``.SUFFIXES'' in his own description file; the dependents will be added to the usual list.A ``.SUFFIXES'' line without any dependents deletes the current list.(It is necessary to clear the current list if the order of names is to be changed)..PPThe following is an excerpt from the default rules file:.DS.ta .5i 1i .SUFFIXES : .o .c .e .r .f .y .yr .ye .l .s YACC=yacc YACCR=yacc \-r YACCE=yacc \-e YFLAGS= LEX=lex LFLAGS= CC=cc AS=as \- CFLAGS= RC=ec RFLAGS= EC=ec EFLAGS= FFLAGS= .c.o : $(CC) $(CFLAGS) \-c $< .e.o .r.o .f.o : $(EC) $(RFLAGS) $(EFLAGS) $(FFLAGS) \-c $< .s.o : $(AS) \-o $@ $< .y.o : $(YACC) $(YFLAGS) $< $(CC) $(CFLAGS) \-c y.tab.c rm y.tab.c mv y.tab.o $@ .y.c : $(YACC) $(YFLAGS) $< mv y.tab.c $@.DE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -