⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch52_08.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 52] 52.8 Building Programs from Source Code </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:58:49Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch52_01.htm"TITLE="52. What's on the Disc"><LINKREL="prev"HREF="ch52_07.htm"TITLE="52.7 Other Ways to Get the Software "><LINKREL="next"HREF="ch52_09.htm"TITLE="52.9 Software Support from RTR "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch52_07.htm"TITLE="52.7 Other Ways to Get the Software "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 52.7 Other Ways to Get the Software "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 52<BR>What's on the Disc</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch52_09.htm"TITLE="52.9 Software Support from RTR "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 52.9 Software Support from RTR "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-3840">52.8 Building Programs from Source Code </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-3840-IX-C-LANGUAGE-SOURCE-CODE"></A><ACLASS="indexterm"NAME="UPT-ART-3840-IX-SOFTWARE-SOURCE-CODE"></A>The programs on the disc are supplied in binary form for the mostpopular UNIX platforms, as listed in article<ACLASS="xref"HREF="ch52_03.htm"TITLE="Shrink-Wrapped Software for UNIX ">52.3</A>.But we also supply C source code for those of you who are on unsupportedplatforms.</P><PCLASS="para">Now, don't run away.You don't have to be a C programmer to compile these sources.I've never written a C program in mylife, and I compile public domain software all the time.The CD-ROM provides build scripts for each of the packages,so many of you can just run the script and have everything installedautomatically.  </P><PCLASS="para">If the build scripts don't work, the CD-ROM also hasa script to copy the sources to your local hard disk.Although we can't promise that you'll be able to build thesources on your own without a hitch, this article includes someexplanation of how to build sources without needing to learn howto program in C.</P><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.1">52.8.1 Running the Build Scripts </A></H3><PCLASS="para">Before you do anything, try out the <EMCLASS="emphasis">build</EM> scripts.You might be able to get away without knowing anything at all about the build process.</P><PCLASS="para">To build programs from source code, first mount the CD-ROM asdescribed in article<ACLASS="xref"HREF="ch52_05.htm"TITLE="Using the Power Tools CD-ROM ">52.5</A>.</P><PCLASS="para">Each package on the CD-ROM that has source code can be compiled with the&quot;build&quot; script.The build script will copy the files off the CD into your currentdirectory, compile, and install them.</P><PCLASS="para">As the CD-ROM is read-only, you must use a directory on some otherdisk for the build.For example, if you wanted to build the &quot;compress&quot;package, a directorycalled <EMCLASS="emphasis">compress</EM> will be created in the current directory when thebuild script is run.The build script has defaultsettings for the directory to which the source code will be copied, the directory in which the package will be installed, the directoryin which the &quot;shareable&quot; portion of the package will be installed, anda &quot;prefix&quot; for the shareable directories.These settings canbe overridden by the following <SPANCLASS="link">environment variables (<ACLASS="linkend"HREF="ch06_01.htm#UPT-ART-1170"TITLE="What Environment Variables Are Good For ">6.1</A>)</SPAN>:<ACLASS="indexterm"NAME="AUTOID-63240"></A></P><DLCLASS="variablelist"><DTCLASS="term">SOURCEDIR</DT><DDCLASS="listitem"><PCLASS="para">This is where the source code for the package resides on the CD-ROM.The build script tries to determine this automatically, so youshould not have set <EMCLASS="emphasis">SOURCEDIR</EM> unless you are using thebuild script somewhere other than the CD-ROM.<ACLASS="indexterm"NAME="AUTOID-63248"></A></P></DD><DTCLASS="term">INSTALLDIR</DT><DDCLASS="listitem"><PCLASS="para">This is the directory where the package will be installed.It is set to<EMCLASS="emphasis">/usr/local</EM> by default.For example, to change <EMCLASS="emphasis">INSTALLDIR</EM> to <EMCLASS="emphasis">/opt</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>setenv INSTALLDIR /opt</B></CODE>   <ICLASS="lineannotation">csh</I>$ <CODECLASS="userinput"><B>INSTALLDIR=/opt ; export INSTALLDIR</B></CODE>   <ICLASS="lineannotation">sh</I></PRE></BLOCKQUOTE></P><PCLASS="para"></P></DD><DTCLASS="term">INSTALLSHAREDIR</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63268"></A>This is the directory where &quot;shareable&quot; portions of the package will beinstalled (<EMCLASS="emphasis">/usr/local/share</EM> by default).You can set it to the same value as <EMCLASS="emphasis">INSTALLDIR</EM> if you want them in the same location.<ACLASS="indexterm"NAME="AUTOID-63272"></A></P></DD><DTCLASS="term">SHAREPREFIX</DT><DDCLASS="listitem"><PCLASS="para">This &quot;prefix&quot; will be prepended to the directory names for <EMCLASS="emphasis">lib</EM>, <EMCLASS="emphasis">include</EM>, <EMCLASS="emphasis">spool</EM>, and <EMCLASS="emphasis">bin</EM>.There is nodefault setting, but you could use <EMCLASS="emphasis">s</EM> if you wanted to conformto the same scheme used by the &quot;install&quot; program to name shareabledirectories <EMCLASS="emphasis">slib</EM>, <EMCLASS="emphasis">sinclude</EM>, <EMCLASS="emphasis">sspool</EM>, and <EMCLASS="emphasis">sbin</EM>.</P></DD></DL><PCLASS="para">By default, the files generated by the build process will not be removed.If you set the <EMCLASS="emphasis">RM</EM> variable before running the build, the entire builddirectory will be removed once the build finishes:&#13;</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>setenv RM true</B></CODE>   <ICLASS="lineannotation">csh</I>$ <CODECLASS="userinput"><B>RM=true ; export RM</B></CODE>   <ICLASS="lineannotation">sh</I></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63296"></A>For a list of the available packages, run the <EMCLASS="emphasis">build.pt</EM> script in the CD-ROM mount directory.The actual name of the script dependson your operating system (as described in article<ACLASS="xref"HREF="ch52_05.htm"TITLE="Using the Power Tools CD-ROM ">52.5</A>),but assuming that the CD-ROM is mounted on <EMCLASS="emphasis">/cdrom</EM>, it is likelyto be one of the following commands:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/cdrom/BUILD.PT\;1</B></CODE>% <CODECLASS="userinput"><B>/cdrom/BUILD.PT</B></CODE>% <CODECLASS="userinput"><B>/cdrom/build.pt\;1</B></CODE>% <CODECLASS="userinput"><B>/cdrom/build.pt</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The command will print a list similar to the following:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">bash         bsdtar       bsplit       calen        cpmod        cvtbasedelete       diff         ediff        emacs        fgrep        fileutilsfind         gawk         getopt       glimpse      grabchars    grep   ...</PRE></BLOCKQUOTE></P><PCLASS="para">To build one of these packages, run the same command followedby the package name.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/cdrom/build.pt bash</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The build script will copy the package to the current directory,compile, and install the package according to the values of theenvironment variables.  For this example, the shareable andnon-shareable portions of the package are combined.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% /archive/cdrom/BUILD.PT jotBUILD script provided by Ready-to-Run Software, Inc.Copyright 1997 Ready-to-Run Software, Inc. All Rights Reserved.Assuming CDROM   is mounted at /archive/cdromAssuming MACHINE is ALPHAAssuming SOURCEDIR is /archive/cdrom/SOURCESIgnore any errors about directories already existingtools/tools/BUGStools/Makefiletools/jot.ctools/lam.ctools/rs.ccc -O -o jot jot.c</PRE></BLOCKQUOTE></P><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.1.1">52.8.1.1 Missing Programs </A></H4><PCLASS="para">Some of the build scripts expect non-standard programs to be installed.Some of these come on the CD-ROM:</P><DLCLASS="variablelist"><DTCLASS="term"><EMCLASS="emphasis">patch</EM></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63326"></A>Several packages depend on the<SPANCLASS="link"><EMCLASS="emphasis">patch</EM> (<ACLASS="linkend"HREF="ch33_09.htm"TITLE="patch: Generalized Updating of Files that Differ ">33.9</A>)</SPAN>program to apply &quot;patches&quot; or &quot;diffs&quot; to sourcecode.This is the primary method of updating source code without replacingthe entire file.</P></DD><DTCLASS="term"><EMCLASS="emphasis">perl</EM></DT><DDCLASS="listitem"><PCLASS="para"><SPANCLASS="link">Perl (<ACLASS="linkend"HREF="ch37_01.htm#UPT-ART-5560"TITLE="What We Do and Don't Tell You About Perl ">37.1</A>)</SPAN><ACLASS="indexterm"NAME="AUTOID-63336"></A>is a scripting language used by several packages, including the installand build scripts.</P></DD><DTCLASS="term"><EMCLASS="emphasis">unshar</EM></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63343"></A>The <EMCLASS="emphasis">unshar</EM> program is needed to unpack<SPANCLASS="link">shell archive files (<ACLASS="linkend"HREF="ch19_03.htm"TITLE="unshar: Unarchive a Shell Archive ">19.3</A>)</SPAN>.</P></DD><DTCLASS="term"><EMCLASS="emphasis">uncompress</EM></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63352"></A>The <EMCLASS="emphasis">uncompress</EM> program is needed to unpack files thathave been compressed with the<SPANCLASS="link"><EMCLASS="emphasis">compress</EM> (<ACLASS="linkend"HREF="ch24_07.htm"TITLE="Compressing Files to Save Space ">24.7</A>)</SPAN>command.</P></DD></DL><PCLASS="para">Some other utilities are not included: </P><DLCLASS="variablelist"><DTCLASS="term"><EMCLASS="emphasis">gcc</EM></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63364"></A>The<SPANCLASS="link">GNU (<ACLASS="linkend"HREF="glossary.htm#UPT-ART-1010"TITLE="Glossary">52.9</A>)</SPAN>C compiler was used to compile most of the packages.You can tryyour system's default C compiler, but it may not work for every package.</P></DD><DTCLASS="term"><EMCLASS="emphasis">GNU make</EM></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63372"></A>GNU<SPANCLASS="link"><EMCLASS="emphasis">make</EM> (<ACLASS="linkend"HREF="ch28_13.htm"TITLE="make Isn't Just for Programmers! ">28.13</A>)</SPAN>was used to compile most of the packages.If you don't have it,try using your system's version.</P></DD></DL></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="UPT-ART-3840-SECT-1.1.2">52.8.1.2 Problems </A></H4><PCLASS="para">Any number of things can go wrong with your build.You might nothave the right libraries or include files installed.Your compiler may not work the way the program expects it to.You might not have the right permissions.You might run out of disk space.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-63380"></A><ACLASS="indexterm"NAME="AUTOID-63383"></A>These problems are so varied that there's no way we can listany generalized solutions.Try asking an administrator or programmeron your site, or try calling <SPANCLASS="link">Ready-to-Run Software's CD support line (<ACLASS="linkend"HREF="ch52_09.htm"TITLE="Software Support from RTR ">52.9</A>)</SPAN>.But we have a few tips that might help:&#13;</P><ULCLASS="itemizedlist"><LICLASS="listitem"><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="bsdtar">bsdtar</A><BR></TH><TDVALIGN="TOP">If your system has problems with filenames longer than 14 characters, youmay have to install <EMCLASS="emphasis">bsdtar</EM>to be able to &quot;untar&quot; the source code.<EMCLASS="emphasis">bsdtar</EM> creates unique 14-character filenames as it unpacks anarchive.&#13;</TD></TR></TABLE></LI><LICLASS="listitem"><PCLASS="para">If your system lacks the<SPANCLASS="link"><EMCLASS="emphasis">-p</EM> option (<ACLASS="linkend"HREF="ch04_08.htm"TITLE="Making Directories Made Easier ">4.8</A>)</SPAN>to the <EMCLASS="emphasis">mkdir</EM

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -