RPM包制作学习笔记 By_itnihao
- rpm capability能力
- 1.Set up the directory structure
- 2.Place the sources in the right directory
- 3.Create a spec file that tells the rpmbuild command what to do
- 4.Build the source and binary RPMs
- BUILD The rpmbuild command builds software in this directory
- RPMS The rpmbuild command stores binary RPMs it reates in this directory
- SOURCES You should put the sources for the application in this directory
- SPECS You should place the spec file for each RPM you plan to make in this directory
- SRPMS The rpmbuild command places source RPMs in this directory
- rpmbuild --showrc
- useradd itnihao
- su - itnihao
- mkdir -pv rpmbuild/{BUILD,RPMS,SOURCES.SPEC,SRPMS}
- echo "% _topdir /home/itnihao/rpmbuild" >~/.rpmmacros
- rpmbuild --showrc|grep _topdir
- -14: _builddir %{_topdir}/BUILD
- -14: _buildrootdir %{_topdir}/BUILDROOT
- -14: _rpmdir %{_topdir}/RPMS
- -14: _sourcedir %{_topdir}/SOURCES
- -14: _specdir %{_topdir}/SPECS
- -14: _srcrpmdir %{_topdir}/SRPMS
- -14: _topdir /home/itnihao/rpmbuild
- #rpmbuild --showrc|grep macros
- # rpm -qpi rrdtool-1.3.8-6.el6.x86_64.rpm
- Name : rrdtool 软件包名字 Relocations: (not relocatable)
- Version : 1.3.8 版本号 Vendor: CentOS
- Release : 6.el6 释出号 Build Date: Sat 21 Aug 2010 05:57:29 PM CST
- Install Date: (not installed) Build Host: c6b5.bsys.dev.centos.org
- Group : Applications/Databases Source RPM: rrdtool-1.3.8-6.el6.src.rpm
- Size : 711138 License: GPLv2+ with exceptions
- Signature : RSA/8, Sun 03 Jul 2011 01:00:33 PM CST, Key ID 0946fca2c105b9de
- Packager : CentOS BuildSystem <http://bugs.centos.org>
- URL : http://oss.oetiker.ch/rrdtool/
- Summary : Round Robin Database Tool to store and display time-series data 软件包简介
- Description :
- RRD is the Acronym for Round Robin Database. RRD is a system to store and display time-series data (i.e. network bandwidth,
- machine-room temperature,server load average). It stores the data in a very compact way that will not expand over time, and
- it presents useful graphs by processing the data to enforce a certain data density. It can be used either via simple wrapper
- scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it.
- The prep setion
- %prep
- 该段内容为安装前脚本程序。它在软件包安装之前执行,通常是检测操作环境,建立有关目录,清理多余文件
- 等等,为软件包的顺利安装做准备。本段很少使用
- 其段名格式为: %pre [子包选项]
- %setup
- 此为预处理阶段,其内容为预处理脚本程序,该程序完成以下任务:
- 建立软件编译用目录
- 将源程序解压缩
- 通过打补丁,升级源程序
- 执行其他一些操作,使源程序随时可进行编译
- 在此脚本程序中,可以使用如下两个宏命令:
- %setup
- 这个宏利用系统中的gzip与tar等命令,来解压源程序包。RPM会自动探测源程序是否压缩,如果压缩,它会用gzip将其解压缩,否则直接使用
- tar命令展开包中文件,其格式为
- %setup [-n name] [-c] [-D] [-T] [-b N] [-a N]
- 注意:[]所括为可选项。
- (1)当没有任何选项时
- 这个宏用来解压默认的源程序包(由头文件Source或Source0域指定).注意:源程序包中的文件应用“软件名-版本号”作为其上层目录,这
- 样%setup宏就可以正常工作。如果不以“软件名-版本号”作为其上层目录。则%setup宏工作时有一个指令“cd 软件包-版本号”(转目录)
- 会因为系统中没有此目录而出错退出(除非在此宏上面加上建立此目录的命令)
- (2)-n name
- 引用目录
- (3)-c:
- 此选项的作用是创建上层目录(“软件名-版本号”目录)并转到这个目录。
- (4)-D
- 解压源程序之前不要删除软件的上层目录(软件名-版本号)
- (5)-T
- 本选项的作用是不解压默认的源程序包(由文件头的Source或者Source0域所定义)
- (6)-b -N
- 本选项指示RPM在转到上层目录前解压第N个源程序包(由文件头SourceN域定义),这适用于含上层目录的源程序包
- (7) -a N
- 本选项指示RPM在转到上层目录后再解压第N个源程序包
- %patch
- 此宏利用系统中的patch命令,来给指定的源程序包打补丁,从而将程序升级。其使用格式为:
- %patch [-P N] [-p N] [-b name] [-E]
- 注: []所括为可选项
- (1) 当没有任何选项时:
- 没有任何选项时,该宏使用的是默认的补丁文件(第0个补丁文件),即由文件头Patch或Patch0域所定义的文件
- patch命令用了两个选项:(有关patch命令用法,详见其用户手册)
- * -p :这个选项用于确定patch所要操作的文件。它针对补丁文件头部的文件名,删除名字中指定数目个
- 斜杠(/)前面的所有字符,从而得到要操作的文件名。
- * -s :这个选项指示patch在打补丁过程中不输出任何信息,即使有错误发生。
- (2) -P N :
- 使用此选项以指示RPM使用第N个补丁文件(由文件头PatchN域定义)。
- (3) -p N :
- 此选项与其参数是由%patch宏直接传给patch命令的。请参见上面patch命令所用的-p选项的介绍。
- (4) -b name :
- 当有多个patch命令操作同一个文件时,patch会将原文件换名保存(其后缀变作.orig)
- (5) -E :
- 此选项直接传给patch命令,其作用是:如果一个文件打完补丁后内容为空(字节数为0),则删除这个文件。
- The build section
- 此为编译段,其内容为编译脚本程序。该程序完成源程序的编译和连接。一个最简单的例子就是程序中仅有一个make命令。这适用于大部分情况
- ,因为多数软件均有自己的makefile,这样通过make命令就可实现编译与连接。如果没有makefile的话,需要软件包制作者自己在编译段书写上一
- 系列的编译连接命令。
- %build
- ./configure \
- --etcdir="%{_sysconfdir}"\
- --mandir="%{_mandir}"\
- --i18n="0"\
- --scrip="0"
- %{_make} %{?_smp_mflags}
- The install section
- 此为安装段,其内容是安装脚本程序。该程序将已编译连接好的执行程序或其它文件存放到指定目录下,这些程序或文件供RPM打包时使用。一个
- 最简单的例子就是程序中仅用一个make install命令,从而完成安装。这也需要相应的软件有makefile维护文件。没有的话,软件包制作者也得
- 自己写指令。
- %install
- %{_rm} -rf %{buildroot}
- %{_make} install DESTDIR="%{buildroot}"
- %find_lang %{name}
- 脚本段
- %pre 安装前
- 该段内容为安装前脚本程序。它在软件包安装之前执行,通常是检测操作环境,建立有关目录,清理多余文件等等,为软件包的顺利安装做准备。
- 本段很少使用其段名格式为: %pre [子包选项]
- %post 安装后
- 该段内容为安装后脚本程序。它在软件包安装完成之后执行,常用来建立符号连接,修改系统配置文件,运行ldconfig程序等,以利软件的正常运
- 行。
- 其段名格式为: %post [子包选项]
- %preun 卸载前
- 该段内容为卸载后脚本程序。它在软件包卸载后执行,完成卸载的缮后工作,如将系统配置文件inetd.conf 改回原来的样子,重新运行一下
- config命令,将已卸载的共享库从缓冲文件ld.so.cache中删除等等。
- 其段名格式为: %postun [子包选项]
- %postun 卸载后
- %verifyscript :
- 该段内容为校验脚本程序。RPM校验软件包时,除了执行标准的校验外,如果软件包制作者设定有此校验脚本程序,还将执行之。
- 其段名格式为: %verifyscript [子包选项]
- The clean
- 此为清理段,其内容是清理脚本程序。此程序在RPM制作好软件包后才执行,它通常是删除那些编译连接时产生的临时文件或目录,完成缮后工作
- 。
- %clean
- %{_rm} -rf %{buildroot}
- BUILDROOT/
故障记录
Checking for unpackaged file(s): /usr/lib/rpm/check-files
在/usr/lib/rpm/macros文件中有一个定义:
%_unpackaged_files_terminate_build 1
把1改为0只警告 itnihao 2012年4月25日于成都