rpmbuild 使用笔记

1. rhel6.0 自定义 RPM 包
过往习惯使用 /usr/src/redhat 作为 RPM 创建默认目录, RHEL6 默认使用 $HOME/rpmbuild 目录创建 RPM

2. 创建目录方法
当尝试编译任意一个 src.rpm  $HOME/rpmbuild 自动创建, 目录结构如下

BUILD  目录用于 RPM 编译
SOURCES  用于存放源码, 补丁, RPM 会自动从该目录自动寻找
SPECS  存放 SPEC 文件
RPMS  二进制软件编译后存放位置
SRPMS  源码 RPM 存放位置
BUILDROOT ....

3. 编译测试
获得 lsyncd-2.0.5.tar.gz 并尝试编译, 获得编译需求参数

利用 make install 获得下面信息

创建文件
/usr/local/bin/lsyncd
创建目录
/usr/local/share/doc/lsyncd/
创建文件
examples/lbash.lua /usr/local/share/doc/lsyncd/lbash.lua
examples/lecho.lua /usr/local/share/doc/lsyncd/lecho.lua
examples/lgforce.lua /usr/local/share/doc/lsyncd/lgforce.lua
examples/limagemagic.lua /usr/local/share/doc/lsyncd/limagemagic.lua
examples/lpostcmd.lua /usr/local/share/doc/lsyncd/lpostcmd.lua
examples/lrsync.lua /usr/local/share/doc/lsyncd/lrsync.lua
examples/lrsyncssh.lua /usr/local/share/doc/lsyncd/lrsyncssh.lua
创建目录
/usr/local/share/man/man1
创建文件
doc/lsyncd.1 /usr/local/share/man/man1/lsyncd.1


mkdir -p $RPM_BUILD_ROOT/usr/local/share/doc/lsyncd
mkdir -p $RPM_BUILD_ROOT%/usr/local/bin
install -p -m 755 lsyncd $RPM_BUILD_ROOT/usr/local/share/doc/lsyncd/
install -p -m 644 doc/lsyncd.1 /usr/local/share/man/man1/lsyncd.1
install -p -m 644 examples/lbash.lua /usr/local/share/doc/lsyncd/lbash.lua
install -p -m 644 examples/lecho.lua /usr/local/share/doc/lsyncd/lecho.lua
install -p -m 644 examples/lgforce.lua /usr/local/share/doc/lsyncd/lgforce.lua
install -p -m 644 examples/limagemagic.lua /usr/local/share/doc/lsyncd/limagemagic.lua
install -p -m 644 examples/lpostcmd.lua /usr/local/share/doc/lsyncd/lpostcmd.lua
install -p -m 644 examples/lrsync.lua /usr/local/share/doc/lsyncd/lrsync.lua
install -p -m 644 examples/lrsyncssh.lua /usr/local/share/doc/lsyncd/lrsyncssh.lua
#make install DESTDIR=$RPM_BUILD_ROOT

 

4. 开始编写 spec 文件
a. 存放软件包 /root/rpmbuild/SOURCES/lsyncd-2.0.5.tar.gz
b. 创建 /root/rpmbuild/SPECS/lsyncd-2.0.5.spec (自动生成模板) 参考下面信息


Name:   lsyncd
Version:        2.0.5
Release:        1%{?dist}
Summary:        A program use to combined rsync service and use to sync file automatic.

Group:          Applications/Internet
License:        GPLv2
URL:            http://code.google.com/p/lsyncd/wiki/Lsyncd20Manual
Source0:        http://lsyncd.googlecode.com/files/lsyncd-2.0.5.tar.gz
BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

BuildRequires:  lua-devel
Requires:       lua

%description
lsyncd 2.x allows you to specify different actions for different kind of events. Particularly moves can now be implemented to be moved locally at the target instead of hitherto deletion of the origin and retransfer of the destination.

%prep
%setup -q


%build
%configure
make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
install -p -m 755 lsyncd $RPM_BUILD_ROOT/%{_bindir}/lsyncd
install -p -m 644 doc/lsyncd.1 $RPM_BUILD_ROOT/%{_mandir}/lsyncd.1
install -p -m 644 examples/lbash.lua $RPM_BUILD_ROOT/%{_docdir}/lbash.lua
install -p -m 644 examples/lecho.lua $RPM_BUILD_ROOT/%{_docdir}/lecho.lua
install -p -m 644 examples/lgforce.lua $RPM_BUILD_ROOT/%{_docdir}/lgforce.lua
install -p -m 644 examples/limagemagic.lua $RPM_BUILD_ROOT/%{_docdir}/limagemagic.lua
install -p -m 644 examples/lpostcmd.lua $RPM_BUILD_ROOT/%{_docdir}/lpostcmd.lua
install -p -m 644 examples/lrsync.lua $RPM_BUILD_ROOT/%{_docdir}/lrsync.lua
install -p -m 644 examples/lrsyncssh.lua $RPM_BUILD_ROOT/%{_docdir}/lrsyncssh.lua


%clean
rm -rf $RPM_BUILD_ROOT
make clean


%files
   /usr/bin/lsyncd
   /usr/share/doc/lbash.lua
   /usr/share/doc/lecho.lua
   /usr/share/doc/lgforce.lua
   /usr/share/doc/limagemagic.lua
   /usr/share/doc/lpostcmd.lua
   /usr/share/doc/lrsync.lua
   /usr/share/doc/lrsyncssh.lua
   /usr/share/doc/lsyncd/lbash.lua
   /usr/share/doc/lsyncd/lecho.lua
   /usr/share/doc/lsyncd/lgforce.lua
   /usr/share/doc/lsyncd/limagemagic.lua
   /usr/share/doc/lsyncd/lpostcmd.lua
   /usr/share/doc/lsyncd/lrsync.lua
   /usr/share/doc/lsyncd/lrsyncssh.lua
   /usr/share/man/lsyncd.1
   /usr/share/man/man1/lsyncd.1.gz
%defattr(-,root,root,-)
%doc

 

%changelog
* Tue Mar  6 2011 terrytsang  <signmem@hotmail.com>
-- example

 

5. spec 特别之处进行描述

a. %configure   这里可以添加编译参数
b. $RPM_BUILD_ROOT/%{_bindir}  $RPM_BUILD_ROOT/%{_docdir} 宏变量, 目录位置参考 ./configure --help
c. 初次使用, 会出现 Installed (but unpackaged) file(s) found: 错误信息
 解决方法: 把出现的文件直接写入到 %files 之后就可以成功
d. 习惯上 %clean 最后需要添加   make clean
e. %changelog 后面, 必须添加一行 -- 开头信息


rpmbuild 编译提示
-b 能够与下面参数进行配合使用
p 代表只执行 spec 文件中 prep 部分
c 只执行 prep 与编译, 常用于你无法确保源码是否能够完整编译,
i 执行 prep, compile, install
b prep, compile, install 只创建一个二进制包
a 创建源码与二进制包

上一篇:Redhat 5 中裸设备(raw) 的配置  http://blog.csdn.net/tianlesoftware/article/details/5796962


下一篇:机器学习利器——决策树和随机森林