文章目录
- 一、命令介绍
- 二、命令选项
- (一)从 specfile建立
- (二)从 tarball包建立
- (三)从 source package包建立
- (四)其它选项
- (五)所有 rpm 都可使用的选项
- (六)附加选项
- (七)帮助选项
 
- (一)从 
- 三、命令示例
- (一)根据配置文件对源码包进一步解压,得到最终的源码文件
 
一、命令介绍
命令 rpmbuild 用于创建 RPM 软件包和 SRPM 软件包,这两类软件包分别是 rpm 格式的二进制软件包和源码软件包
二、命令选项
Build options with [ <specfile> | <tarball> | <source package> ]
中文译为:通过配置文件或 tar.gz 格式的源码包或者 rpm 格式的源码包来构建
(一)从 specfile 建立
 
| 选项 | 说明 | 
|---|---|
| -bp | build through %prep (unpack sources and apply patches) from <specfile>.译文:从 specfile文件的%prep开始建立(解开源码包并打补丁),只作准备,解压与打补丁 | 
| -bc | build through %build (%prep, then compile) from <specfile>.译文:从文件的 %build开始建立(解开源码包、打补丁、编译) | 
| -bi | build through %install (%prep, %build, then install) from <specfile>译文:从文件的 %install开始建立(解开源码包、打补丁、编译、安装) | 
| -bl | verify %files section from <specfile>.译文:检查文件的 %files段,检验文件是否齐全 | 
| -ba | build source and binary packages from <specfile>.译文:创建源码包(SRPM)和二进制包(RPM) | 
| -bb | build binary package only from <specfile>.译文:只构建二进制包 | 
| -bs | build source package only from <specfile>.译文:只建立源码包(SRPM) | 
(二)从 tarball 包建立
 
这个 tarball 应该是以 .tar 为后缀名的包。
| 选项 | 说明 | 
|---|---|
| -tp | build through %prep (unpack sources and apply patches) from <tarball>.译文:从 tar 包的 %prep开始构建(解开源码包并打补丁) | 
| -tc | build through %build (%prep, then compile) from <tarball>.译文:从 tar 包的 %build开始建立(解开源码包、打补丁、编译) | 
| -ti | build through %install (%prep, %build, then install) from <tarball>.译文:从 tar 包的 %install开始建立(解开源码包、打补丁、编译、安装) | 
| -ta | build source and binary packages from <tarball>.译文:从 tar 包建立源码包和二进制包 | 
| -tb | build binary package only from <tarball>.译文:只建立二进制包 | 
| -ts | build source package only from <tarball>.译文:只建立源码包 | 
(三)从 source package 包建立
 
这个源码包,应该是以 .tar.gz 为后缀名的包。
| 选项 | 说明 | 
|---|---|
| --rebuild | build binary package from <source package>.译文:基于源码包建立二进制包(*.rpm) | 
| --recompile | build through %install (%prep, %build, then install) from <source package>.译文:基于源码包的 %install开始建立(解开源码包、打补丁、编译、安装) | 
(四)其它选项
| 选项 | 说明 | 
|---|---|
| --buildroot<DIRECTORY> | override build root. 重写生成根目录 | 
| --clean | remove build tree when done. 完成打包后清除 BUILD下的文件目录 | 
| --nobuild | do not execute any stages of the build. 不进行 BUILD 的阶段 | 
| --nodeps | do not verify build dependencies. 不检查建立包时的关联文件 | 
| --nodirtokens | generate package header(s) compatible with (legacy) rpm[23] packaging. 生成与(传统)rpm[23]打包兼容的包头 | 
| --rmsource | remove sources when done. 完成打包后清除 sources | 
| --rmspec | remove specfile when done. 完成打包后清除 specfile | 
| --short-circuit | skip straight to specified stage (only for c,i). 直接跳到指定的阶段(仅适用于c、i) | 
| --target<CPU-VENDOR-OS> | override target platform. 覆盖目标平台,确定包的最终使用平台 | 
(五)所有 rpm 都可使用的选项
Common options for all rpm modes.
| 选项 | 说明 | 
|---|---|
| -D 或 --define<宏表达式> | define MACRO with value EXPR. 用值表达式定义宏 | 
| -E 或 --eval<表达式> | print macro expansion of EXPR. 打印表达式的宏扩展 | 
| --macros<filename> | read instead of default file(s). 读取而不是默认文件 | 
| --nodigest | don’t verify package digest(s). 不验证包摘要,不检查包的说明信息 | 
| --nosignature | don’t verify package signature(s). 不检查包的签名信息 | 
| --rcfile<filename> | read instead of default file(s). 读 文件代替默认文件 | 
| -r 或 --root<ROOT> | use ROOT as top level directory (default: “/”). 使用根目录作为顶级目录(默认值:“/”) | 
| --querytags | display known query tags. 显示已知查询标记 | 
| --showrc | display final rpmrc and macro configuration. 显示最终的rpmrc和宏配置 | 
| --quiet | provide less detailed output. 提供不太详细的输出 | 
| -v 或 --verbose | provide more detailed output. 提供大量的详细的信息 | 
| --version | print the version of rpm being used. 显示rpm包的版本 | 
(六)附加选项
Options implemented via popt alias/exec. 通过popt alias/exec实现的选项
| 选项 | 说明 | 
|---|---|
| --dbpath<目录> | use database in DIRECTORY. 使用目录中的数据库 | 
| --with<选项> | enable configure for build. 建立时允许配置的选项 | 
| --without<选项> | disable configure for build. 建立时不允许配置的选项 | 
(七)帮助选项
Help options.
| 选项 | 说明 | 
|---|---|
| -? 或 --help | Show this help message. 显示帮助信息 | 
| --usage | Display brief usage message. 显示使用方法的信息 | 
三、命令示例
(一)根据配置文件对源码包进一步解压,得到最终的源码文件
这个最终的源码文件应该是存放在目录 BUILD 下。
先切换到目录 SPECS 下:
[root@localhost ~]# cd /root/rpmbuild/SPECS
选项 -bp 会根据配置文件对 SOURCES 目录下源码包进一步解压:
rpmbuild -bp httpd.specs             
欲了解命令 rpmbuild 在安装 SRPM 软件包的实际使用,猛戳《Linux 如何安装 SRPM 包》