📄 ch52_08.htm
字号:
>uncompress part0?.Z</B></CODE>% <CODECLASS="userinput"><B>unshar part0?</B></CODE>unshar: Sending header to part01.hdr.unshar: Doing part01:If this archive is complete, you will see the following message: "shar: End of archive 1 (of 2)."shar: Extracting "README" (2200 characters)shar: Extracting "options.3" (7383 characters)shar: Extracting "options.c" (10901 characters)shar: Extracting "options.h" (2592 characters)shar: Extracting "qterm.c" (24777 characters)shar: End of archive 1 (of 2).You still must unpack the following archives: 2unshar: Sending header to part02.hdr.unshar: Doing part02:If this archive is complete, you will see the following message: "shar: End of archive 2 (of 2)."shar: Extracting "Makefile" (1908 characters)shar: Extracting "qterm.1" (5805 characters)shar: Extracting "qterm.h" (3281 characters)shar: Extracting "qtermtab" (3311 characters)shar: End of archive 2 (of 2).You have unpacked both archives.</PRE></TD></TR></TABLE></P><PCLASS="para">If youdon't have <EMCLASS="emphasis">shar</EM> and <EMCLASS="emphasis">unshar</EM>, it's on the CD-ROM; butthe true beauty of <EMCLASS="emphasis">shar</EM> archives is that you can always remove any headers and footers from the file and usethe Bourne shell (<EMCLASS="emphasis">sh</EM>) to unpack the files. </P><PCLASS="para">To edit out the header, remove any lines at the top of thefile that don't resemble Bourne shell syntax.Since many <EMCLASS="emphasis">shar</EM>archives are distributed in email or in newsgroups, the filesmight include the header of a mail message or news posting.The author might also precede the actual <EMCLASS="emphasis">shar</EM> archive with some explanation of what the program does.A good bet is to look for a linereading <CODECLASS="literal">#!/bin/sh</CODE> and remove all lines preceding it.Even better, most shell archives contain directions right in the file:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"><ICLASS="lineannotation">(text .... )</I>#! /bin/sh# This is a shell archive. Remove anything before this line,# then feed it into a shell via "sh file" or similar.# To overwrite existing files, type "sh file -c".</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63581"></A>To remove the footer, look for anything resembling a user's mailsignature. (<EMCLASS="emphasis">shar</EM> archives usually have an <EMCLASS="emphasis">exit</EM> messageat the end, so editing out the footer isn't always needed ... but it doesn't hurt.)</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63586"></A>After editing out the header and footer, just run the files through<EMCLASS="emphasis">sh</EM> individually:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>vi part0?</B></CODE> <ICLASS="lineannotation">edit out headers</I>% <CODECLASS="userinput"><B>sh part01; sh part02</B></CODE> ...</PRE></BLOCKQUOTE></P><PCLASS="para"> Note that it's especially important to install and unpack <EMCLASS="emphasis">shar</EM> archives in discrete, well-named directories (such as <EMCLASS="emphasis">qterm_src</EM>, in this case).Since <EMCLASS="emphasis">shar</EM> files are almost always given generic names of<EMCLASS="emphasis">part01</EM>, <EMCLASS="emphasis">part02</EM>, etc.,it's easy to overwrite files or to get confused if youaccidentally unpack more than one package in the same directory. </P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2.5">52.8.2.5 Applying Patches </A></H4><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63603"></A>When I copied the <EMCLASS="emphasis">pcal</EM> sources using the <EMCLASS="emphasis">source.pt</EM>shell script, I also got two<SPANCLASS="link"><EMCLASS="emphasis">patch</EM> files (<ACLASS="linkend"HREF="ch33_09.htm"TITLE="patch: Generalized Updating of Files that Differ ">33.9</A>)</SPAN>:<EMCLASS="emphasis">rtrpatch.pcal</EM> and <EMCLASS="emphasis">RS6000patch.pcal</EM>.These are patches prepared by Ready-to-Run Software for compiling the <EMCLASS="emphasis">pcal</EM> package. </P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63614"></A>The <EMCLASS="emphasis">RS6000patch.pcal</EM> file is a patch for compilng on IBM'sRS6000 platform. If you aren't on a RS6000, then you probably don'tneed this file. When building other packages, you might see otherplatform-specific patch files, with prefixes like <EMCLASS="emphasis">i386</EM>,<EMCLASS="emphasis">xenix</EM>, <EMCLASS="emphasis">hp700</EM>, <EMCLASS="emphasis">sun3</EM>, <EMCLASS="emphasis">sun4</EM>, etc. Naturally, youshouldn't use these packages if you aren't on one of these platforms.</P><PCLASS="para">The <EMCLASS="emphasis">rtrpatch.pcal</EM> file isa general-purpose patch for all platforms.You should apply this patch for all platforms.</P><PCLASS="para">Before you apply any of Ready-to-Run's patches, you should firstmake sure that there aren't any patch files in the untarred sourcedirectory.If the sources did come with patch files, they wouldhave to be applied before Ready-to-Run's.In the <EMCLASS="emphasis">pcal-4.3</EM> directory, list the directory contents:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls -aF</B></CODE>./ Makefile.VMS calendar pcal.man protos.h../ Orig.ReadMe exprpars.c pcaldefs.h readfile.cDescrip.mms Pcal.TEX moon91 pcalglob.h troffman.styMake_Pcal.com Pcal.hlp moon92 pcalinit.c writefil.cMakefile ReadMe moonphas.c pcalinit.psMakefile.Amiga SetUp.com noprotos.h pcallang.hMakefile.DOS VaxCrtl.opt pcal.c pcalutil.c</PRE></BLOCKQUOTE></P><PCLASS="para">A <EMCLASS="emphasis">patch</EM> file generally has the string <EMCLASS="emphasis">patch</EM> or <EMCLASS="emphasis">pch</EM>in it. There are no patch files in this directory. Now that I'm surethat there aren't any other patches, I run the <EMCLASS="emphasis">patch</EM>command. (Naturally, if you don't already have <EMCLASS="emphasis">patch</EM>, you canget its sources off the CD-ROM.) To run <EMCLASS="emphasis">patch</EM>, makesure you're in the source directory (in this case, the <EMCLASS="emphasis">pcal-4.3</EM>subdirectory created when I ran <EMCLASS="emphasis">tar</EM>). Then run <EMCLASS="emphasis">patch</EM>,taking input from the patch file in the parent directory:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch13_01.htm"TITLE="13.1 Using Standard Input and Output"><</A> <ACLASS="co"HREF="ch01_21.htm"TITLE="1.21 Making Pathnames ">../</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>patch < ../rtrpatch.pcal</B></CODE>Hmm... Looks like a new-style context diff to me...The text leading up to this was:--------------------------------|*** Makefile.orig Tue Dec 17 05:34:19 1991|-- Makefile Mon Nov 23 05:59:49 1992--------------------------------Patching file Makefile using Plan A...Hunk #1 succeeded at 5.Hunk #2 succeeded at 46.done</PRE></TD></TR></TABLE></P><PCLASS="para"> The patch is now applied. </P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2.6">52.8.2.6 An Easy Build </A></H4><PCLASS="para">Up to now, all we've been doing is just getting the source treetogether. Now we're up to the part where we actually buildthe package. </P><PCLASS="para">First of all, if there's any universal rule about compilingsources, it's:<ACLASS="indexterm"NAME="AUTOID-63649"></A><BLOCKQUOTECLASS="blockquote"><PCLASS="para"><BCLASS="emphasis.bold">If there's a file called README, read it!</B></P></BLOCKQUOTE></P><PCLASS="para"><EMCLASS="emphasis">README</EM> files often contain esoteric details about the historyof the program and what improvements could be made, etc.But theymight also contain details about how to build the package.Reading a<EMCLASS="emphasis">README</EM> can save you hours of frustration trying to figure out what to tweak to make the program build on your platform.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63658"></A>Another file to look for is one called <EMCLASS="emphasis">Configure</EM>.<EMCLASS="emphasis">Configure</EM> is a shell script that tries to figureout what sort of platform you're on and how to build thepackage for you, and it's remarkably effective.The sourcesfor <EMCLASS="emphasis">perl</EM> and <EMCLASS="emphasis">patch</EM> both come with <EMCLASS="emphasis">Configure</EM> scripts.</P><PCLASS="para"><EMCLASS="emphasis">pcal</EM> doesn't come with a <EMCLASS="emphasis">README</EM> or with a <EMCLASS="emphasis">Configure</EM>script.But it doescome with a file called <EMCLASS="emphasis">Makefile</EM>.(Actually, it comes with several <EMCLASS="emphasis">Makefiles</EM>, for differentplatforms - but the default <EMCLASS="emphasis">Makefile</EM> is the one for UNIXsystems, which is what you want.)The <EMCLASS="emphasis">Makefile</EM> is used by <SPANCLASS="link">the <EMCLASS="emphasis">make</EM> program (<ACLASS="linkend"HREF="ch28_13.htm"TITLE="make Isn't Just for Programmers! ">28.13</A>)</SPAN>.There have been entire books written about <EMCLASS="emphasis">make</EM>, but ifyou're lucky, all you need to know about it is that if you seea <EMCLASS="emphasis">Makefile</EM>, then all you need to compile a program is totype <EMCLASS="emphasis">make</EM>.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63679"></A>First, though, scan through the <EMCLASS="emphasis">Makefile</EM> to see if thereare any comments there.You might have to make some changesin the <EMCLASS="emphasis">Makefile</EM> to configure it for your system.Forexample, the <EMCLASS="emphasis">qterm</EM> <EMCLASS="emphasis">Makefile</EM> has the following very helpful lines:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">## Add "-DUSG5" to DEFS below, if your system is UNIX System V.# Add "-DHAS_VARARGS" if your system supports varargs.# Add "-DOPT_COMPAT" to support old command line options.#DEFS = -DTABFILE=\"$(TABFILE)\" -DOPT_COMPAT</PRE></BLOCKQUOTE></P><PCLASS="para">You probably know whether your system is System V-based or not.If you never used this program before, you probably don't care aboutold command line options.And if you don't know what <EMCLASS="emphasis">varargs</EM>are or whether your system supports it ... try seeing if there'sa<SPANCLASS="link">manpage (<ACLASS="linkend"HREF="ch50_01.htm#UPT-ART-4910"TITLE="UNIX Online Documentation ">50.1</A>)</SPAN>for it.(You might even find out what it is!)</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>man varargs</B></CODE>VARARGS(3) C LIBRARY FUNCTIONS VARARGS(3)NAME varargs - handle variable argument listSYNOPSIS #include <varargs.h> ...</PRE></BLOCKQUOTE></P><PCLASS="para">What do you know, I have <EMCLASS="emphasis">varargs</EM>.So I add the <CODECLASS="literal">-DHAS_VARARGS</CODE>command-line option to the <CODECLASS="literal">DEFS=</CODE> line:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">DEFS = -DTABFILE=\"$(TABFILE)\" -DOPT_COMPAT -DHAS_VARARGS</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">pcal</EM> <EMCLASS="emphasis">Makefile</EM>, on the other hand, only includes asingle line of instruction towards the top: </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"># Set the configuration variables below to taste.</PRE></BLOCKQUOTE></P><PCLASS="para">This isn't particularly helpful, but scan the <EMCLASS="emphasis">Makefile</EM>anyway for anything obviously wrong.When you're satisfied, just cross your fingers and run <EMCLASS="emphasis">make</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>make</B></CODE>/bin/cc -c pcal.c/bin/cc -c exprpars.c/bin/cc -c moonphas.c/bin/cc -c pcalutil.c/bin/cc -c readfile.c/bin/cc -o pcalinit pcalinit.cpcalinit pcalinit.ps pcalinit.h/bin/cc -c writefil.c/bin/cc -o pcal pcal.o exprpars.o moonphas.o pcalutil.o readfile.owritefil.o -lm</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63711"></A>There were no error or warning messages, so you're fine.Errors mean that the program package probably didn't build completely;you'll have to find the cause and fix them.If there were warnings, the programs may not work right or havea subtle flaw.For a program like a spreadsheet, where hidden flawscan be a disaster, you'd better find out what the warnings mean andfix them.Otherwise, just cross your fingers some more and see if the program works.</P><PCLASS="para">When you list the <EMCLASS="emphasis">pcal</EM> source directory now, you shouldsee several new files with a <EMCLASS="emphasis">.o</EM> suffix, but the mostimportant thing is that the <EMCLASS="emphasis">pcal</EM> executable is now builtand ready to be installed on your system.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls -aF</B></CODE>./ Orig.ReadMe moon91 pcaldefs.h protos.h../ Pcal.TEX moon92 pcalglob.h readfile.cDescrip.mms Pcal.hlp moonphas.c pcalinit* readfile.oMake_Pcal.com ReadMe moonphas.o pcalinit.c troffman.styMakefile SetUp.com noprotos.h pcalinit.h writefil.cMakefile.Amiga VaxCrtl.opt pcal* pcalinit.ps writefil.oMakefile.DOS calendar pcal.c pcallang.hMakefile.VMS exprpars.c pcal.man pcalutil.cMakefile.orig exprpars.o pcal.o pcalutil.o</PRE></BLOCKQUOTE></P><PCLASS="para">You can now try out the program, and once you're sure it works, install it.To install the program, many <EMCLASS="emphasis">Makefiles</EM> providean <EMCLASS="emphasis">install</EM> target. </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>make install</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63728"></A>On many machines, you'll need to be logged in as<EMCLASS="emphasis">root</EM> to be able to install the binary and manpage system-wide.If so, it might be a good idea to run <EMCLASS="emphasis">make</EM> with the <EMCLASS="emphasis">-n</EM>option first.The <EMCLASS="emphasis">-n</EM> option says to just show what commandswould be executed without actually executing them.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>make -n install</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Or if you prefer to just install the program by hand, just move the executable and the manpage to the rightdirectories (be sure to rename the manpage as appropriate):</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>mv pcal /usr/local/bin</B></CODE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -