Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87506
  • 博文数量: 30
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 410
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 16:34
文章分类

全部博文(30)

文章存档

2010年(2)

2009年(24)

2008年(4)

我的朋友

分类: LINUX

2009-03-13 19:21:29



  • 读取并解析 filename.spec 文件
  • 运行 %prep 部分来将源代码解包到一个临时目录,并应用所有的补丁程序。
  • 运行 %build 部分来编译代码。
  • 运行 %install 部分将代码安装到构建机器的目录中。
  • 读取 %files 部分的文件列表,收集文件并创建二进制和源 RPM 文件。
  • 运行 %clean 部分来除去临时构建目录。

顾名思义也就是前言部分
#
# Example spec file for cdplayer app...
#
Summary: A CD player app that rocks!
Name: cdplayer
Version: 1.0
Release: 1
Copyright: GPL
Group: Applications/Sound
Source: ftp://ftp.gnomovision.com/pub/cdplayer/cdplayer-1.0.tgz
URL:
Distribution: WSS Linux
Vendor: White Socks Software, Inc.
Packager: Santa Claus

%description
It slices! It dices! It's a CD player app that
can't be beat. By using the resonant frequency
of the CD itself, it is able to simulate 20X
oversampling. This leads to sound quality that
cannot be equaled with more mundane software...

Name: 软件包的名称,后面可使用%{name}的方式引用

Summary: 软件包的内容概要

Version: 软件的实际版本号,例如:1.0.1等,后面可使用%{version}引用

Release: 发布序列号,例如:1linuxing等,标明第几次打包,后面可使用%{release}引用

Group: 软件分组,建议使用标准分组

License: 软件授权方式,通常就是GPL

Source: 源代码包,可以带多个用Source1、Source2等源,后面也可以用%{source1}、%{source2}引用

BuildRoot: 这个是安装或编译时使用的“虚拟目录”,考虑到多用户的环境,一般定义为:
%{_tmppath}/%{name}-%{version}-%{release}-root

%{_tmppath}/%{name}-%{version}-%{release}-buildroot-%(%{__id_u} -n}
该参数非常重要,因为在生成rpm的过程中,执行make install时就会把软件安装到上述的路径中,在打包的时候,同样依赖“虚拟目录”为“根目录”进行操作。
后面可使用$RPM_BUILD_ROOT方式引用。

URL: 软件的主页

Vendor: 发行商或打包组织的信息,例如RedFlag Co,Ltd

Disstribution: 发行版标识

Patch: 补丁源码,可使用Patch1、Patch2等标识多个补丁,使用%patch0或%{patch0}引用

Prefix: %{_prefix} 这个主要是为了解决今后安装rpm包时,并不一定把软件安装到rpm中打包的目录的情况。这样,必须在这里定义该标识,并在编写%install脚本的时候引用,才能实现rpm安装时重新指定位置的功能

Prefix: %{_sysconfdir} 这个原因和上面的一样,但由于%{_prefix}指/usr,而对于其他的文件,例如/etc下的配置文件,则需要用%{_sysconfdir}标识

Build Arch: 指编译的目标处理器架构,noarch标识不指定,但通常都是以/usr/lib/rpm/marcros中的内容为默认值

Requires: 该rpm包所依赖的软件包名称,可以用>=或<=表示大于或小于某一特定版本,例如:
libpng-devel >= 1.0.20 zlib
※“>=”号两边需用空格隔开,而不同软件名称也用空格分开
还有例如PreReq、Requires(pre)、Requires(post)、Requires(preun)、Requires(postun)、BuildRequires等都是针对不同阶段的依赖指定


Provides: 指明本软件一些特定的功能,以便其他rpm识别

Packager: 打包者的信息

%description 软件的详细说明


这里要引入一个叫Macros的东西

Macros — A method of executing multiple commands easily

官方的说法其实就是完成一些必要的检测,并完成相应一些命令的一个方式,说到底一个预编译函数

%setup -c  %{name}-%{version}
大致完成了以下的功能,删除旧的包,创建新目录,解压,改权限
cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
mkdir -p cdplayer-1.0
cd cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .


更多功能请看。(其实达人可以无视)


这部分没有Macro,官方解释是
The reason for this is that the process of building software is either going to be very easy, or highly complicated. In either case, macros won't help much.
大致就是Macro很鸡肋,前后矛盾了--!

一般像下面这样就可以了
%build
make


%install
make install


必须包括你安装好以后会在新系统创建的文件
%files
%defattr(-,root,root)
%{userpath}


附上我的第一份作品,涉及到一些更细节的东西我以后会补充说明
%define debug_package %{nil}

Summary: zabbix_agentd for ChinaNetCloud
Name: zabbix_agentd
Version: 2.6.1
Release: 1
License: GPL
Group: System
Source: zabbix_bin.tar.gz
#BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires(pre): /usr/sbin/useradd
Requires(post): /sbin/chkconfig, /bin/hostname
Requires(preun): /sbin/chkconfig, /sbin/service
#Requires(preun): /sbin/service
Url:
Packager: Daniel
%define userpath /usr/local/sbin/


%description
Zabbix_Agentd for the ChinaNetCloud Servers.


%pre
/usr/sbin/useradd -s /sbin/nologin -c "Zabbix user account" zabbix > /dev/null 2>&1 || :

%prep
%setup -c %{name}-%{version}
%install
install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/init.d
install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/zabbix/
install -d -m 755 $RPM_BUILD_ROOT%{userpath}
install -m 755 zabbix/centos_init/zabbix_agentd $RPM_BUILD_ROOT%{_sysconfdir}/init.d/
install -m 644 zabbix/conf/zabbix_agentd.conf $RPM_BUILD_ROOT%{_sysconfdir}/zabbix/
if [ %{_target_cpu}=x86_64 ]
then
install -m 755 zabbix/2.6.9-64B/zabbix_agentd $RPM_BUILD_ROOT%{userpath}
else
install -m 755 zabbix/2.6.9-32B/zabbix_agentd $RPM_BUILD_ROOT%{userpath}
fi

%post
fullHostname=`/bin/hostname -f`
sed -i 0,/Hostname.*/s//"Hostname=$fullHostname"/ %{_sysconfdir}/zabbix/zabbix_agentd.conf

# Make sure the zabbix server is added into chkconfig
/sbin/chkconfig --add zabbix_agentd
/sbin/chkconfig zabbix_agentd on

%define debug_package %{nil}

Summary: zabbix_agentd for ChinaNetCloud
Name: zabbix_agentd
Version: 2.6.1
Release: 1
License: GPL
Group: System
Source: zabbix_bin.tar.gz
#BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires(pre): /usr/sbin/useradd
Requires(post): /sbin/chkconfig, /bin/hostname
Requires(preun): /sbin/chkconfig, /sbin/service
#Requires(preun): /sbin/service
Url:
Packager: Daniel
%define userpath /usr/local/sbin/


%description
Zabbix_Agentd for the ChinaNetCloud Servers.


%pre
/usr/sbin/useradd -s /sbin/nologin -c "Zabbix user account" zabbix > /dev/null 2>&1 || :

%prep
%setup -c %{name}-%{version}
%install
install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/init.d
install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/zabbix/
install -d -m 755 $RPM_BUILD_ROOT%{userpath}
install -m 755 zabbix/centos_init/zabbix_agentd $RPM_BUILD_ROOT%{_sysconfdir}/init.d/
install -m 644 zabbix/conf/zabbix_agentd.conf $RPM_BUILD_ROOT%{_sysconfdir}/zabbix/
if [ %{_target_cpu}=x86_64 ]
then
install -m 755 zabbix/2.6.9-64B/zabbix_agentd $RPM_BUILD_ROOT%{userpath}
else
install -m 755 zabbix/2.6.9-32B/zabbix_agentd $RPM_BUILD_ROOT%{userpath}
fi

%post
fullHostname=`/bin/hostname -f`
sed -i 0,/Hostname.*/s//"Hostname=$fullHostname"/ %{_sysconfdir}/zabbix/zabbix_agentd.conf

# Make sure the zabbix server is added into chkconfig
/sbin/chkconfig --add zabbix_agentd
/sbin/chkconfig zabbix_agentd on
阅读(2299) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~