Recent work needs to package the previously compiled and installed software packages into rpm packages. Here, the packaging process will be recorded as a reminder.
The operating system I use here is CentOS6.7, and other distributions of the redhat series should be similar.
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
Generally find a similar rpm source code package, install it, and then refer to it to write the spec file of your own package.
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 #Refer to this file to write the spec file of your own package
For the meaning of each option in the spec file, please refer to here
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 newbuilt-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 # Now you can open another terminal to observe rpmbuild.log
In all order, you will eventually find the compiled rpm package in the ~/rpmbuild/RPMS/x86_64/
directory.
%debug_package %{nil}
in the spec fileAutoreq: 0
in the spec file.%setup
and %patch
. These two macros have many options. Pay special attention when using them, see here%pre
, %post
, %preun
, %postun
Then use the script to do some initialization actions, use the script to make some preparations before uninstalling, and use the script to do some cleaning actions after the uninstallation.- bp
Only extract the source code and apply patches- bc
only compile- bi
only install to %{buildroot}- bb
only generate binary rpm package- bs
only generate source rpm package- ba
Generate binary rpm package and source rpm package- - target
specifies the platform for generating the rpm package. By default, the rpm package of i686
and x86_64
will be generated, but generally I only need the rpm package of x86_64
Recommended Posts