Press "Enter" to skip to content

Linux rpmbuild简单介绍

本博客先前介绍过如何解压rpm包,演示了将.rpm包还原成源代码的形式。rpmbuild则是用来将源代码打包成.rpm格式的工具。

xxx.rpm 指普通的软件包,执行rpm -ivh xxx.rpm以后即是完成了安装;
xxx.src.rpm 指的是包含源代码的软件包,执行rpm -ivh xxx.src.rpm以后,并不是安装了该软件,而是在/root目录下生成一个名为rpmbuild的文件夹(RHEL5中在/usr/src),里面包含了此软件的所有源代码,还需要使用rpmbuild工具将源代码打包成.rpm或者.tar.gz格式的软件包,才能正常安装使用。

CentOS6 中安装rpmbuild:

yum install rpm-build

rpmbuild命令参数介绍
-bp 只作准备 (解压与打补丁)
-bc 准备并编译
-bi 编译并安装
-bl 检验文件是否齐全
-ba 编译后做成*.rpm和src.rpm
-bb 编译后做成*.rpm
-bs 只做成*.src.rpm
-tc -ti -ta -tb -ts 的功能类似,只是所需参数由spec文件变成tar包。

例如:

cd /usr/src/redhat/SPECS
rpmbuild -bp kernel-2.6.spec

更具体的用法说明:

Build options with [ <specfile> | <tarball> | <source package> ]:
建立包的选项有:[ 从<specfile文件>建立 | 从<tarball>包建立 | 从<source package>包建立 ]

从specfile文件建立

  -bp  build through %prep (unpack sources and apply patches) from <specfile>
       -bp 从<specfile>文件的%prep段开始建立(解开源码包并打补丁)
  -bc  build through %build (%prep, then compile) from <specfile>
       -bc 从<specfile>文件的%build
  -bi  build through %install (%prep, %build, then install) from <specfile>
  -bl  verify %files section from <specfile>
       检查<specfile>文件的%files段
  -ba  build source and binary packages from <specfile>
       建立源码和二进制包
  -bb  build binary package only from <specfile>
       只建立二进制包
  -bs  build source package only from <specfile>
       只建立源码包

从tarball包建立

  -tp  build through %prep (unpack sources and apply patches) from <tarball>
  -tc  build through %build (%prep, then compile) from <tarball>
  -ti  build through %install (%prep, %build, then install) from <tarball>
  -ta  build source and binary packages from <tarball>
       建立源码和二进制包
  -tb  build binary package only from <tarball>
       只建立二进制包
  -ts  build source package only from <tarball>
       只建立源码包

从source package包建立

  --rebuild   build binary package from <source package>
              建立二进制包
  --recompile 
              build through %install (%prep, %build, then install) from <source package>

关于rpmbuild的使用,请参考CentOS 6.4安装mock

一些.src.rpm包的下载地址:
ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS

Leave a Reply

Your email address will not be published. Required fields are marked *