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

📄 0192-0194.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 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="0188-0191.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0195-0197.html">Next</A>

</CENTER></P>



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



<P>Here are the resulting commands:

</P>

<!-- CODE SNIP //-->

<PRE>

echo &quot;Patch #0:&quot;

patch -p0 -s &lt; /usr/src/redhat/SOURCES/patch-zero

</PRE>

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



<P>The %patch macro nicely displays a message showing that a patch is being applied, and

then invokes the patch command to actually do the dirty work. There are two options to the

patch command:

</P>



<UL>

<LI>          The -p option, which directs

patch to remove the specified number of slashes (and

any intervening directories) from the front of any filenames specified in the patch file.

In this case, nothing will be removed.

<LI>          The -s option, which directs

patch to apply the patch without displaying any

informational messages. Only errors from patch will be displayed.

</UL>



<P>How did the %patch macro know which patch to apply? Keep in mind that, like the

source tag lines, every patch tag is numbered, starting at

0. The %patch macro, by default, applies the patch file named on the patch (or

patch0) tag line.

</P>



<B>

13.4.2.1. Specifying Which patch Tag to Use

</B>



<P>The %patch macro actually has two different ways to specify the

patch tag line it is to use. The first method is to simply append the number of the desired

patch tag to the end of the %patch macro itself. For example, in order to apply the patch specified on the

patch2 tag line, the following %patch macro could be used:

</P>

<!-- CODE SNIP //-->

<PRE>

%patch2

</PRE>

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



<P>The other approach is to use the -P option. This option is followed by the number of the

patch tag line desired. Therefore, this line is identical in function to the previous one:

</P>

<!-- CODE SNIP //-->

<PRE>

%patch -P 2

</PRE>

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



<P>Note that the -P option will not apply the file specified on the

patch0 line, by default. Therefore, if you choose to use the

-P option to specify patch numbers, you'll need to use the

following format when applying patch 0:

</P>

<!-- CODE SNIP //-->

<PRE>

%patch -P 0

</PRE>

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



<B>

13.4.2.2. -p &lt;#&gt;: Strip &lt;#&gt; Leading Slashes and Directories from

patch Filenames

</B>



<P>The -p (note the lowercase p!) option is sent directly to the

patch command. It is followed by a number, which specifies the number of leading slashes (and the directories in between)

to strip from any filenames present in the patch file. For more information on this option,

consult the patch man page.

</P>



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







<B>

13.4.2.3. -b &lt;name&gt;: Set the Backup File Extension to

&lt;name&gt;

</B>



<P>When the patch command is used to apply a patch, unmodified copies of the files patched

are renamed to end with the extension .orig. The

-b option is used to change the extension used by

patch. This is normally done when multiple patches are to be applied to a given file.

By doing this, copies of the file as it existed prior to each patch are readily available.

</P>



<B>

13.4.2.4. -E: Remove Empty Output Files

</B>



<P>The -E option is passed directly to the patch program. When

patch is run with the -E option, any output files that are empty after the patches have been applied are removed.

</P>



<P>Now let's take %patch on a test drive.

</P>



<B>

13.4.2.5. An Example of the %patch Macro in Action

</B>



<P>Using the sample patch tag lines we've used throughout this section, let's put together an

example and look at the resulting commands. In our example, the first patch to be applied

needs to have the root directory stripped. Its

%patch macro will look like this:

</P>

<!-- CODE SNIP //-->

<PRE>

%patch -p1

</PRE>

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



<P>The next patch is to be applied to files in the software's

lib subdirectory, so we'll need to add a cd command to get us there. We'll also need to strip an additional directory:

</P>

<!-- CODE SNIP //-->

<PRE>

cd lib

%patch -P 1 -p2

</PRE>

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



<P>Finally, the last patch is to be applied from the software's top-level directory, so we need to

cd back up a level. In addition, this patch modifies some files that were also patched the first

time, so we'll need to change the backup file extension:

</P>

<!-- CODE SNIP //-->

<PRE>

cd ..

%patch -P 2 -p1 -b .last-patch

</PRE>

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



<P>Here's what the %prep script (minus any %setup macros) looks like:

</P>



<!-- CODE SNIP //-->

<PRE>

%patch -p1

cd lib

%patch -P 1 -p2

cd ..

%patch -P 2 -p1 -b .last-patch

</PRE>

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



<P>And here's what the macros expand to:

</P>



<!-- CODE //-->

<PRE>

echo &quot;Patch #0:&quot;

patch -p1 -s &lt; /usr/src/redhat/SOURCES/patch-zero

cd lib

echo &quot;Patch #1:&quot;

patch -p2 -s &lt; /usr/src/redhat/SOURCES/patch-one

cd ..

echo &quot;Patch #2:&quot;

patch -p1 -b .last-patch -s &lt; /usr/src/redhat/SOURCES/patch-two

</PRE>

<!-- END CODE //-->



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



<P>No surprises here. Note that the %setup macro leaves the current working directory set to

the software's top-level directory, so our cd commands with their relative paths will do the

right thing. Of course, we have environment variables available that could be used here, too.

</P>



<B>

13.4.2.6. Compressed Patch Files

</B>



<P>If a patch file is compressed with gzip, RPM will automatically decompress it

before applying the patch. Here's a compressed

patch file as specified in the spec file:

</P>

<!-- CODE SNIP //-->

<PRE>

Patch: bother-3.5-hack.patch.gz

</PRE>

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



<P>This is part of the script RPM will execute when the

%prep section is executed:

</P>



<!-- CODE //-->

<PRE>

echo Executing: %prep

...

echo &quot;Patch #0:&quot;

gzip -dc /usr/src/redhat/SOURCES/bother-3.5-hack.patch.gz | patch -p1 -s

...

</PRE>

<!-- END CODE //-->



<P>First, the patch file is decompressed using

gzip. The output from gzip is then piped into

patch.

</P>



<P>That's about it for RPM's macros. Next, let's take a look at the

%files list.

</P>



<H3>

13.5. The %files List

</H3>



<P>The %files list indicates to RPM which files on the build system are to be packaged. The

list consists of one file per line. The file may have one or more directives preceding it. These

directives give RPM additional information about the file.

</P>



<P>Normally, each file includes its full path. The path performs two functions. First, it

specifies the file's location on the build system. Second, it denotes where the file should be placed

when the package is to be installed. (This is not entirely the case when a relocatable package is

being built. For more information on relocatable packages, see Chapter 15.)

</P>



<P>For packages that create directories containing hundreds of files, it can be quite

cumbersome creating a list that contains every file. To make this situation a bit easier, if the

%files list contains a path to a directory, RPM will automatically package every file in that directory, as

well as every file in each subdirectory. Shell-style globbing, or wildcard expansion, can also be

used in the %files list.

</P>



<H3><A NAME="ch13_ 10">

13.6. Directives for the %files List

</A></H3>



<P>The %files list may contain a number of different directives. They are used to do the

following:

</P>



<UL>

<LI>          Identify documentation and configuration files

<LI>          Ensure that a file has the correct permissions and ownership set

</UL>



<P><CENTER>

<a href="0188-0191.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0195-0197.html">Next</A>

</CENTER></P>











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

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

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