?? make
字號(hào):
.....TR 57.ND August 15, 1978.RP.de IT.if n .ul\&\\$3\f2\\$1\fR\^\&\\$2...TLMake \(em A Program for Maintaining Computer Programs.AUS. I. Feldman.AI.MH.AB.PPIn a programming project, it is easy to lose track of which files needto be reprocessed or recompiled after a change is made in some part of the source..I Makeprovides a simple mechanism for maintaining up-to-date versions of programs that resultfrom many operations on a number of files.It is possible to tell.I Makethe sequence of commands that create certain files,and the list of files that require other files to be current before the operations can be done.Whenever a change is made in any part of the program,the.I Makecommand will create the proper files simply, correctly,and with a minimum amount of effort..PPThe basic operation of.I Makeis to find the name of a needed target in the description, ensure that all of the files on which it depends exist andare up to date, and then create the target if it has not been modified since its generators were.The description file really defines the graph of dependencies;.I Makedoes a depth-first search of this graphto determine what work is really necessary..PP.I Makealso provides a simple macro substitution facilityand the ability to encapsulate commands in a single filefor convenient administration..AE.SHIntroduction.PPIt is common practice to divide large programs into smaller, more manageable pieces.The pieces may require quite different treatments:some may need to be run through a macro processor, some may need to be processed bya sophisticated program generator (e.g., Yacc[1] or Lex[2]).The outputs of these generators may then have to be compiled with special options and withcertain definitions and declarations.The code resulting from these transformations may then need to be loaded together withcertain libraries under the control of special options.Related maintenance activities involve running complicated test scriptsand installing validated modules.Unfortunately, it is very easy for a programmer to forget which files depend on which others,which files have been modified recently, and the exact sequence of operationsneeded to make or exercise a new version of the program.After a long editing session, one may easily lose track of which files have been changedand which object modules are still valid,since a change to a declaration can obsolete a dozen other files.Forgetting to compile a routine that has been changed or that uses changed declarations will result ina program that will not work, and a bug that can be very hard to track down.On the other hand, recompiling everything in sight just to be safe is very wasteful..PPThe program described in this report mechanizes many of the activities of program developmentand maintenance.If the information on inter-file dependences and command sequences is stored in a file, the simple command.DSmake.DEis frequently sufficient to update the interesting files,regardless of the number that have been edited since the last ``make''.In most cases, the description file is easy to write and changes infrequently.It is usually easier to type the.IT makecommand than to issue even one of the needed operations, so the typical cycle of program development operations becomes.DSthink \(em edit \(em \fImake\fR \(em test . . ..DE.PP.IT Makeis most useful for medium-sized programming projects;it does not solve the problems of maintaining multiple source versionsor of describing huge programs..IT Makewas designed for use on Unix, but a version runs on GCOS..SHBasic Features.PPThe basic operation of.IT makeis to update a target file by ensuringthat all of the files on which it depends exist and are up to date,then creating the target if it has not been modified since its dependents were..IT Makedoes a depth-first search of the graph of dependences.The operation of the command depends on the ability to find the date and timethat a file was last modified..PPTo illustrate, let us consider a simple example:A program named.IT progis made by compiling and loading three C-language files.IT x.c ,.IT y.c ,and.IT z.cwith the.IT lSlibrary.By convention, the output of the C compilations will be found in files named.IT x.o ,.IT y.o ,and.IT z.o .Assume that the files.IT x.cand.IT y.cshare some declarations in a file named.IT defs ,but that.IT z.cdoes not.That is,.IT x.cand.IT y.chave the line.DS#include "defs".DEThe following text describes the relationships and operations:.DSprog : x.o y.o z.o cc x.o y.o z.o \-lS \-o prog.sp .5x.o y.o : defs.DEIf this information were stored in a file named.IT makefile ,the command.DSmake.DEwould perform the operations needed to recreate.IT progafter any changes had been made to any of the four source files.IT x.c ,.IT y.c ,.IT z.c ,or.PP.IT Makeoperates using three sources of information:a user-supplied description file (as above),file names and ``last-modified'' times from the file system,and built-in rules to bridge some of the gaps.In our example, the first line says that.IT progdepends on three ``\fI.o\fR'' files.Once these object files are current, the second line describes how to load them to create.IT prog .The third line says that.IT x.oand.IT y.odepend on the file.IT defs .From the file system,.IT makediscovers that there are three ``\fI.c\fR'' files corresponding to the needed ``\fI.o\fR'' files,and uses built-in information on how to generate an object from a source file(\fIi.e.,\fR issue a ``cc\ \-c'' command)..PPThe following long-winded description file is equivalent to the one above, buttakes no advantage of.IT make 'sinnate knowledge:.DSprog : x.o y.o z.o cc x.o y.o z.o \-lS \-o prog.sp .3x.o : x.c defs cc \-c x.cy.o : y.c defs cc \-c y.cz.o : z.c cc \-c z.c.DE.PPIf none of the source or object files had changed since the last time.IT progwas made, all of the files would be current, andthe command.DSmake.DEwould just announce this fact and stop.If, however, the.IT defsfile had been edited,.IT x.cand.IT y.c(but not.IT z.c )would be recompiled, and then.IT progwould be created from the new ``\fI.o\fR'' files.If only the file.IT y.chad changed, only it would be recompiled, but it would still be necessary to reload.IT prog ..PPIf no target name is given on the.IT makecommand line, the first target mentioned in the description is created;otherwise the specified targets are made.The command.DSmake x.o.DEwould recompile.IT x.oif.IT x.cor.IT defshad changed..PPIf the file exists after the commands are executed,its time of last modification is used in further decisions;otherwise the current time is used.It is often quite useful to include rules with mnemonic names and commands that do notactually produce a file with that name.These entries can take advantage of.IT make 'sability to generate files and substitute macros.Thus, an entry``save''might be included to copy a certain set of files, or an entry``cleanup''might be used to throw away unneeded intermediate files.In other cases one may maintain a zero-length file purely to keep trackof the time at which certain actions were performed.This technique is useful for maintaining remote archives and listings..PP.IT Makehas a simple macro mechanism for substituting in dependency lines and command strings.Macros are defined by command arguments or description file lines with embedded equal signs.A macro is invoked by preceding the name by a dollar sign;macro names longer than one character must be parenthesized.The name of the macro is either the single character after the dollar sign or a name inside parentheses.The following are valid macro invocations:.DS$(CFLAGS)$2$(xy)$Z$(Z).DEThe last two invocations are identical.$$ is a dollar sign.All of these macros are assigned values during input, as shown below.Four special macros change values during the execution of the command:$\(**, $@, $?, and $<.They will be discussed later.The following fragment shows the use:.DSOBJECTS = x.o y.o z.oLIBES = \-lSprog: $(OBJECTS) cc $(OBJECTS) $(LIBES) \-o prog . . ..DEThe command.DSmake.DEloads the three object files with the.IT lSlibrary. The command.DSmake "LIBES= \-ll \-lS".DEloads them with both the Lex (``\-ll'') and the Standard (``\-lS'') libraries,since macro definitions on the command line override definitions in the description.(It is necessary to quote arguments with embedded blanks in.UXcommands.).PPThe following sections detail the form of description files and the command line,and discuss options and built-in rules in more detail..SHDescription Files and Substitutions.PPA description file contains three types of information:macro definitions,dependency information,and executable commands.There is also a comment convention:all characters after a sharp (#) are ignored, as is the sharp itself.Blank lines and lines beginning with a sharp are totally ignored.If a non-comment line is too long, it can be continued using a backslash.If the last character of a line is a backslash, the backslash, newline,and following blanks and tabs are replaced by a single blank..PPA macro definition is a line containing an equal sign not preceded by a colon or a tab.The name (string of letters and digits) to the left of the equal sign(trailing blanks and tabs are stripped) is assigned the string of characters following the equal sign(leading blanks and tabs are stripped.)The following are valid macro definitions:.DS2 = xyzabc = \-ll \-ly \-lSLIBES =.DEThe last definition assigns LIBES the null string.A macro that is never explicitly defined has the null string as value.Macro definitions may also appear on the.IT makecommand line (see below)..PPOther lines give information about target files.The general form of an entry is:.DStarget1 [target2 . . .] :[:] [dependent1 . . .] [; commands] [# . . .][\fI(tab)\fR commands] [# . . .] . . ..DEItems inside brackets may be omitted.Targets and dependents are strings of letters, digits, periods, and slashes.(Shell metacharacters ``\(**'' and ``?'' are expanded.)A command is any string of characters not including a sharp (except in quotes)or newline.Commands may appear either after a semicolon on a dependency lineor on lines beginning with a tab immediately following a dependency line..PPA dependency line may have either a single or a double colon.A target name may appear on more than one dependency line, but all of those lines must be of thesame (single or double colon) type..IP 1.For the usual single-colon case,at most one of these dependency lines may have a command sequence associated with it.If the target is out of date with any of the dependents on any of the lines,and a command sequence is specified (even a null one following a semicolon or tab),it is executed; otherwise a default creation rule may be invoked..IP 2.In the double-colon case, a command sequence may be associated with each dependency line;if the target is out of date with any of the files on a particular line, the associatedcommands are executed.A built-in rule may also be executed.This detailed form is of particular value in updating archive-type files..PPIf a target must be created, the sequence of commands is executed.Normally, each command line is printed and thenpassed to a separate invocation of the Shell after substituting for macros.(The printing is suppressed in silent mode or if the command line begins with an @ sign)..IT Makenormally stops if any command signals an error by returning a non-zero error code.(Errors are ignored if the ``\-i'' flags has been specified on the.IT makecommand line,if the fake target name ``.IGNORE'' appears in the description file,or if the command string in the description file begins with a hyphen.Some.UXcommands return meaningless status).Because each command line is passed to a separate invocation of the Shell,care must be taken with certain commands (e.g., \fIcd\fR and Shell control commands) that have meaning onlywithin a single Shell process;the results are forgotten before the next line is executed..PPBefore issuing any command, certain macros are set.$@ is set to the name of the file to be ``made''.$? is set to the string of names that were found to be younger than the target.If the command was generated by an implicit rule (see below),$< is the name of the related file that caused the action, and$\(** is the prefix shared by the current and the dependent file names..PPIf a file must be made but there are no explicit commands or relevantbuilt-in rules,the commands associated with the name ``.DEFAULT'' are used.If there is no such name,.IT makeprints a message and stops..SHCommand Usage.PPThe.IT make
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -