📄 ch52_08.htm
字号:
> command, youmay need to install a new version from the GNU <EMCLASS="emphasis">fileutils</EM> package.The <EMCLASS="emphasis">-p</EM> option is used by the installation and build scripts.</P></LI></UL><PCLASS="para">And if all else fails, you can try to delve into the source codeitself.That brings us to our next section ...</P></DIV></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2">52.8.2 Compiling Source Code </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63404"></A>Compiling programs from source doesn't require you to be a C programmer, just that you understandthe general procedure and that you have some common sense and luck.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63407"></A><ACLASS="indexterm"NAME="AUTOID-63410"></A>Almost all UNIX binary programs are written in the C language.These programs are written in text files - the text files are referredto as the <EMCLASS="emphasis">source code</EM>-and then converted tobinary files using a <EMCLASS="emphasis">compiler</EM>.The typical compiler on a UNIX system is called <EMCLASS="emphasis">cc</EM>.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63416"></A>Although most people call <EMCLASS="emphasis">cc</EM> a "compiler," it's reallya front-end program.Unless you tell it not to, <EMCLASS="emphasis">cc</EM> first runs a <EMCLASS="emphasis">preprocessor</EM>.Next it runs the compiler.Then it runs the <EMCLASS="emphasis">linker/loader</EM>to make the actual executable file.We'll gloss over that in this article and just say that "<EMCLASS="emphasis">cc</EM> does it."</P><PCLASS="para">On top of <EMCLASS="emphasis">cc</EM>, there's usually another front-end: almost all programs are designed to be compiled using the <EMCLASS="emphasis">make</EM> program.</P><PCLASS="para">Although we can't prepare you for everything you might need toknow to compile programs from the CD-ROM for your platform, this section should at least give you an idea of how it's<EMCLASS="emphasis">supposed</EM> to work.</P><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2.1">52.8.2.1 Copying the Sources </A></H4><PCLASS="para">Before you can actually compile the sources, youneed to copy the sources to your local hard disk.You can't just compile the sources directly from the CD-ROM becausethe CD-ROM is read-only.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63432"></A>The first thing you need to do is to decide where you want toinstall the sources, and then <EMCLASS="emphasis">cd</EM> to that directory. Forexample, I like to build sources in a subdirectory of my home directory.Let's suppose I want to install the <EMCLASS="emphasis">pcal</EM> program.I create the new directory and then <EMCLASS="emphasis">cd</EM> there:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch14_11.htm"TITLE="14.11 Finding (Anyone's) Home Directory, Quickly ">~</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>mkdir ~/pcal_src</B></CODE>% <CODECLASS="userinput"><B>cd ~/pcal_src</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para"> For installing the sources onto your local hard disk, the CD-ROMhas a script called <EMCLASS="emphasis">source.pt</EM>.Assuming that the CD-ROM is mounted on <EMCLASS="emphasis">/cdrom</EM>, the scriptcan be called using one of the following commands:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/cdrom/SOURCE.PT\;1 </B></CODE><CODECLASS="replaceable"><I>package-name</I></CODE>% <CODECLASS="userinput"><B>/cdrom/SOURCE.PT </B></CODE><CODECLASS="replaceable"><I>package-name</I></CODE>% <CODECLASS="userinput"><B>/cdrom/source.pt\;1 </B></CODE><CODECLASS="replaceable"><I>package-name</I></CODE>% <CODECLASS="userinput"><B>/cdrom/source.pt </B></CODE><CODECLASS="replaceable"><I>package-name</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Where <EMCLASS="emphasis">package-name</EM> is the name of the package that youwant to install sources for. To get a listing of the files,call <EMCLASS="emphasis">source.pt</EM> without any arguments:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% source.pt<ACLASS="indexterm"NAME="AUTOID-63460"></A>SOURCE script provided by Ready-to-Run Software, Inc.Copyright 1997 Ready-to-Run Software, Inc. All Rights Reserved.Assuming CDROM is mounted at /archive/cdrom/Usage: /archive/cdrom/SOURCE.PT <packageAvailable packages are: ! 80cols Clear _emacs_ml _enter_csh _enter_sh _exit_csh _exit_sh addup age_files ascii awf bash behead bkedit bsdtar bsplit cal_today calen catsaway center cgrep cgrep_sed checksed chmod_edit chunksort cleanup cleanup_sed cls cols count_it count_types cpmod crontab crush csh_init csh_logout cvtbase date-month del delete diff dir_path dirtop doublespace ediff elookfor emacs exrc fgrep fileutils find findcmd findtext flip fmt_sh formprog ftpfile gawk getmac getopt glimpse grabchars grep groff gzip head hey hgrep index ipl ispell jot lensort less lf lndir logerrs longlines look lookfor ls_today make_print manindex motd_diff namesort netpbm nextday no_run nom offset oldlinks opttest paircheck patch pcal perl5 phone pipegrep pstext psutils pushin qcsh qsubst qterm rcs rcsegrep_fast rcsgrep rcsrevs recomment redo relink ren rename rot runsed runtime sc screen screensize script_tidy search_el sedman sh_init sh_logout sharutils shellutils showmatch sl sls smiley squoze stat stree stripper su tar tcap tcsh termtest textutils tgrep tknew tm tpipe tputinit triplespace twin vgrep vis vtree watchq whereiz which wordfreq xgrep xtail zap zloop zmore zvi</PRE></BLOCKQUOTE></P><PCLASS="para">(Note that all the packages on the CD-ROM are listed here,shell scripts as well as C sources.)</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63464"></A>In my case, I want to install <EMCLASS="emphasis">pcal</EM>, so I run the following command:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/cdrom/source.pt pcal</B></CODE>SOURCE script provided by Ready-to-Run Software, Inc.Copyright 1993 Ready-to-Run Software, Inc. All Rights Reserved.Copied /POWER_TOOLS/SOURCES/PCAL/PCAL_43.Z to pcal-4.3.tar.ZCopied /POWER_TOOLS/SOURCES/PCAL/RS6000/PCAL to RS6000patch.pcalCopied /POWER_TOOLS/SOURCES/PCAL/RTR/PCAL to rtrpatch.pcal3 files copied successfully.</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">source.pt</EM> script copies all the relevant files into your current directory.</P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2.2">52.8.2.2 Uncompressing the Sources </A></H4><PCLASS="para">If you now list the directory, you'll find the files that werejust copied there. </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls</B></CODE>RS6000patch.pcal pcal-4.3.tar.Z rtrpatch.pcal</PRE></BLOCKQUOTE></P><PCLASS="para">The file called <EMCLASS="emphasis">pcal-4.3.tar.Z</EM> is the <EMCLASS="emphasis">pcal</EM>source package, in a tarred and compressed form.The <EMCLASS="emphasis">.Z</EM>suffix tells you that the file was compressed using the <SPANCLASS="link"><EMCLASS="emphasis">compress</EM> (<ACLASS="linkend"HREF="ch24_07.htm"TITLE="Compressing Files to Save Space ">24.7</A>)</SPAN>command.You need to run <EMCLASS="emphasis">uncompress</EM> first:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>uncompress pcal-4.3.tar.Z</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63490"></A>If you don't have the <EMCLASS="emphasis">uncompress</EM> command, use <EMCLASS="emphasis">gunzip</EM>.</P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2.3">52.8.2.3 Untarring the Sources </A></H4><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63497"></A>After you have uncompressed the file, you'll see the file withoutthe <EMCLASS="emphasis">.Z</EM> suffix. </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls</B></CODE>RS6000patch.pcal pcal-4.3.tar rtrpatch.pcal</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63504"></A>The <EMCLASS="emphasis">.tar</EM> suffix to the <EMCLASS="emphasis">pcal-4.3.tar</EM> file meansthat the file was packed using the <SPANCLASS="link"><EMCLASS="emphasis">tar</EM> command (<ACLASS="linkend"HREF="ch19_05.htm"TITLE="Using tar to Create and Unpack Archives ">19.5</A>)</SPAN>.Again, if you don't have <EMCLASS="emphasis">tar</EM>, it's on the CD-ROM.</P><PCLASS="para">To unpack the file, use <EMCLASS="emphasis">tar</EM> with the <EMCLASS="emphasis">-x</EM> optionfor "extract" and the <EMCLASS="emphasis">-f</EM> option to specify a filename.(I also like to use <EMCLASS="emphasis">-v</EM> for verbose output.)My command linemight read:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tar xvf pcal-4.3.tar</B></CODE>x pcal-4.3/ReadMe, 7673 bytes, 15 tape blocksx pcal-4.3/Descrip.mms, 3713 bytes, 8 tape blocksx pcal-4.3/Make_Pcal.com, 3090 bytes, 7 tape blocksx pcal-4.3/Makefile, 1159 bytes, 3 tape blocksx pcal-4.3/Makefile.Amiga, 1010 bytes, 2 tape blocksx pcal-4.3/Makefile.DOS, 1023 bytes, 2 tape blocksx pcal-4.3/Makefile.VMS, 2505 bytes, 5 tape blocksx pcal-4.3/Orig.ReadMe, 984 bytes, 2 tape blocksx pcal-4.3/Pcal.TEX, 28199 bytes, 56 tape blocksx pcal-4.3/Pcal.hlp, 29099 bytes, 57 tape blocksx pcal-4.3/SetUp.com, 670 bytes, 2 tape blocksx pcal-4.3/VaxCrtl.opt, 31 bytes, 1 tape blocksx pcal-4.3/calendar, 12101 bytes, 24 tape blocksx pcal-4.3/exprpars.c, 8538 bytes, 17 tape blocksx pcal-4.3/moon91, 2828 bytes, 6 tape blocksx pcal-4.3/moon92, 2887 bytes, 6 tape blocksx pcal-4.3/pcal.c, 46440 bytes, 91 tape blocksx pcal-4.3/noprotos.h, 2530 bytes, 5 tape blocksx pcal-4.3/pcalglob.h, 4551 bytes, 9 tape blocksx pcal-4.3/pcalinit.c, 4071 bytes, 8 tape blocksx pcal-4.3/protos.h, 4341 bytes, 9 tape blocksx pcal-4.3/moonphas.c, 17817 bytes, 35 tape blocksx pcal-4.3/troffman.sty, 4894 bytes, 10 tape blocksx pcal-4.3/writefil.c, 24597 bytes, 49 tape blocksx pcal-4.3/pcal.man, 25296 bytes, 50 tape blocksx pcal-4.3/pcaldefs.h, 17643 bytes, 35 tape blocksx pcal-4.3/pcalinit.ps, 14297 bytes, 28 tape blocksx pcal-4.3/pcalutil.c, 21238 bytes, 42 tape blocksx pcal-4.3/pcallang.h, 35465 bytes, 70 tape blocksx pcal-4.3/readfile.c, 32888 bytes, 65 tape blocks</PRE></BLOCKQUOTE></P><PCLASS="para"><EMCLASS="emphasis">tar</EM> creates a subdirectory called <EMCLASS="emphasis">pcal-4.3</EM>.<EMCLASS="emphasis">cd</EM>to this directory to continue your build.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cd pcal-4.3</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Note that if you have the <EMCLASS="emphasis">zcat</EM> command, you might have combined the steps for uncompressing anduntarring the files into a single command line, as shownin article<ACLASS="xref"HREF="ch19_07.htm"TITLE="Extracting Files from a Compressed Archive ">19.7</A>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>zcat pcal-4.3.tar.Z | tar xvf -</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">If you are on a System V-based system, you may have to use <EMCLASS="emphasis">tar</EM>with the<SPANCLASS="link"><EMCLASS="emphasis">-o</EM> option (<ACLASS="linkend"HREF="ch19_07.htm"TITLE="Extracting Files from a Compressed Archive ">19.7</A>)</SPAN>to make sure that you get ownership of the files.</P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.2.4">52.8.2.4 Unsharring the Sources </A></H4><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63539"></A><ACLASS="indexterm"NAME="AUTOID-63541"></A><ACLASS="indexterm"NAME="AUTOID-63543"></A>Before we go on, let's back up a bit.Some packages aren'tstored as <EMCLASS="emphasis">tar</EM> archives, but as <SPANCLASS="link"><EMCLASS="emphasis">shar</EM> archives (<ACLASS="linkend"HREF="ch19_02.htm"TITLE="Introduction to Shell Archives ">19.2</A>)</SPAN>.<EMCLASS="emphasis">shar</EM> archives are generally distributed in multiplefiles, under names such as <EMCLASS="emphasis">part01.Z</EM>, <EMCLASS="emphasis">part02.Z</EM>, etc.The <EMCLASS="emphasis">qterm</EM> source package is an example of a packagethat is distributed as <EMCLASS="emphasis">shar</EM> files. </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>mkdir ~/qterm_src</B></CODE>% <CODECLASS="userinput"><B>cd ~/qterm_src</B></CODE>% <CODECLASS="userinput"><B>/cdrom/source.pt qterm</B></CODE>% /archive/cdrom/SOURCE.PT qtermSOURCE script provided by Ready-to-Run Software, Inc.Copyright 1997 Ready-to-Run Software, Inc. All Rights Reserved.Assuming CDROM is mounted at /archive/cdrom/Copied /archive/cdrom//SOURCES/QTERM/PART01.Z to part01.ZCopied /archive/cdrom//SOURCES/QTERM/PART02.Z to part02.ZCopied /archive/cdrom//SOURCES/QTERM/RS6000/QTERM to RS6000patch.qtermCopied /archive/cdrom//SOURCES/QTERM/I386/QTERM to i386patch.qtermCopied /archive/cdrom//SOURCES/QTERM/SUN4C/QTERM to sun4cpatch.qtermCopied /archive/cdrom//SOURCES/QTERM/HP700/QTERM to hp700patch.qtermCopied /archive/cdrom//SOURCES/QTERM/LINUX/QTERM to linuxpatch.qtermCopied /archive/cdrom//SOURCES/QTERM/SSOL2/QTERM to SSol2patch.qtermCopied /archive/cdrom//SOURCES/QTERM/RTR/QTERM to rtrpatch.qterm9 file(s) copied successfully.</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63559"></A>To extract the <EMCLASS="emphasis">qterm</EM> sources, uncompress the "part" filesand then use the <EMCLASS="emphasis">unshar</EM> program to unpack them. </P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch01_16.htm"TITLE="1.16 Wildcards ">?</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -