• 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内容如下:

    #sbs-git:slp/unmodified/libpng libpng 1.2.46 fcaa793c53a17a30625312c0e4e6de51383f2deb
    Name:       libpng
    Summary:    A library of functions for manipulating PNG image format files
    Version:    1.2.50
    Release:    1
    Group:      System/Libraries
    License:    zlib
    URL:        http://www.libpng.org/pub/png/
    Source0:    ftp://ftp.simplesystems.org/pub/png/src/libpng-%{version}.tar.bz2
    Requires(post): /sbin/ldconfig
    Requires(postun): /sbin/ldconfig
    BuildRequires:  zlib-devel
    
    
    %description
    The libpng package contains a library of functions for creating and
    manipulating PNG (Portable Network Graphics) image format files.  PNG
    is a bit-mapped graphics format similar to the GIF format.  PNG was
    created to replace the GIF format, since GIF uses a patented data
    compression algorithm.
    
    Libpng should be installed if you need to manipulate PNG format image
    files.
    
    
    
    %package devel
    Summary:    Development tools for programs to manipulate PNG image format files
    Group:      Development/Libraries
    Requires:   %{name} = %{version}-%{release}
    Requires:   libpng = %{version}-%{release}
    Requires:   zlib-devel
    
    %description devel
    The libpng-devel package contains header files and documentation necessary
    for developing programs using the PNG (Portable Network Graphics) library.
    
    
    
    %prep
    %setup -q -n %{name}-%{version}
    
    %build
    
    %configure --disable-static
    make %{?jobs:-j%jobs}
    
    %install
    rm -rf %{buildroot}
    %make_install 
    rm -rf $RPM_BUILD_ROOT/usr/share/man
    mkdir -p %{buildroot}/usr/share/license
    cp LICENSE %{buildroot}/usr/share/license/%{name}
    
    %post -p /sbin/ldconfig
    %postun -p /sbin/ldconfig
    
    %files
    /usr/share/license/%{name}
    %manifest libpng.manifest
    %{_libdir}/libpng*.so.*
    
    %files devel
    %{_bindir}/*
    %{_includedir}/*
    %{_libdir}/libpng*.so
    %{_libdir}/pkgconfig/*
    
    


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

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


     


  • 相关阅读:
    xunjian.sh
    192.168.50.235配置
    自动备份并删除旧日志
    bg和fg命令
    linux之sed用法
    正则表示第二行,第二列
    linux下redis安装
    Hma梳理
    linux 系统监控、诊断工具之 lsof 用法简介
    java的基本数据类型有八种
  • 原文地址:https://www.cnblogs.com/ccf19881030/p/12004888.html
Copyright © 2020-2023  润新知