rpm打包学习

  最近工作中需要针对freescale的iMX5和iMX6平台做一些arm平台下的系统核心软件包的集成,比如将glib、dbus、pkg-config、libxml2、pixman、gdb、libpng、gcc、gstreamer、ffmpeg、bluez等软件源代码针对arm平台打包成二进制的rpm包以及二进制源代码包.src.rpm。

      一、为什么要将源代码打包成rpm格式的二进制包?

      1、由于不同的计算机体系架构,比如arm和X86上的二进制是不一样的。我试过将一个简单的hello world的C语言的程序,当使用ubuntu12.04自带的gcc编译生成hello可执行程序,在arm的板子上跑不起来;使用scratchbox环境下的arm-linux-gcc交叉编译器编译生成基于arm的可执行程序hello在arm板子上能跑。所以在Linux下我们有时需要自己下载源代码进行编译,比如说Qt4.8.4的源代码,我曾经下载过qt-everywhere-opensource-src-4.8.4.tar.gz源代码,使用自己2G的内存、T5900的处理器编译安装Qt4.8.4需要两三个小时。但是如果针对自己的机器体系结构(比如一般的PC是i386体系)将QT源代码打包成rpm,再使用rpm工具安装,应该快多了,这就是rpm打包的好处吧。

     2、Linux操作系统发行商通常会针对自己的发行版本将源代码打包成二进制的rpm,方便开发者或者软件使用者安装,这样就不用直接使用源代码安装了。当然reahat系列提供了yum安装或者用户界面的安装方式,ubuntu也提供了对应的apt-get和ubuntu软件中心的软件安装方式。

     3、在嵌入式中,需要针对自己板子所在的平台,将第三方源代码或者自己写的代码打包成rpm二进制rpm包,发布给客户使用。

     二、如何将.tar.gz、.tar.xz等格式的源代码打包成rpm包?

    1、首先从BLFS网站http://www.linuxfromscratch.org/blfs/view/svn/index.html或者http://sourceforge.net/等开源网站下载源代码。

    2、然后编写spec文件,这个是很重要的一个环节。使用autotools(automake+autoconf)或者cmake生成源代码对应的makefile文件,再根据makefile编译、安装,打包成rpm。关于Spec文件的编写,可参照以下这几篇文章:

spec文件详解:http://blog.csdn.net/hncomputer/article/details/7162339

spec文件具体编写:http://cpbest.blog.163.com/blog/static/412415192009917477295/

RPM包rpmbuild SPEC文件深度说明:http://hlee.iteye.com/blog/343499

spec文件指南:http://zh.opensuse.org/index.php?title=openSUSE:Specfile_guidelines&variant=zh

RPM打包技术与典型SPEC文件分析:http://www.cnblogs.com/cnland/archive/2013/02/08/2909301.html

   3、配置好rpm打包的目录结构,一般在rpmbuild目录下有BUILD、SOURCES、RPMS、SRPMS、SPECS这几个目录。

   4、打rpm包。

        以从http://www.linuxfromscratch.org/blfs/view/svn/general/libpng.html下载的libpng-1.6.2为例,针对i386环境打包,编写好对应的libpng.spec文件后,再使用rmpbuild -ba libpng.spec执行第2步中编写的spec文件打包,假如在spec文件中的%package -n 描述有libpng-tools、libpng-runtime、libpng-devel三个包,那么执行完spec文件中的内容后可以在RPMS目录下看到对应的libpng-tools-1.6.2-1.i386.rpm、libpng-runtime-1.6.2-1.i386.rpm、libpng-devel-1.6.2-1.i386.rpm以及在SRPMS下生成libpng.src.rpm二进制源码包。

       可以从https://review.tizen.org/git/网站上找到一些常用软件的spec文件,如libpng对应的spec文件网址为:https://review.tizen.org/git/?p=external/libpng.git;a=tree;f=packaging;hb=refs/heads/tizen_2.1

tizen官网给出的libpng.spec内容如下:

[plain] view plain copy
  1. #sbs-git:slp/unmodified/libpng libpng 1.2.46 fcaa793c53a17a30625312c0e4e6de51383f2deb  
  2. Name:       libpng  
  3. Summary:    A library of functions for manipulating PNG image format files  
  4. Version:    1.2.50  
  5. Release:    1  
  6. Group:      System/Libraries  
  7. License:    zlib  
  8. URL:        http://www.libpng.org/pub/png/  
  9. Source0:    ftp://ftp.simplesystems.org/pub/png/src/libpng-%{version}.tar.bz2  
  10. Requires(post): /sbin/ldconfig  
  11. Requires(postun): /sbin/ldconfig  
  12. BuildRequires:  zlib-devel  
  13.   
  14.   
  15. %description  
  16. The libpng package contains a library of functions for creating and  
  17. manipulating PNG (Portable Network Graphics) image format files.  PNG  
  18. is a bit-mapped graphics format similar to the GIF format.  PNG was  
  19. created to replace the GIF format, since GIF uses a patented data  
  20. compression algorithm.  
  21.   
  22. Libpng should be installed if you need to manipulate PNG format image  
  23. files.  
  24.   
  25.   
  26.   
  27. %package devel  
  28. Summary:    Development tools for programs to manipulate PNG image format files  
  29. Group:      Development/Libraries  
  30. Requires:   %{name} = %{version}-%{release}  
  31. Requires:   libpng = %{version}-%{release}  
  32. Requires:   zlib-devel  
  33.   
  34. %description devel  
  35. The libpng-devel package contains header files and documentation necessary  
  36. for developing programs using the PNG (Portable Network Graphics) library.  
  37.   
  38.   
  39.   
  40. %prep  
  41. %setup -q -n %{name}-%{version}  
  42.   
  43. %build  
  44.   
  45. %configure --disable-static  
  46. make %{?jobs:-j%jobs}  
  47.   
  48. %install  
  49. rm -rf %{buildroot}  
  50. %make_install   
  51. rm -rf $RPM_BUILD_ROOT/usr/share/man  
  52. mkdir -p %{buildroot}/usr/share/license  
  53. cp LICENSE %{buildroot}/usr/share/license/%{name}  
  54.   
  55. %post -p /sbin/ldconfig  
  56. %postun -p /sbin/ldconfig  
  57.   
  58. %files  
  59. /usr/share/license/%{name}  
  60. %manifest libpng.manifest  
  61. %{_libdir}/libpng*.so.*  
  62.   
  63. %files devel  
  64. %{_bindir}/*  
  65. %{_includedir}/*  
  66. %{_libdir}/libpng*.so  
  67. %{_libdir}/pkgconfig/*  


当然,我们应该根据自己的需求加以修改,然后就可以打包、发布自己的软件了。

5、最后可以使用rpm -ivh libpng-1.6.2-1.i386.rpm在自己的X86机器上安装对应的rpm包。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值