The actual combat of rpm packaging under CentOS6

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.

Prepare rpm packaging environment#

The operating system I use here is CentOS6.7, and other distributions of the redhat series should be similar.

Install rpm-build

1 sudo yum install -y gcc make rpm-build redhat-rpm-config vim lrzsz

Create necessary folders and files##

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild'>~/.rpmmacros

Make spec file#

Find the spec template file##

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

Write your own package spec file##

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

Making rpm package#

Upload the necessary source files##

1 cp ${some_where}/Python-2.7.10.tgz ~/rpmbuild/SOURCES/

Start making##

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.

Skill summary#

  1. - bp Only extract the source code and apply patches
  2. - bc only compile
  3. - bi only install to %{buildroot}
  4. - bb only generate binary rpm package
  5. - bs only generate source rpm package
  6. - ba Generate binary rpm package and source rpm package
  7. - - 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

reference#

  1. http://vault.centos.org/6.7/os/Source/SPackages/
  2. http://tkdchen.github.io/blog/2013/05/19/rpm-spec-for-python-gist.html
  3. http://www.dahouduan.com/2015/06/15/linux-centos-make-rpm/
  4. http://www.centoscn.com/CentOS/Intermediate/2014/0419/2826.html
  5. http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment
  6. http://ftp.rpm.org/max-rpm/rpmbuild.8.html
  7. http://ftp.rpm.org/max-rpm/s1-rpm-inside-macros.html

Recommended Posts

The actual combat of rpm packaging under CentOS6
The fourth installment of Zabbix under CentOs7
Modify the default encoding of mysql5.6 under CentOS7
Installation under centos6.9 of jenkins learning
Install the latest OpenCV4.3 under Centos8
Installation and use of Mysql under CentOS
Installation and configuration of redis under centos7
Centos install the latest version of cmake
Centos 8.1.1911 solves the problem of yum reinstallation
Construction of Zabbix monitoring platform under CentOS7
[Centos8] The bumpy process of installing docker
Expand the disk size of Ubuntu under VMware
Summarize the knowledge points of Centos7 system reinforcement
Centos7.5 expands the space size under the root directory
Install the old version of seurat under Ubuntu
CentOS7 update the latest kernel | RPM directly install the kernel
Installation and configuration of rsync server under CentOS 6.5
Explain the implementation of Centos8 static IP configuration
Non-Root installation of Microsoft R Open under Centos
Distributed deployment of Apollo configuration center under CentOS8
From installation to entry of FastDFS under Centos7
Centos7 adjusts the size of the root directory mount partition
Installation and cracking of Jira7 operation records under Centos
Environment configuration of JDK, mysql and tomcat under Centos7
Online expansion of file system by LVM under Centos7