linux下面由tar包得到RPM包



linux下面由tar包得到RPM包
 
刚完成由一个tar包到RPM包,记录下面过程,以免又忘了。
   www.2cto.com  
手动由tar包做一个RPM包,就是需要我们自己去写一个spec文件,下面通过举例来实现这个过程:
现在我要将包gnome-control-center-2.29.90.tar.gz做成一个RPM包,首先我这个tar.gz通过./configure、make、make install是可以通过的。
1. 首先将gnome-control-center-2.29.90.tar.gz拷贝到系统制作RPM的SOURCES目录下面,这是我们需要的源码所在的目录。
2. 在SPECS目录下面创建一个叫做gnome-control-center.spec的spec文件。
3. 开始构写这个spec文件,我一般随便拿一个redhat写好的spec文件作为模板,因为每个spec文件的大体都差不多,可以直接在它的上面修改。
 
#描述这个包是做什么
Summary: The Control Center is a central way of accessing Gnome configuration applets   
#包名
Name: gnome-control-center
Version: 2.29.90
Release: 1.se.01
#Source0 就是我们需要的源代码tar包,一般这样指定
Source0: %{name}-%{version}.tar.gz
License: BSD and GPLv2+
Group: System Environment/Base
#BuildRequires就是说你最后得到的这个软件的src.rpm包时,如果你想要通过命令rpmbuild -bp 编译这个包,它会去检测依赖关系,
BuildRequires: esound
BuildRequires: esound-devel
BuildRequires: audiofile-devel
#设置整个编译过程的目录,一般用下面这种方式
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description
The Gnome Control Center allows you to configure various parts of your system using a collection of tools called "capplets". These capplets may be associated with the core set of Gnome applications or other applications for which the developers have written capplets.
 
%prep
 
#设置要解压的tar包的文件
%setup -n %{name}-%{version}
#编译,就是执行./configure和make之类的
 
%build
./configure --prefix=/usr/
make
 
#安装,就是make install
%install
rm -rf %{RPM_BUILD_ROOT}
mkdir %{RPM_BUILD_ROOT}
make DESTDIR=$RPM_BUILD_ROOT install
 
%clean
rm -rf ${RPM_BUILD_ROOT}
 
#file这段是说你最后生成的包中包含了哪些文件,比如我们通过命令rpm -ql  gdm-2.30.4-33.el6_2.x86_64
#打印出的结果中指出这个软件包安装了哪些文件,其实就是通过file这里指定
%files
#设置它的属性
%defattr(-,root,root)
#我将这么一个可执行文件加入到这个包里面。
/usr/bin/gnome-control-center
 
#就是修改记录
%changelog
* Tue Dec 4 2012 Aiping  Liu <....@......> 
- 大致说明下你为什么修改
 
保存这个文件,运行命令:
#rpmbuild   -ba  gnome-control-center.spec
就可以得到我们需要到的rpm包,而且这个包安装的时候只会安装一个文件:/usr/bin/gnome-control-center。
 
可以你在编译的时候会出现类似下面的错误:
error: Installed (but unpackaged) file(s) found:
。。。。。。。。。。。。。
RPM build errors:
    Installed (but unpackaged) file(s) found:
   /usr/bin/gnome-appearance-properties
   /usr/bin/gnome-at-mobility
   /usr/bin/gnome-at-properties
。。。。。。。。。。。
其实这和你spec文件中写的“%file”那一块有关,意思是说:你有这些文件没有在spec文件中没有被包含,但是又被安装,解决办法是:
1. 如果显示很多文件,将这些文件你可以分门别类,用%doc、%config这些宏来指定,其实如果它报错的时候,只显示一两个文件,可以直接把那个文件写在%file下面
2. 进入文件/usr/lib/rpm/macros,找到
%__check_files         %{_rpmconfigdir}/check-files %{buildroot}
这一行,把这一行注释掉,然后重新编译。
这两种方法,还是根据自己的需要来选择。
 

相关内容

    暂无相关文章