最近的工作需要将以前编译安装的软件包打包成rpm包,这里将打包过程记录一下以备忘。
我这里用的操作系统是CentOS6.7,redhat系的其它发行版应该也类似。
1 | sudo yum install -y gcc make rpm-build redhat-rpm-config vim lrzsz |
---|
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
一般找一个类似的rpm源码包,将其安装,然后参照它写自己软件包的spec文件。
mkdir ~/rpms
wget -O ~/rpms/python-2.6.6-64.el6.src.rpm http://vault.centos.org/6.7/os/Source/SPackages/python-2.6.6-64.el6.src.rpm
rpm -ivh ~/rpms/python-2.6.6-64.el6.src.rpm
vim ~/rpmbuild/SPECS/python.spec # 参照这个文件来写自己软件包的spec文件
spec文件中各个选项的意义参照这里
cd ~/rpmbuild
cat ./SPECS/python27-tstack.spec
%debug_package %{nil}
%define install_dir /usr/local/python27
Name: python27-tstack
Version: 2.7.10
Release: 1%{?dist}
Summary: python27 modified by tstack
URL: http://www.python.org/
Group: Development/Languages
License: Python
Provides: python-abi = 2.7
Provides: python(abi) = 2.7
Source0: Python-2.7.10.tgz
BuildRequires: readline-devel, openssl-devel, gmp-devel, pcre-devel, mysql-devel, libffi-devel
Requires: readline, openssl, gmp, pcre, mysql, libffi
Autoreq: 0
%description
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
%prep
%setup -q -n Python-%{version}
%build
./configure --prefix=%{install_dir} --with-cxx-main=/usr/bin/g++
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%clean
rm -rf %{buildroot}
%files
%defattr (-,root,root)
%{install_dir}/bin/
%{install_dir}/include/
%{install_dir}/lib/
%{install_dir}/share/
%doc
%changelog
1 | cp ${some_where}/Python-2.7.10.tgz ~/rpmbuild/SOURCES/ |
---|
cd ~/rpmbuild
rpmbuild -bb --target x86_64 SPECS/python27-tstack.spec &> rpmbuild.log # 这时可以打开另一个终端观察下rpmbuild.log
一切顺序的话,最终会在~/rpmbuild/RPMS/x86_64/
目录下找到编译好的rpm包。
%debug_package %{nil}
即可Autoreq: 0
即可%setup
、%patch
,这两个宏的选项较多,使用时要特别注意,参见这里%pre
, %post
, %preun
, %postun
指定rpm包在安装卸载前后的动作,比如在安装前用脚本做一些准备、在安装后用脚本做一些初始化动作、在卸载前用脚本做一些准备、在卸载后用脚本做一些清理动作-bp
只解压源码及应用补丁-bc
只进行编译-bi
只进行安装到%{buildroot}-bb
只生成二进制rpm包-bs
只生成源码rpm包-ba
生成二进制rpm包和源码rpm包--target
指定生成rpm包的平台,默认会生成i686
和x86_64
的rpm包,但一般我只需要x86_64
的rpm包