Kapitel 6. Bau des Pakets

Inhaltsverzeichnis

6.1. Kompletter (Neu-)Bau
6.2. Autobuilder
6.3. Der Befehl debuild
6.4. Das Paket pbuilder
6.5. Das Kommando git-buildpackage und ähnliche
6.6. Schneller Neubau

Nun sollten wir soweit sein, das Paket zu bauen.

6.1. Kompletter (Neu-)Bau

In order to perform a complete (re)build of a package properly, you need to make sure you have installed

Dann führen Sie den folgenden Befehl im Quellverzeichnis des Programms aus:

$ dpkg-buildpackage

Dies wird alles für Sie erledigen, um vollständige Binärpakete und Quellpakete zu erstellen. Im Einzelnen:

  • Aufräumen des Quellverzeichnisbaums (»debian/rules clean«),

  • Bauen des Quellpakets (»dpkg-source -b«),

  • Bauen des Programms (»debian/rules build«),

  • Bauen der Binärpakete (»fakeroot debian/rules binary«),

  • Signieren der .dsc-Quelldatei mit gpg,

  • Erstellen und Signieren der für das Hochladen notwendigen .changes-Datei mit dpkg-genchanges und gpg.

The only input that will be required of you is your GPG secret pass phrase, twice. [64] If you are building Debian packages only for your own local use, you can skip promptings for the GPG signatures on the .dsc file and the .changes file like this:

$ dpkg-buildpackage -us -uc

For a non-native Debian package, e.g., gentoo, you will see the following files in the parent directory (~/gentoo) after building packages:

  • gentoo_0.9.12.orig.tar.gz

    This is the original upstream source code tarball, merely renamed to the above so that it adheres to the Debian standard. Note that this was created initially by the dh_make -f ../gentoo-0.9.12.tar.gz.

  • gentoo_0.9.12-1.dsc

    Dies ist eine Zusammenfassung des Inhalts des Quellcode-Pakets. Diese Datei wird aus Ihrer Datei control erzeugt und für das Entpacken des Quellcodes mittels dpkg-source(1) benötigt. Diese Datei ist mit GPG signiert, somit können sich die Leute vergewissern, dass sie von Ihnen kommt.

  • gentoo_0.9.12-1.debian.tar.gz

    This compressed tarball contains your debian directory contents. Each and every addition you made to the original source code is stored as a quilt patch in debian/patches.

    Wenn jemand Ihr Paket von Grund auf neu bauen will, kann er dafür einfach die drei oben genannten Dateien verwenden. Das Verfahren des Auspackens ist trivial: kopieren Sie einfach die drei Dateien in ein Verzeichnis und führen Sie »dpkg-source -x gentoo_0.9.12-1.dsc« aus. [65]

  • gentoo_0.9.12-1_i386.deb

    Das ist Ihr fertiges Binärpaket. Sie können es mit dpkg installieren und wieder entfernen wie jedes andere Paket auch.

  • gentoo_0.9.12-1_i386.changes

    This file describes all the changes made in the current package revision; it is used by the Debian FTP archive maintenance programs to install the binary and source packages. It is partly generated from the changelog file and the .dsc file. This file is GPG signed, so that people can be sure that it's really yours.

    As you keep working on the package, its behavior will change and new features will be added. People downloading your package can look at this file and quickly see what has changed. Debian archive maintenance programs will also post the contents of this file to the debian-devel-changes@lists.debian.org mailing list.

The long strings of numbers in the .dsc and .changes files are SHA1/SHA256 checksums for the files mentioned. Anyone downloading your files can test them with sha1sum(1) or sha256sum(1) and if the numbers don't match, they'll know the file is corrupt or has been tampered with.

For a native Debian package, e.g., mypackage, you will see the following files in the parent directory after building packages:

  • mypackage_1.0.tar.gz

    This is the source code tarball created from the mypackage-1.0 directory by the dpkg-source command. (Its suffix is not orig.tar.gz.)

  • mypackage_1.0.dsc

    This is a summary of the contents of the source code as in the non-native Debian package. (There is no Debian revision.)

  • mypackage_1.0_i386.deb

    This is your completed binary package as in the non-native Debian package. (There is no Debian revision.)

  • mypackage_1.0_i386.changes

    This file describes all the changes made in the current package version as in the non-native Debian package. (There is no Debian revision.)

6.2. Autobuilder

Debian supports many ports with the autobuilder network running buildd daemons on computers of many different architectures. Although you do not need to do this yourself, you should be aware of what will happen to your packages. Let's look into roughly how they rebuild your packages for multiple architectures. [66]

For Architecture: any packages, the autobuilder system performs a rebuild. It ensures the installation of

  • sowohl das Paket build-essential als auch

  • die Pakete, die im Feld Build-Depends (siehe Abschnitt 4.1, „control) aufgeführt sind, installiert sind.

Dann führt es den folgenden Befehl im Quellverzeichnis aus:

$ dpkg-buildpackage -B

Hiermit wird alles erledigt, um ein architekturabhängiges Binärpaket für eine andere Architektur zu erstellen. Im Einzelnen:

  • Aufräumen des Quellverzeichnisbaums (»debian/rules clean«),

  • Bauen des Programms (»debian/rules build«),

  • Bauen der architekturabhängigen Binärpakete (»fakeroot debian/rules binary-arch«)

  • Signieren der .dsc-Quelldatei mit gpg,

  • Erstellen und Signieren der für das Hochladen notwendigen .changes-Datei mit dpkg-genchanges und gpg.

Das ist der Grund, weshalb Sie Ihr Paket auch für andere Architekturen sehen.

Although packages listed in the Build-Depends-Indep field are required to be installed for our normal packaging work (see Abschnitt 6.1, „Kompletter (Neu-)Bau“), they are not required to be installed for the autobuilder system since it builds only architecture dependent binary packages. [67] This distinction between normal packaging and autobuilding procedures is what dictates whether you should record such required packages in the Build-Depends or Build-Depends-Indep fields of the debian/control file (see Abschnitt 4.1, „control).

6.3. Der Befehl debuild

You can automate the dpkg-buildpackage command's package build process further with the debuild command. See debuild(1).

Customization of the debuild command can be done through /etc/devscripts.conf or ~/.devscripts. I would suggest at least the following items:

DEBSIGN_KEYID=Your_GPG_keyID
DEBUILD_LINTIAN_OPTS=-i -I --show-overrides

With these, packages are signed by your specified GPG key ID (good for sponsoring packages) and checked in detail by the lintian command.

Cleaning the source and rebuilding the package from your user account is as simple as:

$ debuild

Here, if you are building Debian packages only for your own local use, you can skip promptings for the GPG signatures on the .dsc file and the .changes file like this:

$ debuild -us -uc

You can clean the source tree as simply as:

$ debuild clean

6.4. Das Paket pbuilder

For a clean room (chroot) build environment to verify the build dependencies, the pbuilder package is very useful. [68] This ensures a clean build from the source under the sid auto-builder for different architectures and avoids a severity serious FTBFS (Fails To Build From Source) bug which is always in the RC (release critical) category. [69]

Let's customize the pbuilder package as follows:

  • setting the /var/cache/pbuilder/result directory writable by for your user account.

  • creating a directory, e.g. /var/cache/pbuilder/hooks, writable by the user, to place hook scripts in.

  • configuring ~/.pbuilderrc or /etc/pbuilderrc to include the followsing.

    AUTO_DEBSIGN=${AUTO_DEBSIGN:-yes}
    HOOKDIR=/var/cache/pbuilder/hooks
    

Hiermit können Sie erstellte Pakete mit Ihrem geheimen GPG-Schlüssel im Verzeichnis ~/.gnupg/ unterschreiben.

First let's initialize the local pbuilder chroot system as follows.

$ sudo pbuilder create

If you already have a completed source package, issue the following commands in the directory where the foo.orig.tar.gz, foo.debian.tar.gz, and foo.dsc files exist to update the local pbuilder chroot system and to build binary packages in it.

$ sudo pbuilder --update
$ sudo pbuilder --build foo_version.dsc

The newly built packages without the GPG signatures will be located in /var/cache/pbuilder/result/ with non-root ownership.

The GPG signatures on the .dsc file and the .changes file can be generated as:

$ cd /var/cache/pbuilder/result/
$ debsign foo_version.dsc
$ debsign foo_version_arch.changes

If you have an updated source tree but have not generated the matching source package, issue the following commands in the source directory where the debian directory exists, instead.

$ sudo pbuilder --update
$ pdebuild

Here, if you are building Debian packages only for your local use, you can skip promptings for the GPG signatures on the .dsc file and the .changes file as:

$ AUTO_DEBSIGN=no pdebuild

Sie können sich in der erstellten chroot-Umgebung anmelden, indem Sie den Befehl »pbuilder --login --save-after-login« verwenden und diese dann so einrichten wie Sie wollen. Diese Umgebung kann gespeichert werden, indem die Shell-Eingabeaufforderung mittels ^D (Steuerung-D) verlassen wird.

Die aktuelle Version des Programms lintian kann in der chroot-Umgebung ausgeführt werden, indem das Hook-Skript /var/cache/pbuilder/hooks/B90lintian wie folgt eingerichtet wird. [70]

#!/bin/sh
set -e
install_packages() {
        apt-get -y --force-yes install "$@"
        }
install_packages lintian
echo "+++ lintian output +++"
su -c "lintian -i -I --show-overrides /tmp/buildd/*.changes" - pbuilder
# use this version if you don't want lintian to fail the build
#su -c "lintian -i -I --show-overrides /tmp/buildd/*.changes; :" - pbuilder
echo "+++ end of lintian output +++"

You need to have access to the latest sid environment to build packages properly for sid. In practice, sid may be experiencing issues which makes it undesirable for you to migrate your whole system. The pbuilder package can help you to cope with this kind of situation.

You may need to update your stable packages after their release for stable-proposed-updates, stable/updates, etc. [71] For such occasions, the fact you may be running a sid system is not a good enough excuse for failing to update them promptly. The pbuilder package can help you to access environments of almost any Debian derivative distribution of the same architecture.

See http://www.netfort.gr.jp/~dancer/software/pbuilder.html, pdebuild(1), pbuilderrc(5), and pbuilder(8).

6.5. Das Kommando git-buildpackage und ähnliche

If your upstream uses a source code management system (VCS) [72] to maintain their code, you should consider using it as well. This makes merging and cherry-picking upstream patches much easier. There are several specialized wrapper script packages for Debian package building for each VCS.

  • git-buildpackage: a suite to help with Debian packages in Git repositories.

  • svn-buildpackage: Hilfsprogramme zur Betreuung von Debian-Paketen mit Subversion.

  • cvs-buildpackage: a set of Debian package scripts for CVS source trees.

Use of git-buildpackage is becoming quite popular for Debian Developers to manage Debian packages with the Git server on alioth.debian.org. [73] This package offers many commands to automate packaging activities.

  • git-import-dsc(1): import previous Debian package to a Git repository.

  • git-import-orig(1): import new upstream tar to a Git repository.

  • git-dch(1): generate the Debian changelog from Git commit messages.

  • git-buildpackage(1): build Debian packages from a Git repository.

  • git-pbuilder(1): build Debian packages from a Git repository using pbuilder/cowbuilder.

These commands use 3 branches to track packaging activity.

  • main for Debian package source tree.

  • upstream for upstream source tree.

  • pristine-tar for upstream tarball generated by the --pristine-tar option.[74]

You can configure git-buildpackage with ~/.gbp.conf. See gbp.conf(5). [75]

6.6. Schneller Neubau

With a large package, you may not want to rebuild from scratch every time while you're tuning details in debian/rules. For testing purposes, you can make a .deb file without rebuilding the upstream sources like this[76]:

$ fakeroot debian/rules binary

Or simply do the following to see if it builds or not:

$ fakeroot debian/rules build

Wenn Sie mit Ihren Anpassungen fertig sind, vergessen Sie nicht, das Paket gemäß der korrekten Prozedur neu zu bauen. Sie werden .deb-Dateien, die auf diese Weise gebaut wurden, nicht korrekt hochladen können.



[64] This GPG key must be signed by a Debian developer to get connected to the web of trust and must be registered to the Debian keyring. This enables your uploaded packages to be accepted to the Debian archives. See Creating a new GPG key and Debian Wiki on Keysigning.

[65] You can avoid applying quilt patches in the 3.0 (quilt) source format at the end of the extraction with the --skip-patches option. Alternatively, you can run dquilt pop -a after normal operation.

[66] Das tatsächliche Autobuilder-System besteht aus einem wesentlich komplizierteren Schema als dem hier dargestellten. Diese Details führen aber hier zu weit.

[67] Unlike under the pbuilder package, the chroot environment under the sbuild package used by the autobuilder system does not enforce the use of a minimal system and may have many leftover packages installed.

[68] Since the pbuilder package is still evolving, you should check the actual configuration situation by consulting the latest official documentation.

[69] See http://buildd.debian.org/ for more on Debian package auto-building.

[70] This assumes HOOKDIR=/var/cache/pbuilder/hooks. You can find many examples of hook scripts in the /usr/share/doc/pbuilder/examples directory.

[71] Es gibt für Aktualisierungen Ihrer Stable-Pakete einige Einschränkungen.

[72] See Version control systems for more.

[73] Debian wiki Alioth documents how to use the alioth.debian.org service.

[74] The --pristine-tar option invokes the pristine-tar command which can regenerate an exact copy of a pristine upstream tarball using only a small binary delta file and the contents of the tarball, which are typically kept in an upstream branch in the VCS.

[75] Here are some web resources available for advanced audiences.

[76] Umgebungsvariablen, die normalerweise auf vernünftige Werte gesetzt sind, werden bei dieser Methode nicht eingerichtet. Erstellen Sie niemals echte Pakete, die hochgeladen werden sollen, mit dieser schnellen Methode.