📄 0188-0191.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="0185-0187.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0192-0194.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-188"><P>Page 188</P></A>
<B>
13.4.1.6. -a <n>: Unpack the nth Sources After Changing Directory
</B>
<P>The -a option works similarly to the -b option, except that the sources are unpacked after
changing directory into the top-level build directory.
Like the -b option, -a requires -T in order to prevent two sets of unpacking commands. Here are the commands that a
%setup -T -a 0 line would produce:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf 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>Note that there is no mkdir command to create the top-level
directory prior to issuing a cd into it. In our example, adding the
-c option will make things right:
</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 result is the proper sequence of commands for unpacking a
tar file with no top-level directory.
</P>
<B>
13.4.1.7. Using %setup in a Multisource Spec File
</B>
<P>If all these interrelated options seem like overkill for unpacking a single source file, you're
right. The real reason for the various options is to make it easier to combine several separate
source archives into a single, buildable entity. Let's see how they work in that type of environment.
</P>
<P>For the purposes of this example, our spec file will have the following three
source tags (yes, the source tags should include a URL pointing to the
sources):
</P>
<!-- CODE SNIP //-->
<PRE>
source: source-zero.tar.gz
source1: source-one.tar.gz
source2: source-two.tar.gz
</PRE>
<!-- END CODE SNIP //-->
<P>To unpack the first source is not hard; all that's required is to use
%setup with no options:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-189"><P>Page 189</P></A>
<P>This produces the following set of commands:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | 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>If source-zero.tar.gz didn't include a top-level directory, we could have made one by
adding the -c option:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -c
</PRE>
<!-- END CODE SNIP //-->
<P>which would result in the following:
</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/source-zero.tar.gz | 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>Of course, if the top-level directory did not match the package name, the
-n option could have been added:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -n blather
</PRE>
<!-- END CODE SNIP //-->
<P>which results in the following:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf blather
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd blather
cd /usr/src/redhat/BUILD/blather
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>Or this:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -c -n blather
</PRE>
<!-- END CODE SNIP //-->
<P>results in the following:
</P>
<!-- CODE SNIP //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf blather
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-190"><P>Page 190</P></A>
<!-- CODE //-->
<PRE>
mkdir -p blather
cd blather
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd /usr/src/redhat/BUILD/blather
chown -R root.root .
chmod -R a+rX,g-w,o-w .
</PRE>
<!-- END CODE //-->
<P>Now let's add the second source file. Things get a bit more interesting here. First, we need
to identify which source tag (and, therefore, which
source file) we're talking about. So we need to use
either the -a or -b option, depending on the characteristics of the source archive.
For this example, let's say that -a is the option we want. Adding that option, plus a
1 to point to the source file specified in the
source1 tag, we have this:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -a 1
</PRE>
<!-- END CODE SNIP //-->
<P>Since we've already seen that using the -a or
-b option results in duplicate unpacking, we need to disable the default unpacking by adding the
-T option:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup -T -a 1
</PRE>
<!-- END CODE SNIP //-->
<P>Next, we need to make sure that the top-level directory
isn't deleted. Otherwise, the first source file we just unpacked would be gone.
That means we need to include the -D option to
prevent that from happening. Adding this final option, and including the now complete macro in
our %prep script, we now have this:
</P>
<!-- CODE SNIP //-->
<PRE>
%setup
%setup -T -D -a 1
</PRE>
<!-- END CODE SNIP //-->
<P>This will result in the following commands:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | 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 .
cd /usr/src/redhat/BUILD
cd cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-one.tar.gz | 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>So far, so good. Let's include the last source file, but
with this one, we'll say that it needs to be unpacked in a subdirectory of
cdplayer-1.0 called database. Can we use %setup in this case?
</P>
<A NAME="PAGENUM-191"><P>Page 191</P></A>
<P>We could, if source-two.tgz creates the database subdirectory. If not, then it'll be necessary
to do it by hand. For the purposes of our example, let's say that
source-two.tgz wasn't created to include the database subdirectory, so we'll have to do it ourselves. Here's our
%prep script now:
</P>
<!-- CODE //-->
<PRE>
%setup
%setup -T -D -a 1
mkdir database
cd database
gzip -dc /usr/src/redhat/SOURCES/source-two.tar.gz | tar -xvvf -
</PRE>
<!-- END CODE //-->
<P>Here's the resulting script:
</P>
<!-- CODE //-->
<PRE>
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | 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 .
cd /usr/src/redhat/BUILD
cd cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-one.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
mkdir database
cd database
gzip -dc /usr/src/redhat/SOURCES/source-two.tar.gz | tar -xvvf -
</PRE>
<!-- END CODE //-->
<P>The three commands we added to unpack the last set of sources were added to the end of
the %prep script.
</P>
<P>The bottom line to using the %setup macro is that you can probably get it to do what you
want, but don't be afraid to tinker. And even if
%setup can't be used, it's easy enough to add the necessary commands to do the work manually. Above all, make sure you use the
--test option when testing your %setup macros, so you can see what commands they're translating to.
</P>
<H4>
13.4.2. The %patch Macro
</H4>
<P>The %patch macro, as its name implies, is used to apply patches to the unpacked sources.
</P>
<P>In the following examples, our spec file has the following
patch tag lines:
</P>
<!-- CODE SNIP //-->
<PRE>
patch0: patch-zero
patch1: patch-one
patch2: patch-two
</PRE>
<!-- END CODE SNIP //-->
<P>At its simplest, the %patch macro can be invoked without any options:
</P>
<!-- CODE SNIP //-->
<PRE>
%patch
</PRE>
<!-- END CODE SNIP //-->
<P><CENTER>
<a href="0185-0187.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0192-0194.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -