Introduction of RPM packaging

This is an introduction and basic usage for RPM packaging, reading upstream docs if you want more.

Basic concepts of RPM

RPM is an packaging system for Linux distros. besides Red Hat’ Fedora, RHEL, CentOS, many other important distros also using RPM package system, include but not limited: openSuSE, Turbo Linux, openEuler, etc.

Packaging principle

RPM using spec file to describe a package’s preparation, compilation, and packaging process.

Structure of SPEC file

Each section indicates a step to compile source code to an RPM package, below is an example:

Section Source dir Dir Operaion
%prep %_sourcedir %_builddir prepare source in for compiling in %_builddir with tarball, patch stored in %_sourcedir
%build %_builddir %_builddir compile in %_builddir with configure, make or other similar operation to generate binaries
%install %_builddir %_buildrootdir install binaries to %_buildrootdir
%check %_builddir %_builddir check binaries with test program in source, can be skipped
%files %_buildrootdir %_rpmdir or %_srpmdir files in %_builddir will be packaged to RPM or SRPM pacakge

Package process

Preparation

Tools

RPM package tools:

  • rpm-build
  • rpmdevtools(optional, but suggested)

Directories sturcture

Using rpmdevtools command rpmdev-setuptree to generate a standard RPM packaging tree. default location is ~/rpmbuild and structure as below:

rpmbuild
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

Install a SRPM package with command rpm, will create this tree, too.

spec file default in SPECS sub directory

Source code tarball and patches or other files used in building process, will be put in SOURCES, all files should be declared in SPEC file.

Packaging

After prepared all files and spec file, using rpmbuild to run package process

  • SRPM package
rpmbuild -bs ~/rpmbuild/SPECS/my.spec
  • RPM package
rpmbuild -bb ~/rpmbuild/SPECS/my.spec
  • Package SRPM and RPM in one process
rpmbuild -ba ~/rpmbuild/SPECS/my.spec

rpmbuild will generate directories and packages under~/rpmbuild/SRPMS and ~/rpmbuild/RPMS when everything is okay.

To read Fedora documentation to get more knowledge of RPM package.

Example

mock

The dependency requirement may be different in deferent root file system, so a ‘clean’ root filessystem for package is necessary. mock is the tool to create the ‘clean filesystem’. mock is used in many distros.

Using mock to create package, is similar to rpmbuild as below:

mock -r distro-config-file  --rebuild --spec=spec-file --sources=source-dir

Read mock documentation to get more of mock.

Packaging system

Distributions or third party communities such as oepkgs.net will provide computing resources to create RPM packages for distributes.

Copyright © oepkgs.net All rights reserved.

版权所有 © oepkgs.net 保留所有权利

中国科学院软件研究所openEuler 社区共同发起并提供支持

京ICP备05046678号-13

Email: support(at)oepkgs.net