rpm打包spec文件

spec结构说明

spec文件包含8部分

The Preamble

包说明信息,包含功能,版本等

The Prep Section

解压并进入SOURCE目录

The Build Section

编译,例如congfigure,make

The Install Section

安装目录,make install或者cp,mv...

Install and Uninstall Scripts

安装或者卸载前后执行的动作

The Verity Script

安装时的环境检查

The Clean Section

编译时后的清除工作

The File List

需要打进包里的文件列表


RPM宏命令

%{_topdir}            %{getenv:HOME}/rpmbuild
%{_builddir}          %{_topdir}/BUILD
%{_rpmdir}            %{_topdir}/RPMS
%{_sourcedir}         %{_topdir}/SOURCES
%{_specdir}           %{_topdir}/SPECS
%{_srcrpmdir}         %{_topdir}/SRPMS
%{_buildrootdir}      %{_topdir}/BUILDROOT

宏指令一般地定义在 spec 文件中.语法象 %define macro1 value, 要使用这个宏,使用%{macro1}.宏指定也可以事先在配置文件中调整.
就是下面的文件.

    默认设置为 /usr/lib/rpm/macros or /etc/rpm/macros
    用户设置 ~/.rpmmacros


RPM打包目录

tree /usr/src/redhat/
/usr/src/redhat/
|-- BUILD
|-- RPMS
|   |-- i386
|   |-- noarch
|   `-- x86_64
|-- SOURCES
|-- SPECS
`-- SRPMS

可以自定义目录到其它地方

cd ~/rpmbuild/SPECS && rpmbuild --define "_topdir ~/rpmbuild" -v -ba abc.spec

建立自己的打包工作目录与环境
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mkdir -p ~/rpmbuild/RPMS/{noarch,i386,x86_64}
echo "%_topdir %(echo \$HOME)/rpmbuild" > ~/.rpmmacros

SPEC简例

The Preamble例子:

#
# 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: http://www.gnomovision.com/cdplayer/cdplayer.html
Distribution: WSS Linux
Vendor: White Socks Software, Inc.
Packager: Santa Claus <sclaus@northpole.com>

%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...
          

The %prep Section

%prep
rm -rf $RPM_BUILD_DIR/cdplayer-1.0
zcat $RPM_SOURCE_DIR/cdplayer-1.0.tgz | tar -xvf -
可以简化:

%prep
%setup

The %build Section

%build
make 


The %install Section

%install
make install
          

The %files Section

%files
%doc README
/usr/local/bin/cdp
/usr/local/bin/cdplay
/usr/local/man/man1/cdp.1
%doc表明普通文件,上面的表明README将放至/usr/doc中,也可定义放到放到其它目录

开始打包

cd /usr/src/redhat/SPECS

rpm -ba cdplayer-1.0.spec

不出错,会在SRPMS下结果


rpm -ba --test cdplayer-1.0.spec会产生build shell文件

#!/bin/sh -e
# Script generated by rpm

RPM_SOURCE_DIR="/usr/src/redhat/SOURCES"
RPM_BUILD_DIR="/usr/src/redhat/BUILD"
RPM_DOC_DIR="/usr/doc"
RPM_OPT_FLAGS="-O2 -m486 -fno-strength-reduce"
RPM_ARCH="i386"
RPM_OS="Linux"
RPM_ROOT_DIR="/tmp/cdplayer"
RPM_BUILD_ROOT="/tmp/cdplayer"
RPM_PACKAGE_NAME="cdplayer"
RPM_PACKAGE_VERSION="1.0"
RPM_PACKAGE_RELEASE="1"
set -x

umask 022

echo Executing: %prep
cd /usr/src/redhat/BUILD

cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz | tar -xvvf -
if [ $? -ne 0 ]; then
  exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
          

常见标签

%build 开始构建包. 常见写法:

configure;make

或者直接到源码目录下进行build(非tar.gz源码包方式):

cd $OLDPWD/..; configure;make

%install 开始把软件安装到虚拟的根目录中。常见写法:

make install DESTDIR=${RPM_BUILD_ROOT}

或者直接copy:

mkdir -p .%{_prefix}/bin/

cp $OLDPWD/../bin/* .%{_prefix}/bin/

%clean 清理临时文件

%pre rpm安装前执行的脚本

%post rpm安装后执行的脚本

%preun rpm卸载前执行的脚本

%postun rpm卸载后执行的脚本

%files 定义那些文件或目录会放入rpm中

%defattr (-,root,root) 指定包装文件的属性,分别是(mode,owner,group),-表示默认值,对文本文件是0644,可执行文件是0755

%exclude 列出不想打包到rpm中的文件 ※小心,如果%exclude指定的文件不存在,也会出错的。

%changelog 变更日志 


引用:

http://www.php-oa.com/2010/05/11/linux-rpm-build.html

rpm 说明:

http://www.rpm.org/max-rpm/

rpm macros

http://fedoraproject.org/wiki/Packaging:RPMMacros

http://www.php-oa.com/2010/05/11/linux-rpm-build.html

http://rdc.taobao.com/blog/cs/?p=43


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值