Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56870
  • 博文数量: 14
  • 博客积分: 1425
  • 博客等级: 上尉
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-30 10:33
文章分类

全部博文(14)

文章存档

2011年(5)

2006年(9)

我的朋友

分类: LINUX

2011-02-14 15:47:12

Building an RPM from a Tar Archive
Now that you understand the basics of building an RPM from an SRPM, it’s relatively
easy to build an SRPM and an RPM from a tar archive, sometimes also known as
a “tarball.”
Obtain the Source Files
You’ll need to obtain the source code for the package you want to create. You’ll need
to locate the FTP or Web site for the software you want, obtain the version of your
choice, download it, and then put it in the SOURCES directory.
Create the Spec File
Here’s where you get to brew a spec file from scratch. While spec files can be complex,
this section just covers the basics you’ll need to get a spec file running.
The Preamble Open up a spec file in your favorite text editor. Start with the
preamble. Here’s the preamble (abridged) from version 4.1 of the fileutils.spec
configuration file:
Summary: The GNU versions of common file management utilities.
Name: fileutils
Version: 4.1
Release: 10
License: GPL
Group: Applications/File
Source0: {name}-%{version}.tar.bz2
Source1: DIR_COLORS
Using the Red Hat Package Manager 209
Source2: colorls.sh
Source3: colorls.csh
Patch1: fileutils-4.0-spacedir.patch
Patch2: fileutils-4.0s-sparc.patch

Patch15: fileutils-4.1-chown-optparse.patch
Buildroot: %{_tmppath}/%{name}-%{version}-root
Prereq: /sbin/install-info
BuildRequires: libtermcap-devel glibc-devel gcc make binutils fileutils
%description
The fileutils package includes a number of GNU versions of common and
popular file management utilities. Fileutils includes the following…
Preamble entries consist of a tag, followed by a colon, followed by information.
Some entries are language-specific; these are denoted by a two-letter country code in
parentheses just before the colon. The order of the lines is unimportant. Table 4-12
lists entries that may be part of the preamble.
Tag Description
Name The name of the package.
Version The version of the software being packaged.
Release The number of times this software has been packaged.
Buildroot The directory this package was built in.
Copyright Contains the software’s copyright information.
Group The software category associated with this package.
Patch Patches applied to the software.
Source Two entries are associated with this tag. The first indicates where the
packaged software’s source may be found. The second gives the name
of the source file in the SOURCES subdirectory.
Summary A short, one-line description of the software being packaged.
URL If present, this lists the Web page that contains documentation for this
package.
Distribution The company this package was created for, such as Red Hat. Usually
includes a version number such as 8.0.
Vendor The group or organization that distributes the package.
Packager The group or organization that packaged this software.
Description A detailed description of the packaged software.
TABLE 4-12
Preamble Entries
in a Spec File
210 Chapter 4: Basic Configuration and Administration
The Prep Section The prep section prepares the source files for packaging.
Usually it starts by deleting leftover files from previous builds with a command such
as rm -rf. Then it unarchives the source files and applies any required patches. A sample
prep section might look like this:
%prep
/bin/rm -rf $RPM_BUILD_DIR/foo-2.2
/bin/tar xzf $RPM_SOURCE_DIR/foo-2.2.tar.gz
Note that the prep section is nothing more than a shell script. The environment
variables RPM_BUILD_DIR and RPM_SOURCE_DIR are preset by RPM. They
expand to /usr/src/redhat/BUILD and /usr/src/redhat/SOURCE, respectively. This
prep script extracts the contents of foo-2.2.tar.gz into the SOURCE directory. Any
patches to the source would be applied here.
There is a predefined macro that will handle both steps from the previous example.
The %setup macro removes any files left over from a previous build and then extracts
the contents of the source file. Now, we can simplify the prep script:
%prep
%setup
The Build Section Like the prep section, the build section is also a shell script.
This script will handle building binary programs out of the source code. Depending
on the software, this step may be very easy, or quite involved. A sample build script
might be:
%build
make clean
./configure -prefix=/usr -exec-prefix=/
make
The “make clean” command removes old objects and configuration files. Then the
configure script is run with some options which sets up the installation on a computer
such as one based on the Intel architecture. The make command then can compile
the software.
The Install Section Yet another shell script, the install section, allows you to
build a set of installation files within the source distribution. If the application is
straightforward, the install commands may be as simple as:
%install
make install
The Files Section This is a list of files that will become part of the package. Any
files you want to distribute in the package must be listed here.
You may specify a %doc directive on a line, which indicates that the file listed on
this line is documentation. That file will be placed in the /usr/doc/package subdirectory
when the end user installs this package on the system. Here’s an example of a files
section from our fictional package foo-2.2:
%files
%doc README
%doc FAQ
/usr/bin/foo
/usr/man/man1/foo.1
This example installs the README and FAQ files in the /usr/doc/foo-2.2 subdirectory.
Building the RPM and the SRPM
Now that you’ve prepared your spec file, you’re ready to build the RPM and the SRPM
with the following command:
# rpm -ba foo-2.2.spec
You can build your packages in slightly different ways, as described in the command
switches shown in Table 4-13.
Testing Your RPM
It’s important you test your RPM thoroughly before releasing it for general distribution.
Install it, uninstall it, run the program through its paces. Make sure the documentation
and man pages were installed correctly and that configuration files are present and
have sane defaults.
Using the Red Hat Package Manager 211
Option Description
-bp Execute only the prep section.
-bl Check the files section to make sure all the files exist.
-bc Execute only the build section.
-bi Execute only the install section.
-bs Build only the SRPM.
--test Do not execute any build stages. (Useful for testing the syntax of your
spec file.)
TABLE 4-13
rpm Switches for
Building RPMs
and SRPMs
212 Chapter 4: Basic Configuration and Administration
Like many other Linux commands, rpm has short and long versions of the same
switch. For example, -i is the same as --install (note the double dash before the
long version). You can learn which options have “long” equivalents by checking
the man page for that command.

阅读(630) | 评论(0) | 转发(0) |
0

上一篇:Apache http服务配置文件说明

下一篇:无题

给主人留下些什么吧!~~