Kapitel 4. Einfaches Beispiel

Inhaltsverzeichnis

4.1. Gesamtbild
4.2. Was ist Debmake?
4.3. Was ist Debuild?
4.4. Schritt 1: Holen der Quellen der Originalautoren
4.5. Schritt 2: Mit Debmake erstellte Vorlagendateien
4.6. Schritt 3: Anpassung der Vorlagendateien
4.7. Schritt 4: Paketbau mit debuild
4.8. Schritt 3 (alternativ): Änderungen der Quellen der Originalautoren
4.8.1. Patch durch diff -u
4.8.2. Patch durch Dquilt
4.8.3. Patch durch dpkg-source --commit

Es gibt ein altes lateinisches Sprichwort: »Longum iter est per praecepta, breve et efficax per exempla« (»Der Weg mit den Regeln ist lang, mit Beispielen aber kurz und effizient«).

Hier ist ein Beispiel zur Erstellung eines einfachen Debian-Pakets aus einer einfachen C-Quelle mittels einer Makefile als Bausystem.

Nehmen wir an, der Tarball der Originalautoren heißt debhello-0.0.tar.gz.

Diese Art der Quellen soll als Nichtsystemdatei wie folgt instaliert werden:

 $ tar -xzmf debhello-0.0.tar.gz
 $ cd debhello-0.0
 $ make
 $ make install

Die Debian-Paketierung ändert diesen »make install«-Prozess in die Installation von Dateien an den Ort im Zielsystemabbild statt des normalen Ortes unterhalb von /usr/local.

Anmerkung

Beispiele zur Erstellung von Debian-Paketen aus anderen, komplizierteren Bausystemen werden in Kapitel 8, Weitere Beispiele beschrieben.

The big picture for building a single non-native Debian package from the upstream tarball debhello-0.0.tar.gz can be summarized as:

  • The maintainer obtains the upstream tarball debhello-0.0.tar.gz and untars its contents to the debhello-0.0 directory.
  • The debmake command debianizes the upstream source tree by adding template files only in the debian directory.

    • The debhello_0.0.orig.tar.gz symlink is created pointing to the debhello-0.0.tar.gz file.
    • The maintainer customizes template files.
  • The debuild command builds the binary package from the debianized source tree.

    • debhello-0.0-1.debian.tar.xz is created containing the debian directory.

Big picture of package building. 

 $ tar -xzmf debhello-0.0.tar.gz
 $ cd debhello-0.0
 $ debmake
   ... manual customization
 $ debuild
   ...

Tipp

The debuild command in this and following examples may be substituted by equivalent commands such as the pdebuild command.

Tipp

If the upstream tarball in the .tar.xz format is available, use it instead of the one in the .tar.gz and .tar.bz2 formats. The xz compression format offers the better compression than the gzip and bzip2 compressions.

Der Befehl debmake ist ein Hilfsskript für die Debian-Paketierung.

  • It always sets most of the obvious option states and values to reasonable defaults.
  • Es erstellt den Tarball der Originalautoren und die benötigten Symlinks, falls sie fehlen.
  • Es setzt die bestehenden Konfigurationsdateien im Verzeichnis debian/ nicht außer Kraft.
  • Es unterstützt die Multiarch-Pakete.
  • Es erstellt gute Vorlagendateien wie eine debian/copyright-Datei, die konform zu DEP-5 ist.

Diese Funktionalitäten ermöglichen ein einfaches und moderens Paketieren für Debian mit debmake.

Anmerkung

Der Befehl debmake ist nicht die einzige Art, ein Debian-Paket zu erstellen. Viele Pakete werden nur mit einem Texteditor paketiert und imitieren dabei die Paketierung anderer, ähnlicher Pakete.

Hier ist eine Zusammenfassung von Befehlen, die dem Befehl debuild ähnlich sind.

Anmerkung

See dpkg-buildpackage(1) for exact details.

Let’s get the upstream source.

Download debhello-0.0.tar.gz

 $ wget http://www.example.org/download/debhello-0.0.tar.gz
 ...
 $ tar -xzf debhello-0.0.tar.gz
 $ tree
/home/ned/deb_holgerw/fremdpakete/debmake-doc/on-salsa/debmake-doc/bin/L: lin...

Here, the C source hello.c is a very simple one.

hello.c

        

Here, the Makefile supports GNU Coding Standards and FHS. Notably:

  • build binaries honoring $(CPPFLAGS), $(CFLAGS), $(LDFLAGS), etc.
  • install files with $(DESTDIR) defined to the target system image
  • install files with $(prefix) defined, which can be overridden to be /usr

Makefile

        

Anmerkung

The echo of the $(CFLAGS) variable is used to verify the proper setting of the build flag in the following example.

Tipp

Falls der Befehl debmake mit der Option -T aufgerufen wird, werden in den Vorlagendateien ausführlichere Kommentare erstellt.

Die Ausagabe des Befehls debmake ist sehr ausführlich und erklärt seine Tätigkeiten wie folgt:

        

The debmake command generates all these template files based on command line options. Since no options are specified, the debmake command chooses reasonable default values for you:

  • Der Quellpaketname: debhello
  • Die Version der Originalautoren: 0.0
  • Deb Binärpaketname: debhello
  • The Debian revision: 1
  • The package type: bin (the ELF binary executable package)
  • Die Option -x: -x1 (Vorgabe für das einzelne Binärpaket)

Lassen Sie uns die erstellten Vorlagendateien anschauen.

Der Quellbaum, nach der grundlegenden Ausführung von debmake

        

The debian/rules file is the build script provided by the package maintainer. Here is its template file generated by the debmake command.

debian/rules (Vorlagendatei): 

        

This is essentially the standard debian/rules file with the dh command. (There are some commented out contents for you to customize it.)

The debian/control file provides the main meta data for the Debian package. Here is its template file generated by the debmake command.

debian/control (Vorlagendatei): 

        

Warnung

If you leave “Section: unknown” in the template debian/control file unchanged, the lintian error may cause the build to fail.

Since this is the ELF binary executable package, the debmake command sets “Architecture: any” and “Multi-Arch: foreign”. Also, it sets required substvar parameters as “Depends: ${shlibs:Depends}, ${misc:Depends}”. These are explained in Kapitel 5, Grundlagen.

Anmerkung

Please note this debian/control file uses the RFC-822 style as documented in 5.2 Source package control files — debian/control of the “Debian Policy Manual”. The use of the empty line and the leading space are significant.

The debian/copyright file provides the copyright summary data of the Debian package. Here is its template file generated by the debmake command.

debian/copyright (Vorlagendatei): 

        

Um ein geeignetes Debian-Paket zu erstellen, sind manuelle Anpassungen durch den Betreuer notwendig.

Um Dateien als Teil der Systemdateien zu installieren, sollte der Wert von $(prefix) in der Makefile von /usr/local außer Kraft gesetzt werden. Dies kann durch die nachfolgende debian/rules durch die Zieleinstellung »prefix=/usr« für override_dh_auto_install erreicht werden.

debian/rules (Betreuerversion): 

        

Exportieren der Umgebungsvariable DH_VERBOSE in der Datei debian/rules zwingt das Werkzeug debhelper dazu, einen feingranularen Baubericht zu erstellen.

Durch Exportieren von DEB_BUILD_MAINT_OPTION wie oben werden die Härtungsoptionen wie in »FUNKTIONALITÄTSBEREICHE« in dpkg-buildflags(1) beschrieben gesetzt. [8]

Durch Exportieren von DEB_CFLAGS_MAINT_APPEND wie oben wird der C-Compiler gezwungen, alle Warnungen auszugeben.

Durch Exportieren von DEB_LDFLAGS_MAINT_APPEND wie oben wird der Linker gezwungen, nur zu linken, wenn die Bibliothek tatsächlich benötigt wird. [9]

Der Befehl dh_auto_install für das Makefile-basierende Bausystem führt im wesentlichen »$(MAKE) install DESTDIR=debian/debhello« aus. Die Erstellung dieses Zieles override_dh_auto_install ändert sein Verhalten zu »$(MAKE) install DESTDIR=debian/debhello prefix=/usr«.

Hier sind die Betreuerversionen der Dateien debian/control und debian/copyright.

debian/control (Betreuerversion): 

        

debian/copyright (Betreuerversion): 

        

Es gibt eine Reihe von weiteren Vorlagendateien unter dem Verzeichnis debian/. Diese müssen auch aktualisiert werden.

Vorlagendateien unter debian/. (v=0.0): 

        

Tipp

Konfigurationsdateien, die vom Befehl dh_* aus dem Paket debhelper verwandt werden, behandeln normalerweise # als Beginn einer Kommentardatei.

You can create a non-native Debian package using the debuild command or its equivalents (see Abschnitt 4.3, „Was ist Debuild?“) in this source tree. The command output is very verbose and explains what it does as follows.

 ...

 ...

 ...

 ...

 ...

 ...

Sie können überprüfen, dass CFLAGS korrekt mit -Wall und -pedantic durch die Variable DEB_CFLAGS_MAINT_APPEND aktualisiert ist.

Wie vom Paket lintian berichtet sollte eine Handbuchseite zum Paket hinzugefügt werden, wie dies in späteren Beispielen gezeigt wird (siehe Kapitel 8, Weitere Beispiele). Lassen Sie uns jetzt weitermachen.

Lassen Sie uns die Ergebnisse anschauen.

Die durch den Befehldebuild erstellten Dateien von debhello Version 0.0

        

You see all the generated files.

  • Das debhello_0.0.orig.tar.gz ist ein Symlink auf den Tarball der Originalautoren.
  • The debhello_0.0-1.debian.tar.xz contains the maintainer generated contents.
  • The debhello_0.0-1.dsc is the meta data file for the Debian source package.
  • The debhello_0.0-1_amd64.deb is the Debian binary package.
  • The debhello-dbgsym_0.0-1_amd64.deb is the Debian debug symbol binary package. See Abschnitt 5.17.1, „Neue -dbgsym-Pakete (Stretch 9.0 und danach)“.
  • The debhello_0.0-1_amd64.build file is the build log file.
  • The debhello_0.0-1_amd64.buildinfo file is the meta data file generated by dpkg-genbuildinfo(1).
  • The debhello_0.0-1_amd64.changes is the meta data file for the Debian binary package.

The debhello_0.0-1.debian.tar.xz contains the Debian changes to the upstream source as follows.

The compressed archive contents of debhello_0.0-1.debian.tar.xz

        

The debhello_0.0-1_amd64.deb contains the binary files to be installed to the target system.

The debhello-debsym_0.0-1_amd64.deb contains the debug symbol files to be installed to the target system..

The binary package contents of all binary packages: 

        

The generated dependency list of all binary packages.

The generated dependency list of all binary packages (v=0.0): 

        

Achtung

Many more details need to be addressed before uploading the package to the Debian archive.

Anmerkung

If manual adjustments of auto-generated configuration files by the debmake command are skipped, the generated binary package may lack meaningful package description and some of the policy requirements may be missed. This sloppy package functions well under the dpkg command, and may be good enough for your local deployment.

Das obige Beispiel veränderte die Quellen der Originalautoren nicht, um ein geeignetes Debian-Paket zu erstellen.

An alternative approach as the maintainer is to change the upstream source by modifying the upstream Makefile to set the $(prefix) value to /usr.

The packaging is practically the same as the above step-by-step example except for two points in Abschnitt 4.6, „Schritt 3: Anpassung der Vorlagendateien“:

This alternative approach to Debian packaging using a series of patch files may be less robust for future upstream changes but more flexible coping with the difficult upstream source. (See Abschnitt 7.13, „3.0 source format“.)

Anmerkung

For this particular packaging case, the above Abschnitt 4.6, „Schritt 3: Anpassung der Vorlagendateien“ using the debian/rules file is the better approach. But let’s keep on with this approach as a leaning process.

Here is an example to create 000-prefix-usr.patch by the dquilt command which is a simple wrapper of the quilt program. The syntax and function of the dquilt command is the same as the quilt(1) command, except for the fact that the patch is stored in the debian/patches/ directory.

          

Here, Makefile in the upstream source tree doesn’t need to be restored to the original state. The dpkg-source command invoked by the Debian packaging procedure in Abschnitt 4.7, „Schritt 4: Paketbau mit debuild“, understands the patch application state recorded by the dquilt program in the .pc/ directory. As long as all the changes are committed by the dquilt command, the Debian source package can be built from the modified source tree.

Anmerkung

If the .pc/ directory is missing, the dpkg-source command assumes that no patch was applied. That’s why the more primitive patch generation methods like in Abschnitt 4.8.1, „Patch durch diff -u“ without generating the .pc/ directory require the upstream source tree to be restored.



[8] This is a cliché to force a read-only relocation link for the hardening and to prevent the lintian warning “W: debhello: hardening-no-relro usr/bin/hello”. This is not really needed for this example but should be harmless. The lintian tool seems to produce a false positive warning for this case which has no linked library.

[9] This is a cliché to prevent overlinking for the complex library dependency case such as Gnome programs. This is not really needed for this simple example but should be harmless.