LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 7639|回复: 9

怎么制作RPM包啊?

[复制链接]
发表于 2003-3-14 15:16:46 | 显示全部楼层 |阅读模式
谁能告诉我怎么制作RPM包啊?
发表于 2003-3-14 15:51:52 | 显示全部楼层
RPM是Redhat Package Manage的缩写。透过RPM的管理,使用者可以把Source Code包装成一种Source和Binary的档案形式。利用它,我们可以用Binary的档案进行安装,用 Source 的档案形式重新整理包装。许多Linux爱好者对安装RPM包比较熟悉,但对如何在Linux下制作RPM包不甚了解,因此,我将通过实例,讲解如何在Linux下制作RPM包。

1. 最初要求
为了创建RPM,你需要RPM要编译的源代码、一个rpmrc文件(设置一些RPM的缺省值并控制它的行为),以及一个spec文件(控制包的建立过程)。这里假定已有其它的开发环境(gcc、make、install、vi等),而且你的源代码已经编译成功。

2. 制作流程
1)确定/etc/rpmrc(也可能是/usr/lib/rpm/rpmrc)已经正确设定。rpmrc文件控制几乎所有RPM的行为。如果你想重载一个或多个全局设置,可以在~/.rpmrc文件中包含你的定制。可以使用rpm--showrc来显示RPM的当前设置。大多数情况下,rpmrc 文件的设置不需要改变。

2)取回所建造的源代码并放入正确的目录中。

3)编写spec文件。

4)使用rpm -ba 来构造整个程式套件。

3.应用举例
现在以Lynx实用程序来介绍构造RPM包的整个过程。Lynx是在文本方式下的Web浏览器,可以从ftp://www.slcc.edu/pub/lynx/取得。

1)得到lynx源代码。

2)lynx-2.8.spec文件的详细编写方法略。

3)使用RPM来构造包。

按照rpmrc文件的缺省设置,应该把lynx-2.8.spec文件放入SPECS/目录下,然后执行:

rpm -ba lynx-2.8.spec

其中-b 表示prep、compile、install,并build出一份binary RPM包。-a 表示执行所有的build动作,即还要build 出一份source code RPM包。

如果一切顺利的话,可以在RPMS/目录下找到lynx-2.8-4.i386.rpm文件。可以执行:

rpm -qpl lynx-2.8-4.i386.rpm

来观察RPM 包中是否包含了要求的所有文件。

为了测试它的正确性,可以拷贝此文件到另一台机器上,并执行:

rpm -ivh lynx-2.8-4.i386.rpm

进行安装测试。

一旦测试成功,就可以上载你的大作,享受成功的喜悦。

小结

制作RPM包需要开发人员做很多工作。比如不仅要懂得c/c++编程,而且还要能熟练掌握像make、autoconf、diff、patch、tar、install等工具的使用并能编写spec文件。但从长远来看,应用RPM,在软件包的维护和方便性方面使得开发者受益。
发表于 2003-3-15 22:33:44 | 显示全部楼层
好啊
发表于 2003-8-12 23:56:51 | 显示全部楼层
有没有软件来完成这些工作?
发表于 2003-8-13 00:48:28 | 显示全部楼层
制作rpm也并不难,关键是掌握SPEC的书写规则,而这些规则又有几个部分。具体资料可参考redhat的maxrpm及rpm howto文档。
发表于 2003-8-13 09:59:08 | 显示全部楼层
那怎么把rpm包分解开来呢?
发表于 2003-8-13 16:09:27 | 显示全部楼层
这儿有一个编RPM的教程,不过是英文的,从培训教材上cp地。。。


-----------------------------------------------------------------
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: ftp://alpha.gnu.org/gnu/fetish/%{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.
发表于 2003-8-13 16:12:38 | 显示全部楼层
哪位可以拿一个实例来详细的讲解一下,就very gooooooooooood

英文教材虽能看懂,但涉及到具体制做中,可能会出现好多问题。。。

希望能详细说一下spec文件的编写。。。
发表于 2009-9-23 19:17:25 | 显示全部楼层
Post by moxnet;321948
哪位可以拿一个实例来详细的讲解一下,就very gooooooooooood

英文教材虽能看懂,但涉及到具体制做中,可能会出现好多问题。。。

希望能详细说一下spec文件的编写。。。
这里有一个显示主机名的程序:
制作rpm过程:
(1)编辑源文件
#cd /usr/src/redhat/SOURCES
# vi showhost.sh
脚本程序如下:
#!/bin/bash
HOST=`/bin/hostname`
/bin/echo $HOST
修改程序属性
#chmod 755 showhost.sh
将程序打包:
# tar zxvf showhost.tar.gz showhost.sh
(2)编辑showhost.spec文件
#cd /usr/src/redhat/SPECS
#vi showhost.spec
输入内容如下:
Summary:   This is a demo RPM Package.
Name:  showhost
Version: 1.0
Release: 1
License: GPL
Group: My Home
Source: showhost.tar.gz
Url: http://www.buaa.edu.cn
Packager: test

%description
This package is just a demo RPM/

%prep
%setup -c
%install
install -m 755 showhost.sh /usr/local/bin/showhost.sh

%files
/usr/local/bin/showhost.sh
(3)开始编译并打包成RPM包,命令如下:
#rpmbuild -ba showhost.spec

进行安装
#rpm -ivh ../RPMS/i386/showhost-1.0-1-i386.rpm

查询一下showhost的包信息
#rpm -qi showhost

好了,一个简单完整的RPM包制作的例子。

参考:《Red Hat Enterprise Linux 4.0 系统配置与管理》 林晓飞等著 清华大学出版社
回复 支持 反对

使用道具 举报

发表于 2010-3-8 18:58:59 | 显示全部楼层
学习了 :)顶起
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表