0132-0134.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 282 行
HTML
282 行
<HTML>
<HEAD>
<TITLE>Maximum RPM (RPM):Building Packages: A Simple Example:EarthWeb Inc.-</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311054 //-->
<!-- TITLE=Maximum RPM (RPM)//-->
<!-- AUTHOR=Edward Bailey//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=11 //-->
<!-- PAGES=0125-0138 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0129-0131.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0135-0137.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-132"><P>Page 132</P></A>
<H4><A NAME="ch11_ 12">
11.3.6. The Missing Spec File Sections
</A></H4>
<P>Our sample spec file is somewhat simplistic and it's missing two sections that might be used
in more complex situations. We'll go over each one briefly here. More complete information
on these sections will be given at various points in the book.
</P>
<B>
11.3.6.1. The Install/Uninstall Scripts
</B>
<P>One missing section to our spec file is the section that would define one or more of four
possible scripts. The scripts are executed at various times when a package is installed or erased.
</P>
<P>The scripts can be executed at the following points:
</P>
<UL>
<LI> Before a package is installed
<LI> After a package is installed
<LI> Before a package is erased
<LI> After a package is erased
</UL>
<P>We'll see how these scripts are used in Chapter 20.
</P>
<B>
11.3.6.2. The %clean Section
</B>
<P>The other missing section has the rather descriptive title
%clean. This section can be used to clean up any files that are not part of the application's normal build area. For example, if
the application creates a directory structure in
/tmp as part of its build, it will not be removed.
By adding a sh script to the %clean section, such situations can be handled gracefully, right
after the binary package is created.
</P>
<H3><A NAME="ch11_ 13">
11.4. Starting the Build
</A></H3>
<P>Now it's time to begin the build. First, we change directory into the directory holding
cdplayer's spec file:
</P>
<!-- CODE SNIP //-->
<PRE>
# cd /usr/src/redhat/SPECS
#
</PRE>
<!-- END CODE SNIP //-->
<P>Next, we start the build with an rpm -b command:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -ba cdplayer-1.0.spec
</PRE>
<!-- END CODE SNIP //-->
<P>The a following the -b option directs RPM to perform all phases of the build process.
Sometimes it is necessary to stop at various phases during the initial build to resolve problems
that crop up while writing the spec file. In these cases, other letters can be used after the
-b in order to stop the build at the desired phase. For this example, however, we will continue through
the entire build process.
</P>
<A NAME="PAGENUM-133"><P>Page 133</P></A>
<P>In this example, the only other argument to the build command is the name of the
package's spec file. This can be wildcarded to build more than one package, but in our example,
we'll stick with one.
</P>
<P>Let's look at RPM's output during the build:
</P>
<!-- CODE //-->
<PRE>
* Package: cdplayer
+ umask 022
+ echo Excuting: %prep
Excuting: %prep
+ cd /usr/src/redhat/BUILD
+ cd /usr/src/redhat/BUILD
+ rm -rf cdplayer-1.0
+ gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz
+ tar -xvvf -
drwxrwxr-x root/users 0 Aug 4 22:30 1996 cdplayer-1.0/
-rw-r--r-- root/users 17982 Nov 10 01:10 1995 cdplayer-1.0/COPYING
-rw-r--r-- root/users 627 Nov 10 01:10 1995 cdplayer-1.0/ChangeLog
-rw-r--r-- root/users 482 Nov 10 01:11 1995 cdplayer-1.0/INSTALL
.
.
.
-rw-r--r-- root/users 2720 Nov 10 01:10 1995 cdplayer-1.0/struct.h
-rw-r--r-- root/users 730 Nov 10 01:10 1995 cdplayer-1.0/vol.c
-rw-r--r-- root/users 2806 Nov 10 01:10 1995 cdplayer-1.0/volume.c
-rw-r--r-- root/users 1515 Nov 10 01:10 1995 cdplayer-1.0/volume.h
+ [ 0 -ne 0 ]
+ cd cdplayer-1.0
+ cd /usr/src/redhat/BUILD/cdplayer-1.0 + chown -R root.root .
+ chmod -R a+rX,g-w,o-w .
+ exit 0
</PRE>
<!-- END CODE //-->
<P>The output continues, but let's stop here for a moment and discuss what has happened so far.
</P>
<P>At the start of the output, RPM displays the package name
(cdplayer), sets the umask, and starts executing the
%prep section. Thanks to the %setup macro, RPM then changes
directory into the build area, removes any existing old sources, and extracts the sources from the
original compressed tar file. Although each file is listed as it is extracted, we've omitted most of
the files listed to save space.
</P>
<P>The %setup macro continues by changing directory into
cdplayer's top-level source directory and setting the file ownership and permissions properly. As you can see, it does quite a bit
of work for you.
</P>
<P>Let's take a look at the output from the %build section next:
</P>
<!-- CODE //-->
<PRE>
+ umask 022
+ echo Excuting: %build
Excuting: %build
+ cd /usr/src/redhat/BUILD
+ cd cdplayer-1.0
+ make
gcc -Wall -O2 -c -I/usr/include/ncurses cdp.c
gcc -Wall -O2 -c -I/usr/include/ncurses color.c
gcc -Wall -O2 -c -I/usr/include/ncurses display.c
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-134"><P>Page 134</P></A>
<!-- CODE //-->
<PRE>
gcc -Wall -O2 -c -I/usr/include/ncurses misc.c
gcc -Wall -O2 -c -I/usr/include/ncurses volume.c
volume.c: In function `mix_set_volume':
volume.c:67: warning: implicit declaration of function `ioctl'
gcc -Wall -O2 -c -I/usr/include/ncurses hardware.c
gcc -Wall -O2 -c -I/usr/include/ncurses database.c
gcc -Wall -O2 -c -I/usr/include/ncurses getline.c
gcc -o cdp cdp.o color.o display.o misc.o volume.o hardware.o database.o
getline.o -I/usr/include/ncurses -L/usr/lib -lncurses
groff -Tascii -man cdp.1 | compress >cdp.1.Z
+ exit 0
</PRE>
<!-- END CODE //-->
<P>There are no surprises here. After setting the umask and changing directory into
cdplayer's top-level directory, RPM issues the
make command we put into the spec file. The rest of
the output comes from make as it actually builds the software. Next comes the
%install section:
</P>
<!-- CODE //-->
<PRE>
+ umask 022
+ echo Excuting: %install
Excuting: %install
+ cd /usr/src/redhat/BUILD
+ cd cdplayer-1.0
+ make install
chmod 755 cdp
chmod 644 cdp.1.Z
cp cdp /usr/local/bin
ln -s /usr/local/bin/cdp /usr/local/bin/cdplay
cp cdp.1 /usr/local/man/man1
+ exit 0
</PRE>
<!-- END CODE //-->
<P>Just as in the previous sections, RPM again sets the umask and changes directory into the
proper directory. It then executes cdplayer's install target, installing the newly built software on
the build system. Those of you who carefully studied the spec file might have noticed that the
README file is not part of the install section. It's not a problem, as we see here:
</P>
<!-- CODE //-->
<PRE>
+ umask 022
+ echo Excuting: special doc
Excuting: special doc
+ cd /usr/src/redhat/BUILD
+ cd cdplayer-1.0
+ DOCDIR=//usr/doc/cdplayer-1.0-1
+ rm -rf //usr/doc/cdplayer-1.0-1
+ mkdir -p //usr/doc/cdplayer-1.0-1
+ cp -ar README //usr/doc/cdplayer-1.0-1
+ exit 0
</PRE>
<!-- END CODE //-->
<P>After the customary umask and cd commands, RPM constructs the path that will be used
for cdplayer's documentation directory. It then cleans out any preexisting directory and
copies the README file into it. The cdplayer app is now installed on the build system. The only
thing left to do is to create the actual package files and perform some housekeeping. The binary
package file is created first:
</P>
<!-- CODE SNIP //-->
<PRE>
Binary Packaging: cdplayer-1.0-1
Finding dependencies...
Requires (2): libc.so.5 libncurses.so.2.0
</PRE>
<!-- END CODE SNIP //-->
<P><CENTER>
<a href="0129-0131.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0135-0137.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?