RPM SPEC文件编写通用规范

来源:百度文库 编辑:神马文学网 时间:2024/04/29 20:34:38
一、简介
本教程参考了 RedHatLinux .spec file Specification and RPM HOWTO and Maximum RPM.
作者:哈蜜瓜 转载请注明引自http://www.linuxsir.com
二、软件包的规范
1. %定义
下面的值被定义在头中作为特征子,该特征子在一个时期以新形式区分规格文件, 对于该规格文件所有的包都适用这个规则。 该特征子应当在前导部分发布。
引用:
<<例子>>
%define distrib RedHatLinux
2. 描述总体和使用 UTF-8 编码 %描述
在TurobLinux 使用 UTF-8 编码的环境下 Summary 和 %description、%changelog 的每一个区域应当使用 UTF-8 编码进行描述和编辑。
3. 压缩 man pages 和信息
通过 gzip 压缩 man page 和 info 文件.
引用:
<<例子>>
gzip -9f $RPM_BUILD_ROOT%{prefix}/man/*/*
gzip -9f $RPM_BUILD_ROOT%{prefix}/share/info/*info*
三、SPEC 中每个章节的规范
1. 前导部分
- 参照 名称,Version,Release,Source,Patch,BuildRoot,Requires 生成 %define 定义
- 在 Source/Patch 部分描述 URL 地址。
- BuildRoot 的格式是/var/tmp/%{name}-%{ver}-root.
- Serial 的格式是 "YYYYMMDDXX" (YYYY: 年 MM: 月 DD: 日 XX: 系列号).
- URL 地址是你所在地区的最近站点(如果可能的话)。
- 命名补钉文件的规则如下:
命名代表{功能} 或者 {修改的文件名}.
引用:
{Package Name}-{Package Version}-{DescribeWhatThePatchDoes}.patch
按照下面的规则使用补丁的 ID 号
引用:
补丁 ID 规则
0-9 Makefile、configure 等的补丁
10-39 指定功能或包含他的文件的补丁
40-59 配置文件的补丁
60-79 字体或字符补丁
80-99 通过 xgettexize 得到的目录情况的补丁
100- 其他补丁
<<例子>>
下面的文件是改变grub-0.93.tar.gz configure的补丁:
引用:
grub-0.93-configfile.patch
补钉 ID 号应当以 0 开始, 这是因为该补丁是“configure的补丁”
引用:
Patch0: grub-0.93-configfile.patch
2. %package 部分
3. %changelog 部分
- 描述包的配置理由(添加、删除、修改).
- 描述补钉的功能.
4. %prep 部分
- 描述 "rm -rf $RPM_BUILD_ROOT" .
- 描述或编辑本部分用到的命令到 PreReq:.
5. %prep 部分
6. %setup 部分
- 通过 "-b .XXX" 描述补丁备份.
7. %build 部分
- 声明 CFLAG="$RPM_OPT_FLAGS"
- %configure 没有使用.
- 通过 %ifnarch 和 %endif‘ 语法描述构造的意图.
这个构造把目标当做 makes alpha, i386.
8. %install 部分
- 描述 "rm -rf $RPM_BUILD_ROOT"
- 生成二进制文件.
9. %post 部分
- 用 ldconfig 命令更新库参照表.
- 描述或编辑本部分用到的命令到 PreReq:.
10. %postun 部分
- 用 ldconfig 命令更新库参照表.
- 描述或编辑本部分用到的命令到 PreReq:.
11. %files 部分
- 使用 defattr 描述权限。
四、规格文件SPEC范本
引用:
Name: grub
Version: 0.93
Release: 5
Summary: GRUB - the Grand Unified Boot Loader.
Group: System Environment/Base
License: GPL
URL: http://www.gnu.org/software/%{name}/
Source0: ftp://alpha.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz
# let‘s have some sort of organization for the patches
# patches 0-19 are for config file related changes (menu.lst->grub.conf)
Patch0: grub-0.93-configfile.patch
Patch1: grub-0.90-symlinkmenulst.patch
# patches 20-39 are for grub-install bits
Patch20: grub-0.90-install.in.patch
Patch21: grub-0.90-installcopyonly.patch
Patch22: grub-0.90-addsyncs.patch
# patches 40-59 are for miscellaneous build related patches
# link against curses statically
Patch40: grub-0.90-staticcurses.patch
# compatibility for automake 1.6
Patch41: grub-0.92-automake16.patch
# patches submitted upstream and pending approval
# change the message so that how to accept changes is clearer (#53846)
Patch81: grub-0.93-endedit.patch
# support large disks (#80980, #63848) (applied upstream)
Patch82: grub-0.93-largedisk.patch
# patches 100-199 are for features proposed but not accepted upstream
# add support for appending kernel arguments
Patch100: grub-0.90-append.patch
# add support for lilo -R-esque select a new os to boot into
Patch101: grub-0.91-bootonce.patch
# patches 200-299 are for graphics mode related patches
Patch200: grub-0.93-graphics.patch
Patch201: grub-0.91-splashimagehelp.patch
Patch202: grub-0.93-graphics-bootterm.patch
# patches 300-399 are for things already upstream
Patch300: grub-0.93-serial-terminfo.patch
# patches 500+ are for miscellaneous little things
# support for non-std devs (eg cciss, etc)
Patch500: grub-0.93-special-device-names.patch
# support for building on x86_64
Patch501: grub-0.92-hammer.patch
ExclusiveArch: i386 x86_64
BuildRequires: binutils >= 2.9.1.0.23
PreReq: /sbin/install-info
Requires: mktemp
BuildRoot: %{_tmppath}/%{name}-%{version}-root
%description
GRUB (Grand Unified Boot Loader) is an experimental boot loader
capable of booting into most free operating systems - Linux, FreeBSD,
NetBSD, GNU Mach, and others as well as most commercial operating
systems.
%prep
%setup -q
%patch0 -p1 -b .config
%patch1 -p1 -b .menulst
%patch20 -p1 -b .install
%patch21 -p1 -b .copyonly
%patch22 -p1 -b .addsync
%patch40 -p1 -b .static
%patch41 -p1 -b .automake16
%patch81 -p0 -b .endedit
%patch82 -p0 -b .largedisk
%patch100 -p1 -b .append
%patch101 -p1 -b .bootonce
%patch200 -p1 -b .graphics
%patch201 -p1 -b .splashhelp
%patch202 -p1 -b .bootterm
%patch300 -p0 -b .terminfo
%patch500 -p1 -b .raid
%patch501 -p1 -b .hammer
%build
autoreconf --install --force
%ifarch x86_64
LDFLAGS="-Wl,-static" ; export LDFLAGS
%endif
CFLAGS="-Os -g" ; export CFLAGS
%configure --sbindir=/sbin --disable-auto-linux-mem-opt
make
%install
rm -fr $RPM_BUILD_ROOT
%makeinstall sbindir=${RPM_BUILD_ROOT}/sbin
mkdir -p ${RPM_BUILD_ROOT}/boot/grub
rm -f ${RPM_BUILD_ROOT}/%{_infodir}/dir
%clean
rm -fr $RPM_BUILD_ROOT
%post
if [ "$1" = 1 ]; then
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/grub.info.gz
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/multiboot.info.gz
fi
%preun
if [ "$1" = 0 ] ;then
/sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/grub.info.gz
/sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/multiboot.info.gz
fi
%files
%defattr(-,root,root)
%doc AUTHORS ChangeLog NEWS README COPYING TODO docs/menu.lst
/boot/grub
/sbin/grub
/sbin/grub-install
/sbin/grub-terminfo
/sbin/grub-md5-crypt
%{_bindir}/mbchk
%{_infodir}/grub*
%{_infodir}/multiboot*
%{_mandir}/man*/*
%{_datadir}/grub
五、参考资料
http://www.chinalinuxpub.com/doc/ho...TO-6.html#ss6.1
http://www.redhat.com/docs/books/ma...pm-html.tar.bz2
http://www.redhat.com/docs/books/max...m-html.tar.bz2