wiki:RpmHowToPackagers

Version 4 (modified by Yuri Dario, 14 years ago) (diff)

Initial packager information's

RPM How-To for packagers

Basic informations for packagers: from writing a spec file, to testing a package, to releasing a package.

Introduction

RPM uses a special file to compile source code, prepare installation and create .rpm files: it is a .spec file, which is just a bunch of shell commands to prepare, build, install, check and clean the setup. Instead of writing a .spec file from scratch, you can get an existing one: a good source for them is the RPM find service. Enter the name of your package, and choose a distribution. Usually packages for Fedora or OpenSUSE 11.3 are good. Select your package from the left link, you will get a page with all details; one of them is the .src.rpm package, it contains the spec file, platform specific patches, package sources (in .tar.gz, .tar.bz2, .tar.xz format). Use unrpm.cmd (check bootstrap directory) to extract all files to a temporary location.

The first time you start rpmbuild.exe, it will create a set of directories in your %HOME% directory:

  • %HOME%\rpmbuild\BUILD (temporary storage for compiled files)
  • %HOME%\rpmbuild\BUILDROOT (temporary storage for installed files)
  • %HOME%\rpmbuild\RPMS (destinations of built .rpm files)
  • %HOME%\rpmbuild\SOURCES (source files and patches)
  • %HOME%\rpmbuild\SPECS (spec files)
  • %HOME%\rpmbuild\SRPMS (destination of built .src.rpm files)

Basic RPM tags: name: version: license: source: source1: patch0: patch1:

Prepare source code

This is done in the %prep section. Here the %setup macro will expand your source package (the one in the Source: line) and write the files by default in the %HOME%\rpmbuild\BUILD\{name}- {version} directory. You can change this with -n parameter for %setup macro. If you need to extract more source files, use the -a parameter. To apply first patch add patch0 -p1 -b .my_suffix; the second will use patch1...' and so on. Example:

%prep
# -D Do not delete the directory before unpacking.
# -T Disable the automatic unpacking of the archives.
%setup -q -n %{name}-%{srcver} %{?with_int_bdb:-a 1} -a 2
%patch001 -p1 -b .base

Build source code

Done in the %build section: common steps are execution of the configure script and use of gnu make to build code (this may be different for other programs). Example:

%build
CONFIG_SHELL="/bin/sh" ; export CONFIG_SHELL ; \
LDFLAGS="-Zbin-files -Zhigh-mem -Zomf -Zargs-wild -Zargs-resp" ; export LDFLAGS ; \
LIBS="-lurpo -lmmap -lpthread" ; export LIBS ; \
%configure \
    --enable-shared --disable-static --without-lua \
    %{!?with_int_bdb: --with-external-db} \
    %{?with_sqlite: --enable-sqlite3} \
    --enable-python \
    "--cache-file=%{_topdir}/cache/%{name}.cache"