📄 tutorial.ms
字号:
.\" Copyright (c) 1988, 1989 by Adam de Boor.\" Copyright (c) 1989 by Berkeley Softworks.\" Copyright (c) 1988, 1989, 1993.\" The Regents of the University of California. All rights reserved..\".\" This code is derived from software contributed to Berkeley by.\" Adam de Boor..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)tutorial.ms 8.1 (Berkeley) 8/18/93.\".EH 'PSD:12-%''PMake \*- A Tutorial'.OH 'PMake \*- A Tutorial''PSD:12-%'.\" xH is a macro to provide numbered headers that are automatically stuffed.\" into a table-of-contents, properly indented, etc. If the first argument.\" is numeric, it is taken as the depth for numbering (as for .NH), else.\" the default (1) is assumed..\".\" $Id: tutorial.ms,v 1.4 89/01/08 20:20:22 adam Exp Locker: adam $.\".\" @P The initial paragraph distance..\" @Q The piece of section number to increment (or 0 if none given).\" @R Section header..\" @S Indent for toc entry.\" @T Argument to NH (can't use @Q b/c giving 0 to NH resets the counter).de xH.NH \\$1\\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9.nr PD .1v.XS \\n%.ta 0.6i\\*(SN \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9.XE.nr PD .3v...\" CW is used to place a string in fixed-width or switch to a.\" fixed-width font..\" C is a typewriter font for a laserwriter. Use something else if.\" you don't have one....de CW.ie !\\n(.$ .ft C.el \&\\$3\fC\\$1\fP\\$2...\" Anything I put in a display I want to be in fixed-width.am DS.CW...\" The stuff in .No produces a little stop sign in the left margin.\" that says NOTE in it. Unfortunately, it does cause a break, but.\" hey. Can't have everything. In case you're wondering how I came.\" up with such weird commands, they came from running grn on a.\" gremlin file....de No.br.ne 0.5i.po -0.5i.br.mk .nr g3 \\n(.f.nr g4 \\n(.s.sp -1.\" .st cf\D's -1u'\D't 5u'.sp -1\h'50u'\D'l 71u 0u'\D'l 50u 50u'\D'l 0u 71u'\D'l -50u 50u'\D'l -71u 0u'\D'l -50u -50u'\D'l 0u -71u'\D'l 50u -50u'.sp -1\D't 3u'.sp -1.sp 7u\h'53u'\D'p 14 68u 0u 46u 46u 0u 68u -46u 46u -68u 0u -47u -46u 0u -68u 47u -46u'.sp -1.ft R.ps 6.nr g8 \\n(.d.ds g9 "NOTE.sp 74u\h'85u'\v'0.85n'\h-\w\\*(g9u/2u\&\\*(g9.sp |\\n(g8u.sp 166u\D't 3u'\D's -1u'.br.po.rt .ft \\n(g3.ps \\n(g4...de Bp.ie !\\n(.$ .IP \(bu 2.el .IP "\&" 2...po +.3i.TLPMake \*- A Tutorial.AUAdam de Boor.AIBerkeley Softworks2150 Shattuck Ave, PenthouseBerkeley, CA 94704adam@bsw.uu.net\&...!uunet!bsw!adam.FSPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appears in all copies.The University of California, Berkeley Softworks, and Adam de Boor make norepresentations about the suitability of this software for anypurpose. It is provided "as is" without express or implied warranty..FE.PP.xH 1 Introduction.LPPMake is a program for creating other programs, or anything else youcan think of for it to do. The basic idea behind PMake is that, forany given system, be it a program or a document or whatever, therewill be some files that depend on the state of other files (on whenthey were last modified). PMake takes these dependencies, which youmust specify, and uses them to build whatever it is you want it tobuild..LPPMake is almost fully-compatible with Make, with which you may alreadybe familiar. PMake's most important feature is its ability to runseveral different jobs at once, making the creation of systemsconsiderably faster. It also has a great deal more functionality thanMake. Throughout the text, whenever something is mentioned that is animportant difference between PMake and Make (i.e. something that willcause a makefile to fail if you don't do something about it), or issimply important, it will be flagged with a little sign in the leftmargin, like this:.No.LPThis tutorial is divided into three main sections corresponding to basic,intermediate and advanced PMake usage. If you already know Make well,you will only need to skim chapter 2 (there are some aspects ofPMake that I consider basic to its use that didn't exist in Make).Things in chapter 3 make life much easier, while those in chapter 4are strictly for those who know what they are doing. Chapter 5 hasdefinitions for the jargon I use and chapter 6 contains possiblesolutions to the problems presented throughout the tutorial..xH 1 The Basics of PMake.LPPMake takes as input a file that tells a) which files depend on whichother files to be complete and b) what to do about files that are``out-of-date.'' This file is known as a ``makefile'' and is usually.Ix 0 def makefilekept in the top-most directory of the system to be built. While youcan call the makefile anything you want, PMake will look for.CW Makefileand.CW makefile(in that order) in the current directory if you don't tell itotherwise..Ix 0 def makefile defaultTo specify a different makefile, use the.B \-fflag (e.g..CW "pmake -f program.mk" ''). ``.Ix 0 ref flags -f.Ix 0 ref makefile other.LPA makefile has four different types of lines in it:.RS.IP \(bu 2File dependency specifications.IP \(bu 2Creation commands.IP \(bu 2Variable assignments.IP \(bu 2Comments, include statements and conditional directives.RE.LPAny line may be continued over multiple lines by ending it with abackslash..Ix 0 def "continuation line"The backslash, following newline and any initial whitespaceon the following line are compressed into a single space before theinput line is examined by PMake..xH 2 Dependency Lines.LPAs mentioned in the introduction, in any system, there aredependencies between the files that make up the system. For instance,in a program made up of several C source files and one header file,the C files will need to be re-compiled should the header file bechanged. For a document of several chapters and one macro file, thechapters will need to be reprocessed if any of the macros changes..Ix 0 def "dependency"These are dependencies and are specified by means of dependency lines inthe makefile..LP.Ix 0 def "dependency line"On a dependency line, there are targets and sources, separated by aone- or two-character operator.The targets ``depend'' on the sources and are usually created fromthem..Ix 0 def target.Ix 0 def source.Ix 0 ref operatorAny number of targets and sources may be specified on a dependency line.All the targets in the line are made to depend on all the sources.Targets and sources need not be actual files, but every source must beeither an actual file or another target in the makefile.If you run out of room, use a backslash at the end of the line to continue ontothe next one..LPAny file may be a target and any file may be a source, but therelationship between the two (or however many) is determined by the``operator'' that separates them..Ix 0 def operatorThree types of operators exist: one specifies that the datedness of atarget is determined by the state of its sources, while anotherspecifies other files (the sources) that need to be dealt with beforethe target can be re-created. The third operator is very similar tothe first, with the additional condition that the target isout-of-date if it has no sources. These operations are represented bythe colon, the exclamation point and the double-colon, respectively, and aremutually exclusive. Their exact semantics are as follows:.IP ":".Ix 0 def operator colon.Ix 0 def :If a colon is used, a target on the line is considered to be``out-of-date'' (and in need of creation) if .RS.IP \(bu 2any of the sources has been modified more recently than the target, or.IP \(bu 2the target doesn't exist..RE.Ix 0 def out-of-date.IP "\&"Under this operation, steps will be taken to re-create the target onlyif it is found to be out-of-date by using these two rules..IP "!".Ix 0 def operator force.Ix 0 def !If an exclamation point is used, the target will always be re-created,but this will not happen until all of its sources have been examinedand re-created, if necessary..IP "::".Ix 0 def operator double-colon.Ix 0 def ::If a double-colon is used, a target is out-of-date if:.RS.IP \(bu 2any of the sources has been modified more recently than the target, or.IP \(bu 2the target doesn't exist, or.IP \(bu 2the target has no sources..RE.IP "\&"If the target is out-of-date according to these rules, it will be re-created.This operator also does something else to the targets, but I'll gointo that in the next section (``Shell Commands'')..LPEnough words, now for an example. Take that C program I mentionedearlier. Say there are three C files.CW a.c , (.CW b.cand.CW c.c )each of whichincludes the file.CW defs.h .The dependencies between the files could then be expressed as follows:.DSprogram : a.o b.o c.oa.o b.o c.o : defs.ha.o : a.cb.o : b.cc.o : c.c.DE.LPYou may be wondering at this point, where.CW a.o ,.CW b.oand.CW c.ocame in and why.I theydepend on.CW defs.hand the C files don't. The reason is quite simple:.CW programcannot be made by linking together .c files \*- it must bemade from .o files. Likewise, if you change.CW defs.h ,it isn't the .c files that need to be re-created, it's the .o files.If you think of dependencies in these terms \*- which files (targets)need to be created from which files (sources) \*- you should have no problems..LPAn important thing to notice about the above example, is that all the\&.o files appear as targets on more than one line. This is perfectlyall right: the target is made to depend on all the sources mentionedon all the dependency lines. E.g..CW a.odepends on both.CW defs.hand.CW a.c ..Ix 0 ref dependency.No.LPThe order of the dependency lines in the makefile isimportant: the first target on the first dependency line in themakefile will be the one that gets made if you don't say otherwise.That's why.CW programcomes first in the example makefile, above..LPBoth targets and sources may contain the standard C-Shell wildcardcharacters.CW { , (.CW } ,.CW * ,.CW ? ,.CW [ ,and.CW ] ),but the non-curly-brace ones may only appear in the final component(the file portion) of the target or source. The characters mean thefollowing things:.IP \fB{}\fPThese enclose a comma-separated list of options and cause the patternto be expanded once for each element of the list. Each expansioncontains a different element. For example, .CW src/{whiffle,beep,fish}.cexpands to the three words.CW src/whiffle.c ,.CW src/beep.c ,and .CW src/fish.c .These braces may be nested and, unlike the other wildcard characters,the resulting words need not be actual files. All other wildcardcharacters are expanded using the files that exist when PMake isstarted..IP \fB*\fPThis matches zero or more characters of any sort. .CW src/*.cwill expand to the same three words as above as long as .CW srccontains those three files (and no other files that end in .CW .c )..IP \fB?\fPMatches any single character..IP \fB[]\fPThis is known as a character class and contains either a list ofsingle characters, or a series of character ranges .CW a-z , (for example means all characters between a and z), or both. It matchesany single character contained in the list. E.g..CW [A-Za-z]will match all letters, while.CW [0123456789]will match all numbers..xH 2 Shell Commands.LP``Isn't that nice,'' you say to yourself, ``but how are filesactually `re-created,' as he likes to spell it?''The re-creation is accomplished by commands you place in the makefile.These commands are passed to the Bourne shell (better known as``/bin/sh'') to be executed and are.Ix 0 ref shell.Ix 0 ref re-creation.Ix 0 ref updateexpected to do what's necessary to update the target file (PMakedoesn't actually check to see if the target was created. It justassumes it's there)..Ix 0 ref target.LPShell commands in a makefile look a lot like shell commands you wouldtype at a terminal, with one important exception: each command in amakefile.I must
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -