📄 0185-0187.html
字号:
<HTML>
<HEAD>
<TITLE>Maximum RPM (RPM):Inside the Spec File: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=13 //-->
<!-- PAGES=0163-0204 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0182-0184.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0188-0191.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-185"><P>Page 185</P></A>
<B>
13.4.1.1. -n <name>: Set Name of Build Directory
</B>
<P>In the preceding example, the %setup macro simply uncompressed and unpacked the sources.
</P>
<P>In this case, the tar file containing the original sources was created so that the top-level
directory was included in the tar file. The name of the top-level directory was also identical to
that of the tar file, which was in
<name>-<version> format.
</P>
<P>However, this is not always the case. Quite often, the original sources unpack into a
directory whose name is different from the original
tar file. Since RPM assumes that the directory
will be called <name>-<version>, when the directory is called something else, it's necessary to
use %setup's -n option. Here's an example: Assume for a moment that the
cdplayer sources, when unpacked, create a top-level directory named
cd-player. In this case, our %setup line would look like this:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -n cd-player
</PRE>
<!-- END CODE SNIP //-->
<P>and the resulting commands would look like this:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cd-player
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd cd-player
cd /usr/src/redhat/BUILD/cd-player
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>The results are identical to using %setup with no options, except for the fact that
%setup now does a recursive delete on the directory
cd-player (instead of cdplayer-1.0) and changes
directory into cd-player (instead of cdplayer-1.0).
</P>
<P>Note that all subsequent build-time scripts will change directory into the directory
specified by the -n option. This makes -n unsuitable as a means of unpacking sources in directories
other than the top-level build directory. In the following sections, we'll show a way around this
restriction.
</P>
<P>A quick word of warning: If the name specified with the
-n option doesn't match the name of the directory created when the sources are unpacked, the build will stop pretty quickly, so
it pays to be careful when using this option.
</P>
<B>
13.4.1.2. -c: Create Directory (and Change to It) Before Unpacking
</B>
<P>How many times have you grabbed a tar file and unpacked it, only to find that it
splattered files all over your current directory? Sometimes source archives are created without a
top-level directory.
</P>
<P>As you can see from the examples so far, %setup expects the archive to create its own
top-level directory. If this isn't the case, you'll need to use the
-c option.
</P>
<A NAME="PAGENUM-186"><P>Page 186</P></A>
<P>This option simply creates the directory and changes directory into it before unpacking
the sources. Here's what it looks like:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
mkdir -p cdplayer-1.0
cd cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>The only changes from using %setup with no options are the
mkdir and cd commands, prior to the commands that unpack the sources. Note that you can use the
-n option along with -c, so something like %setup -c -n
blather works as expected.
</P>
<B>
13.4.1.3. -D: Do Not Delete Directory Before Unpacking Sources
</B>
<P>The -D option keeps the %setup macro from deleting the software's top-level directory.
This option is handy when the sources being unpacked are to be added to an already-existing
directory tree. This would be the case when more than one
%setup macro is used. Here's what %setup does when the
-D option is employed:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>As advertised, the rm prior to the tar command is gone.
</P>
<B>
13.4.1.4. -T: Do Not Perform Default Archive Unpacking
</B>
<P>The -T option disables %setup's normal unpacking of
the archive file specified on the source0 line. Here's
what the resulting commands look like:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.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 .
</PRE>
<!-- END CODE //-->
<P>Doesn't make much sense, does it? There's a method to this madness. We'll see the
-T in
action in the next section.
</P>
<A NAME="PAGENUM-187"><P>Page 187</P></A>
<B>
13.4.1.5. -b <n>: Unpack the nth Sources Before Changing Directory
</B>
<P>The -b option is used in conjunction with the
source tag. Specifically, it is used to identify which of the numbered
source tags in the spec file are to be unpacked.
</P>
<P>The -b option requires a numeric argument matching an existing source tag. If a numeric
argument is not provided, the build will fail:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -ba cdplayer-1.0.spec
Package: cdplayer
Need arg to %setup -b
Build failed.
#
</PRE>
<!-- END CODE SNIP //-->
<P>Remembering that the first source tag is implicitly numbered
0, let's see what happens when the %setup line is changed to
%setup -b 0:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>That's strange. The sources were unpacked twice. It doesn't make sense until you realize
that this is why there is a -T option. Since -T disables the default source file unpacking, and
-b selects a particular source file to be unpacked, the two are meant to go together, like this:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -T -b 0
</PRE>
<!-- END CODE SNIP //-->
<P>Looking at the resulting commands, we find this:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>That's more like it! Let's go on to the next option.
</P>
<P><CENTER>
<a href="0182-0184.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0188-0191.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -