前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >rpm打包学习

rpm打包学习

作者头像
ccf19881030
发布2019-04-23 15:54:23
2.2K0
发布2019-04-23 15:54:23
举报
文章被收录于专栏:ccf19881030的博客ccf19881030的博客

  最近工作中需要针对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内容如下:

代码语言:javascript
复制
#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包。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013年05月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档