0150-0153.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 363 行

HTML
363
字号




<HTML>

<HEAD>

<TITLE>Maximum RPM (RPM):rpm -b Command Reference: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=12 //-->

<!-- PAGES=0139-0162 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0147-0149.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0154-0157.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-150"><P>Page 150</P></A>







<P>But there's another way. Just follow these steps:

</P>



<OL>

<LI>          Place the original source tar file in RPM's

SOURCES directory.

<LI>          Create a partial spec file in RPM's

SPECS directory (be sure to include a valid Source line).

<LI>          Issue an rpm -bp to properly create the build environment.

</OL>



<P>Now use --short-circuit to attempt a compile. Here's an example:

</P>



<!-- CODE //-->

<PRE>

# rpm -bc --short-circuit cdplayer-1.0.spec

* Package: cdplayer

+ umask 022

+ echo Executing: %build

Executing: %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

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 &gt;cdp.1.Z

+ exit 0

#

</PRE>

<!-- END CODE //-->



<P>Normally, the -bc option instructs RPM to stop the build after the

%build section of the spec file has been executed. By adding

--short-circuit, however, RPM starts the build by

executing the %build section and stops when everything in

%build has been executed.

</P>



<P>There is only one other build stage that can be

--short-circuited: the install stage. The reason for this restriction is to make it difficult to bypass RPM's use of pristine sources. If it

were possible to --short-circuit to -bb or -ba, a package builder might take the easy way out

and simply hack at the build tree until the software built successfully, then package the

hacked sources. So, RPM will only --short-circuit to

-bc or -bi. Nothing else will do.

</P>



<P>What exactly does an rpm -bi --short-circuit do, anyway? Like an

rpm -bc --short-

</P>



<P>circuit, it starts executing at the named stage, which in this case is

%install. Note that the build environment must be ready to perform an install before attempting to

--short-circuit to the %install stage. If the software installs via

make install, make will automatically compile the software anyway.

</P>



<A NAME="PAGENUM-151"><P>Page 151</P></A>







<P>And what happens if the build environment isn't ready and a

--short-circuit is attempted? Let's see:

</P>



<!-- CODE //-->

<PRE>

# rpm -bi --short-circuit cdplayer-1.0.spec

* Package: cdplayer

+ umask 022

+ echo Executing: %install

Executing: %install

+ cd /usr/src/redhat/BUILD

+ cd cdplayer-1.0

/var/tmp/rpmbu01157aaa: cdplayer-1.0: No such file or directory

Bad exit status

#

</PRE>

<!-- END CODE //-->



<P>RPM blindly started executing the %install stage, but came to an abrupt halt when it

attempted to change directory into cdplayer-1.0, which didn't exist. After giving a descriptive error

message, RPM exited with a failure status. Except for some minor differences,

rpm -bc would have failed in the same way.

</P>



<H4><A NAME="ch12_ 6">

12.1.8. --buildarch &lt;arch&gt;: Perform a Build for the

&lt;arch&gt; Architecture

</A></H4>



<P>The --buildarch option is used to override RPM's architecture detection logic.

The option is followed by the desired architecture name. Here's an example:

</P>



<!-- CODE //-->

<PRE>

# rpm -ba --buildarch i486 cdplayer-1.0.spec

Package: cdplayer

...

Binary Packaging: cdplayer-1.0-1

...

Wrote: /usr/src/redhat/RPMS/i486/cdplayer-1.0-1.i486.rpm

...

Wrote: /usr/src/redhat/SRPMS/cdplayer-1.0-1.src.rpm

#

</PRE>

<!-- END CODE //-->



<P>We've removed most of RPM's output from this example, but the main thing we can see

from this example is that the package was built for the

i486 architecture, due to the inclusion of the

--buildarch option on the command line. We can also see that RPM wrote the binary

package in the architecture-specific directory,

/usr/src/redhat/RPMS/i486. Using RPM's

--queryformat option confirms the package's architecture:

</P>



<!-- CODE //-->

<PRE>

# rpm -qp --queryformat `%{arch}\n'\

&gt; /usr/src/redhat/RPMS/i486/cdplayer-1.0-1.i486.rpm

i486

#

</PRE>

<!-- END CODE //-->



<P>For more information on build packages for multiple architectures, see Chapter 19,

&quot;Building Packages for Multiple Architectures and Operating Systems.&quot;

</P>



<A NAME="PAGENUM-152"><P>Page 152</P></A>







<H4><A NAME="ch12_ 7">

12.1.9. --buildos &lt;os&gt;: Perform Build for the

&lt;os&gt; Operating System

</A></H4>



<P>The --buildos option is used to override RPM's operating system detection logic. The

option is followed by the desired operating system name. Here's an example:

</P>



<!-- CODE //-->

<PRE>

# rpm -ba --buildos osf1 cdplayer-1.0.spec

...

Binary Packaging: cdplayer-1.0-1

...

Wrote: /usr/src/redhat/RPMS/i386/cdplayer-1.0-1.i386.rpm

Source Packaging: cdplayer-1.0-1

...

Wrote: /usr/src/redhat/SRPMS/cdplayer-1.0-1.src.rpm

#

</PRE>

<!-- END CODE //-->



<P>There's nothing in the build output that explicitly states that the build operating system

has been set to osf1. Let's see if --queryformat will tell us:

</P>



<!-- CODE SNIP //-->

<PRE>

# rpm -qp --queryformat `%{os}\n'\

&gt; /usr/src/redhat/RPMS/i386/cdplayer-1.0-1.i386.rpm

osf1

#

</PRE>

<!-- END CODE SNIP //-->



<P>The package was indeed built for the specified operating system. For more information

on building packages for multiple operating systems, see Chapter 19.

</P>



<H4><A NAME="ch12_ 8">

12.1.10. --sign: Add a Digital Signature to the Package

</A></H4>



<P>The --sign option directs RPM to add a digital signature to the package being built.

Currently, this is done using PGP. Here's an example of

--sign in action:

</P>



<!-- CODE //-->

<PRE>

# rpm -ba --sign cdplayer-1.0.spec

Enter pass phrase: &lt;passphrase&gt; (not echoed)

Pass phrase is good.

Package: cdplayer

...

Binary Packaging: cdplayer-1.0-1

...

Generating signature: 1002

Wrote: /usr/src/redhat/RPMS/i386/cdplayer-1.0-1.i386.rpm

...

Source Packaging: cdplayer-1.0-1

...

Generating signature: 1002

Wrote: /usr/src/redhat/SRPMS/cdplayer-1.0-1.src.rpm

#

</PRE>

<!-- END CODE //-->



<P>The most obvious effect of adding the --sign option to a build command is that RPM

then asks for your private key's passphrase. After entering the passphrase (which isn't echoed),

the build proceeds as usual. The only other difference between this and a nonsigned build is

that the Generating signature: lines have a nonzero value.

</P>



<A NAME="PAGENUM-153"><P>Page 153</P></A>







<P>Let's check the source and binary packages we've just created to see if they are, in fact, signed:

</P>



<!-- CODE //-->

<PRE>

# rpm --checksig /usr/src/redhat/SRPMS/cdplayer-1.0-1.src.rpm

/usr/src/redhat/SRPMS/cdplayer-1.0-1.src.rpm: size pgp md5 OK

# rpm --checksig /usr/src/redhat/RPMS/i386/cdplayer-1.0-1.i386.rpm

/usr/src/redhat/RPMS/i386/cdplayer-1.0-1.i386.rpm: size pgp md5 OK

#

</PRE>

<!-- END CODE //-->



<P>The fact that there is a pgp in --checksig's output indicates that the packages have been signed.

</P>



<P>For more information on signing packages, see Chapter 17, &quot;Adding PGP Signatures to a

Package.&quot; Appendix G, &quot;An Introduction to PGP,&quot; contains information on obtaining and

installing PGP.

</P>



<H4><A NAME="ch12_ 9">

12.1.11. --test: Create, Save Build Scripts for Review

</A></H4>



<P>There are times when it might be necessary to get a more in-depth view of a particular

build. By using the --test option, it's easy. When

--test is added to a build command, the scripts RPM would normally use to actually perform the build are created and saved for you to

review. Let's see how it works:

</P>



<!-- CODE SNIP //-->

<PRE>

# rpm -ba --test cdplayer-1.0.spec

Package: cdplayer

#

</PRE>

<!-- END CODE SNIP //-->



<P>Unlike in a normal build, there's not much output. But the

--test option has caused a set of scripts to be written

and saved for you. Where are they?

</P>



<P>If you are using a customized rpmrc file, the scripts will be written to the directory specified

by the rpmrc entry tmppath. If you haven't changed this setting, RPM, by default, writes the

scripts in /var/tmp. Here they are:

</P>



<!-- CODE //-->

<PRE>

# ls -l /var/tmp

total 4

-rw-rw-r--    1 root    root       670 Sep 17 20:35 rpmbu00236aaa

-rw-rw-r--    1 root    root       449 Sep 17 20:35 rpmbu00236baa

-rw-rw-r--    1 root    root       482 Sep 17 20:35 rpmbu00236caa

-rw-rw-r--    1 root    root       552 Sep 17 20:35 rpmbu00236daa

#

</PRE>

<!-- END CODE //-->



<P>Each file contains a script that performs a given part of the build. Here's the first file:

</P>



<!-- CODE //-->

<PRE>

#!/bin/sh -e

# Script generated by rpm



RPM_SOURCE_DIR=&quot;/usr/src/redhat/SOURCES&quot;

RPM_BUILD_DIR=&quot;/usr/src/redhat/BUILD&quot;

RPM_DOC_DIR=&quot;/usr/doc&quot;

RPM_OPT_FLAGS=&quot;-O2 -m486 -fno-strength-reduce&quot;

RPM_ARCH=&quot;i386&quot;

RPM_OS=&quot;Linux&quot;

RPM_ROOT_DIR=&quot;/tmp/cdplayer&quot;

RPM_BUILD_ROOT=&quot;/tmp/cdplayer&quot;

RPM_PACKAGE_NAME=&quot;cdplayer&quot;

</PRE>

<!-- END CODE //-->



<P><CENTER>

<a href="0147-0149.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0154-0157.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

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