Repackage src.rpm

Here are some hints for creating a proper Debian source package while referencing the src.rpm package created for the RPM system.

Although I call this activity as repackage, this activity involves many manual alteration processes and packaging strategy choices which are different from the original src.rpm.

It is not easy to decide which part of the source code to activate and which binary sub packages to offer for the Debian package, the use of src.rpm (or the SPEC file) as the baseline expedites decisions for such issues. So use them if you can!

<!> Pre-requisite: Read and understand everything in Debian New Maintainers' Guide.

<!> This is not the same as repackaging of the binary RPM file using the alien package.

How to find src.rpm from Fedora project

Redhat kindly publishes their latest src.rpm packages of the Fedora project to the public. They can be searched at:

For example, searching on "ibus*" glob returns "Search Results for packages matching "ibus*" with 47 sets of ID and Name starting with a set "3103" and "ibus".

Clicking on package name "ibus" leads to "Information for package ibus" with many build results. Here, "NVR" value such as "ibus-1.5.3-1.fc19" roughly means:

Clicking on NVR "ibus-1.5.3-1.fc19" leads to "Information for build ibus-1.5.3-1.fc19".

This page lists information on the src.rpm, the binary rpm (armv7hl and noarch) and Changelog.

The URL of the latest src.rpm of Fedora is linked from "RPMs" -> "src" -> "(download)".

The outline information page of src.rpm containing build dependency indicated in the SPEC file and files bundled is linked from "RPMs" -> "src" -> "(info)".

How to find src.rpm from OpenSUSE project

Novell kindly publishes their latest src.rpm packages of the open SUSE project to the public. They can be searched at:

For example, searching on "ibus" returns "Search Results for packages matching "ibus" with 26 sets of packages.

Clicking on package name "ibus" leads to "Intelligent Input Bus for Linux OS". Clicking "Repositories" and "standard" leads you to a page with "ibus-1.5.4-5.1.src.rpm".

This is the URL for the latest src.rpm of open SUSE.

I also look for URL such as: http://download.opensuse.org/factory/repo/src-oss/suse/src/

How to download and extract src.rpm

I have created a "rget" script as:

#!/bin/sh
FCURL=$1
FCSRPM=$(basename $FCURL)

mkdir ${FCSRPM}
cd ${FCSRPM}/
wget ${FCURL}
rpm2cpio ${FCSRPM} | cpio -dium

For Fedora project, using right click on "(download)" to "Copy link address" and pasting to the console, I run "rget" command as:

 $ rget http://arm.koji.fedoraproject.org//packages/ibus-anthy/1.5.3/1.fc19/src/ibus-anthy-1.5.3-1.fc19.src.rpm

This performs the following:

The "debamke -a <URL_TO_src.rpm>" command (from the debmake package) can download and unpack the source RPM file while adding template debian/* files.

How to read the build info

spec file

The build info for the src.rpm is found in the spec file. For "ibus", the spec file is "ibus.spec".

(!) Some upstream tar balls include a <packagename>.spec file in the source tree. That can be used as well.

Debian packaging system stores package information in multiple files under the "debian" directory.

Instead, the spec file stores them all in a file sectioned by lines starting with "%" such as "%package", "%description", "%patch", "%build", "%configure", "%install", "%files", ... Basically, each section embeds shell script lines and text data lines.

Their meanings are quite intuitive. Their exact meanings are explained elsewhere:

For now, let's recall the very basics.

The "#" character is used to put comment like a shell program

The "%" character has many other functions other than sectioning the spec file. Let's see them by the example.

%if (0%{?fedora} > 18 || 0%{?rhel} > 6)
%global with_python_pkg 1
%else
%global with_python_pkg 0
%endif

The above example section of configuration is like CPP conditional section and means:

If (the target fedora version is larger than 18 or the rhel version is larger than 6 in number):
    set global variable with_python_pkg to 1
else:
    set global variable with_python_pkg to 0
endif

The global variables are string and can be used as the argument of "%if" for this CPP like conditional section. The string value 1 means True and the string value 0 means False.

How to set up source tree

The most interesting sections of the spec file are sections describing how to setup the source tree. You need to read several sections to get the idea. For example in "ibus.spec":

%global with_preload_xkb_engine 1

... [skip lines]

Name:       ibus
Version:    1.5.3
Release:    1%{?dist}
Summary:    Intelligent Input Bus for Linux OS
License:    LGPLv2+
Group:      System Environment/Libraries
URL:        http://code.google.com/p/ibus/
Source0:    http://ibus.googlecode.com/files/%{name}-%{version}.tar.gz
Source1:    %{name}-xinput
# Upstreamed patches.
# Patch0:     %{name}-HEAD.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=810211
Patch1:     %{name}-810211-no-switch-by-no-trigger.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=541492
Patch2:     %{name}-541492-xkb.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=530711
Patch3:     %{name}-530711-preload-sys.patch
# Hide minor input method engines on ibus-setup by locale
Patch4:     %{name}-xx-setup-frequent-lang.patch

... [skip lines]

%prep
%setup -q

# %%patch0 -p1
cp client/gtk2/ibusimcontext.c client/gtk3/ibusimcontext.c ||
%patch1 -p1 -b .noswitch
%if %with_preload_xkb_engine
%patch2 -p1 -b .preload-xkb
rm -f bindings/vala/ibus-1.0.vapi
rm -f data/dconf/00-upstream-settings
%endif
%patch3 -p1 -b .preload-sys
%patch4 -p1 -b .setup-frequent-lang

This means:

The file removals can be implemented in the override_dh_auto_clean target.

(!) There are many entries with BuildRequires:. They indicate the package build dependency of the source.

option for ./configure

Another interesting section is "%configure". For example in "ibus.spec":

%global with_pygobject2 1

... [skip lines]

%configure \
    --disable-static \
    --enable-gtk2 \
    --enable-gtk3 \
    --enable-xim \
    --enable-gtk-doc \
    --with-no-snooper-apps='gnome-do,Do.*,firefox.*,.*chrome.*,.*chromium.*' \
    --enable-surrounding-text \
%if %with_pygobject2
    --enable-python-library \
%endif
    --enable-introspection

The global variable "with_pygobject2" is 1 (True). So when building package, this spec file asks to execute:

./configure \
    --disable-static \
    --enable-gtk2 \
    --enable-gtk3 \
    --enable-xim \
    --enable-gtk-doc \
    --with-no-snooper-apps='gnome-do,Do.*,firefox.*,.*chrome.*,.*chromium.*' \
    --enable-surrounding-text \
    --enable-python-library \
    --enable-introspection

This usually goes to debian/rules under "override_dh_configure:" as:

override_dh_configure:
 [TAB]  dh_configure -- \
        --disable-static \
        --enable-gtk2 \
        --enable-gtk3 \
        --enable-xim \
        --enable-gtk-doc \
        --with-no-snooper-apps='gnome-do,Do.*,firefox.*,.*chrome.*,.*chromium.*' \
        --enable-surrounding-text \
        --enable-python-library \
        --enable-introspection

If cdbs is used, these flags are added by "DEB_CONFIGURE_EXTRA_FLAGS +=" in the debian/rules file.

install

Just like Debian packaging system have <bin_package>.install to pick files to be installed into a particular binary package, src.rpm have a section "%file <bin_package_suffix>" section. Please note that only suffix is used to identify the binary package name in the spec file.

If you need to execute command to generate installed files, execute them in the override_dh_auto_install target etc..

For example, libtool archive files are removed in the "ibus.spec" file in install phase after the execution of the standard "make install" as:

%install
make install DESTDIR=$RPM_BUILD_ROOT INSTALL='install -p'
rm -f $RPM_BUILD_ROOT%{_libdir}/libibus-%{ibus_api_version}.la
rm -f $RPM_BUILD_ROOT%{_libdir}/gtk-2.0/%{gtk2_binary_version}/immodules/im-ibus.la
rm -f $RPM_BUILD_ROOT%{_libdir}/gtk-3.0/%{gtk3_binary_version}/immodules/im-ibus.la

This can be translated into debian/rules by removing such files before install as:

override_dh_install:
        dh_install --fail-missing -X .la

Please note the purpose of the manual repackaging is not the line-by-line conversion. It is to create a new Debian package in the most natural form while reusing the known-good-packaging-idea used in the RPM world.

splitting into binary packages

The main binary (=source) package name, its package dependency, and the main package description are defined in SPEC file as, e.g. ibus,:

...
Name:       ibus
...
Requires:   %{name}-libs = %{version}-%{release}
Requires:   %{name}-gtk2 = %{version}-%{release}
Requires:   %{name}-gtk3 = %{version}-%{release}
Requires:   %{name}-conf = %{version}-%{release}

Requires:   pygtk2
Requires:   iso-codes
Requires:   dbus-python >= %{dbus_python_version}
Requires:   im-chooser >= %{im_chooser_version}
Requires:   notify-python
Requires:   librsvg2
...
%description
IBus means Intelligent Input Bus. It is an input framework for Linux OS.
...

The sub binary package name suffix, its package dependency, and its description are defined in SPEC file as, e.g. ibus-libs,:

...
%package libs
Summary:    IBus libraries
Group:      System Environment/Libraries

Requires:   glib2 >= %{glib_ver}
Requires:   dbus >= 1.2.4

%description libs
This package contains the libraries for IBus
...

(!) The corresponding Debian package name is libibus-1.0-5 for this case. Package naming convention differences need to be noted.

Reminders for repackaging

Please note few things for this repackaging:

#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# To enable all hardening options, uncomment following line
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# To add extra build options
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# To ensure setting $(DEB_HOST_MULTIARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) 

# For hardening problem under cmake, uncomment following line
#CFLAGS += $(CPPFLAGS)
#CXXFLAGS += $(CPPFLAGS)

%:
 [TAB]   dh $@

...

Example of src.rpm repackaging

I strongly recommend to see the actual example: ibus 1.5.3-* Debian package and its FC19 src.rpm.

This can be done as:

$ git clone git://anonscm.debian.org/pkg-ime/ibus.git
$ cd ibus
$ gitk --all

There are much more details needed to be handled than described in the above.

Other source of reference information

If you need reference information other than Fedora and OpenSUSE projects, see an extensive list found at:


CategoryPackaging