Chapter 4. Einfaches Beispiel

Table of Contents

4.1. Packaging tarball
4.2. Gesamtbild
4.3. Was ist Debmake?
4.4. Was ist Debuild?
4.5. Schritt 1: Holen der Quellen der Originalautoren
4.6. Schritt 2: Mit Debmake erstellte Vorlagendateien
4.7. Schritt 3: Anpassung der Vorlagendateien
4.8. Schritt 4: Paketbau mit debuild
4.9. Schritt 3 (alternativ): Änderungen der Quellen der Originalautoren
4.9.1. Patch durch diff -u
4.9.2. Patch durch Dquilt
4.9.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.

[Note] Note

Beispiele zur Erstellung von Debian-Paketen aus anderen, komplizierteren Bausystemen werden in Chapter 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
   … manuelle Anpassung
 $ debuild
   …

[Tip] Tip

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

[Tip] Tip

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.

In retrospective, I created debmake to simplify this documentation. I consider debmake to be more-or-less a demonstration session generator for tutorial purpose.

[Note] Note

Many packages are packaged using only a text editor while imitating how other similar packages are packaged and consulting how the Debian policy requires us to do. This seems to me the most popular method for the real-life packaging activity.

The debmake command isn’t the only helper script to make a Debian package. If you are interested alternative packaging helper tools, please see:

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

[Note] Note

Siehe dpkg-buildpackage(1) für die 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
.
├── debhello-0.0
│   ├── LICENSE
│   ├── Makefile
│   └── src
│       └── hello.c
└── debhello-0.0.tar.gz

2 directories, 4 files

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

hello.c

 $ cat debhello-0.0/src/hello.c
#include <stdio.h>
int
main()
{
        printf("Hello, world!\n");
        return 0;
}

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

 $ cat debhello-0.0/Makefile
prefix = /usr/local

all: src/hello

src/hello: src/hello.c
        @echo "CFLAGS=$(CFLAGS)" | \
                fold -s -w 70 | \
                sed -e 's/^/# /'
        $(CC) $(CPPFLAGS) $(CFLAGS) $(LDCFLAGS) -o $@ $^

install: src/hello
        install -D src/hello \
                $(DESTDIR)$(prefix)/bin/hello

clean:
        -rm -f src/hello

distclean: clean

uninstall:
        -rm -f $(DESTDIR)$(prefix)/bin/hello

.PHONY: all install clean distclean uninstall

[Note] Note

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

[Tip] Tip

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:

 $ cd debhello-0.0
 $ debmake
I: set parameters
I: =================================================================
I: package_dir     = /usr/lib/python3/dist-packages
I: base_path       = /usr
I: base_lib_path   = /usr/lib/debmake
I: base_share_path = /usr/share/debmake
I: =================================================================
I: sanity check of parameters
I: pkg="debhello", ver="0.0", rev="1"
I: *** start packaging in "debhello-0.0". ***
I: provide debhello_0.0.orig.tar.gz for non-native Debian package
I: pwd = "/path/to"
I: $ ln -sf debhello-0.0.tar.gz debhello_0.0.orig.tar.gz
I: pwd = "/path/to/debhello-0.0"
I: parse binary package settings:
I: binary package=debhello Type=bin / Arch=any M-A=foreign
I: analyze the source tree
I: build_type = make
I: scan source for copyright+license text and file extensions
I: 100 %, ext = c
I: check_all_licenses
I: …
I: check_all_licenses completed for 2 files.
I: bunch_all_licenses
I: format_all_licenses
I: make debian/* template files
I: single binary package
I: debmake -x "1" ...
I: creating => debian/control
I: creating => debian/copyright
I: substituting => /usr/share/debmake/extra0/changelog
I: creating => debian/changelog
I: substituting => /usr/share/debmake/extra0/rules
I: creating => debian/rules
I: substituting => /usr/share/debmake/extra1/README.Debian
I: creating => debian/README.Debian
I: substituting => /usr/share/debmake/extra1/watch
I: creating => debian/watch
I: substituting => /usr/share/debmake/extra1source/format
I: creating => debian/source/format
I: substituting => /usr/share/debmake/extra1tests/control
I: creating => debian/source/control
I: substituting => /usr/share/debmake/extra1upstream/metadata
I: creating => debian/upstream/metadata
I: substituting => /usr/share/debmake/extra1tests/control
I: creating => debian/tests/control
I: substituting => /usr/share/debmake/extra1patches/series
I: creating => debian/patches/series
I: substituting => /usr/share/debmake/extra1sourcex/local-options
I: creating => debian/source/local-options
I: substituting => /usr/share/debmake/extra1sourcex/options
I: creating => debian/source/options
I: substituting => /usr/share/debmake/extra1sourcex/patch-header
I: creating => debian/source/patch-header
I: run "debmake -x2" to get more template files
I: $ wrap-and-sort

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
  • Die 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

 $ cd ..
 $ tree
.
├── debhello-0.0
│   ├── LICENSE
│   ├── Makefile
│   ├── debian
│   │   ├── README.Debian
│   │   ├── changelog
│   │   ├── control
│   │   ├── copyright
│   │   ├── patches
│   │   │   └── series
│   │   ├── rules
│   │   ├── source
│   │   │   ├── control
│   │   │   ├── format
│   │   │   ├── local-options
│   │   │   ├── options
│   │   │   └── patch-header
│   │   ├── tests
│   │   │   └── control
│   │   ├── upstream
│   │   │   └── metadata
│   │   └── watch
│   └── src
│       └── hello.c
├── debhello-0.0.tar.gz
└── debhello_0.0.orig.tar.gz -> debhello-0.0.tar.gz

7 directories, 19 files

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): 

 $ cat debhello-0.0/debian/rules
#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
        dh $@

#override_dh_auto_install:
#       dh_auto_install -- prefix=/usr

#override_dh_install:
#       dh_install --list-missing -X.pyc -X.pyo

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): 

 $ cat debhello-0.0/debian/control
Source: debhello
Section: unknown
Priority: optional
Maintainer: "Firstname Lastname" <email.address@example.org>
Build-Depends: debhelper-compat (= 13)
Standards-Version: 4.5.1
Homepage: <insert the upstream URL, if relevant>
Rules-Requires-Root: no

Package: debhello
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: auto-generated package by debmake
 This Debian binary package was auto-generated by the
 debmake(1) command provided by the debmake package.

[Warning] Warning

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 Chapter 5, Grundlagen.

[Note] Note

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): 

 $ cat debhello-0.0/debian/copyright
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: debhello
Upstream-Contact: <preferred name and address to reach the upstream project>
Source: <url://example.com>
#
# Please double check copyright with the licensecheck(1) command.

Files:     Makefile
           src/hello.c
Copyright: __NO_COPYRIGHT_NOR_LICENSE__
License:   __NO_COPYRIGHT_NOR_LICENSE__

#----------------------------------------------------------------------------...
# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following
# license/copyright files.

#----------------------------------------------------------------------------...
# License file: LICENSE
 License:
 .
 All files in this archive are licensed under the MIT License as below.
 .
 Copyright 2015 Osamu Aoki <osamu@debian.org>
 .
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
 to deal in the Software without restriction, including without limitation
 the rights to use, copy, modify, merge, publish, distribute, sublicense,
 and/or sell copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following conditions:
 .
 The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software.
 .
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

In order to install files as a part of the system files, the $(prefix) value of /usr/local in the Makefile should be overridden to be /usr. This can be accommodated by the following the debian/rules file with the override_dh_auto_install target setting “prefix=/usr”.

debian/rules (Betreuerversion): 

 $ vim debhello-0.0/debian/rules
 … hack, hack, hack, …
 $ cat debhello-0.0/debian/rules
#!/usr/bin/make -f
export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
        dh $@

override_dh_auto_install:
        dh_auto_install -- prefix=/usr

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. [9]

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. [10]

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): 

 $ vim debhello-0.0/debian/control
  … hack, hack, hack, …
 $ cat debhello-0.0/debian/control
Source: debhello
Section: devel
Priority: optional
Maintainer: Osamu Aoki <osamu@debian.org>
Build-Depends: debhelper-compat (= 13)
Standards-Version: 4.5.1
Homepage: https://salsa.debian.org/debian/debmake-doc
Rules-Requires-Root: no

Package: debhello
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: Simple packaging example for debmake
 This Debian binary package is an example package.
 (This is an example only)

debian/copyright (Betreuerversion): 

 $ vim debhello-0.0/debian/copyright
 … hack, hack, hack, …
 $ cat debhello-0.0/debian/copyright
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: debhello
Upstream-Contact: Osamu Aoki <osamu@debian.org>
Source: https://salsa.debian.org/debian/debmake-doc

Files:     *
Copyright: 2015-2021 Osamu Aoki <osamu@debian.org>
License:   Expat
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
 to deal in the Software without restriction, including without limitation
 the rights to use, copy, modify, merge, publish, distribute, sublicense,
 and/or sell copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following conditions:
 .
 The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software.
 .
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

Vorlagendateien unter debian/. (v=0.0): 

 $ tree debhello-0.0/debian
debhello-0.0/debian
├── README.Debian
├── changelog
├── control
├── copyright
├── patches
│   └── series
├── rules
├── source
│   ├── control
│   ├── format
│   ├── local-options
│   ├── options
│   └── patch-header
├── tests
│   └── control
├── upstream
│   └── metadata
└── watch

4 directories, 14 files

[Tip] Tip

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

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

 $ cd debhello-0.0
 $ debuild
 dpkg-buildpackage -us -uc -ui -i -i
 …
 debian/rules clean
dh clean
 …
 debian/rules binary
dh binary
   dh_update_autotools_config
   dh_autoreconf
   dh_auto_configure
        install -d /path/to/debhello-0.0/debian/.debhelper/generated/_source/...
   dh_auto_build
        make -j12 "INSTALL=install --strip-program=true"
make[1]: Entering directory '/path/to/debhello-0.0'
# CFLAGS=-g -O2
# -ffile-prefix-map=/home/osamu/src/public/debmake-doc/debmake-doc/examp
 …
Now running lintian -i -I --show-overrides debhello_0.0-1_amd64.changes ...
 …
N:   Renamed from: binary-without-manpage
N:
W: debhello: readme-debian-contains-debmake-template
N:
 …

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 Chapter 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

 $ cd ..
 $ tree -FL 1
.
├── debhello-0.0/
├── debhello-0.0.tar.gz
├── debhello-dbgsym_0.0-1_amd64.deb
├── debhello_0.0-1.debian.tar.xz
├── debhello_0.0-1.dsc
├── debhello_0.0-1_amd64.build
├── debhello_0.0-1_amd64.buildinfo
├── debhello_0.0-1_amd64.changes
├── debhello_0.0-1_amd64.deb
└── debhello_0.0.orig.tar.gz -> debhello-0.0.tar.gz

1 directory, 9 files

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 Section 5.19.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

 $ tar -tzf debhello-0.0.tar.gz
debhello-0.0/
debhello-0.0/src/
debhello-0.0/src/hello.c
debhello-0.0/LICENSE
debhello-0.0/Makefile
 $ tar --xz -tf debhello_0.0-1.debian.tar.xz
debian/
debian/README.Debian
debian/changelog
debian/control
debian/copyright
debian/patches/
debian/patches/series
debian/rules
debian/source/
debian/source/control
debian/source/format
debian/source/options
debian/source/patch-header
debian/tests/
debian/tests/control
debian/upstream/
debian/upstream/metadata
debian/watch

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: 

 $ dpkg -c debhello-dbgsym_0.0-1_amd64.deb
drwxr-xr-x root/root …  ./
drwxr-xr-x root/root …  ./usr/
drwxr-xr-x root/root …  ./usr/lib/
drwxr-xr-x root/root …  ./usr/lib/debug/
drwxr-xr-x root/root …  ./usr/lib/debug/.build-id/
drwxr-xr-x root/root …  ./usr/lib/debug/.build-id/be/
-rw-r--r-- root/root …  ./usr/lib/debug/.build-id/be/11292eded3fc22396a0b62...
drwxr-xr-x root/root …  ./usr/share/
drwxr-xr-x root/root …  ./usr/share/doc/
lrwxrwxrwx root/root …  ./usr/share/doc/debhello-dbgsym -> debhello
 $ dpkg -c debhello_0.0-1_amd64.deb
drwxr-xr-x root/root …  ./
drwxr-xr-x root/root …  ./usr/
drwxr-xr-x root/root …  ./usr/bin/
-rwxr-xr-x root/root …  ./usr/bin/hello
drwxr-xr-x root/root …  ./usr/share/
drwxr-xr-x root/root …  ./usr/share/doc/
drwxr-xr-x root/root …  ./usr/share/doc/debhello/
-rw-r--r-- root/root …  ./usr/share/doc/debhello/README.Debian
-rw-r--r-- root/root …  ./usr/share/doc/debhello/changelog.Debian.gz
-rw-r--r-- root/root …  ./usr/share/doc/debhello/copyright

The generated dependency list of all binary packages.

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

 $ dpkg -f debhello-dbgsym_0.0-1_amd64.deb pre-depends \
            depends recommends conflicts breaks
Depends: debhello (= 0.0-1)
 $ dpkg -f debhello_0.0-1_amd64.deb pre-depends \
            depends recommends conflicts breaks
Depends: libc6 (>= 2.2.5)

[Caution] Caution

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

[Note] Note

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 Section 4.7, “Schritt 3: Anpassung der Vorlagendateien”:

  • Store the maintainer modifications to the upstream source as the corresponding patch files in the debian/patches/ directory and list their filenames in the debian/patches/series file as indicated in Section 5.10, “debian/patches/*”. There are several ways to generate patch files. A few examples are given in these sections:

  • The maintainer modification to the debian/rules file doesn’t have the override_dh_auto_install target as follows:

    debian/rules (alternative maintainer version): 

     $ cd debhello-0.0
     $ vim debian/rules
     … hack, hack, hack, …
     $ cat debian/rules
    #!/usr/bin/make -f
    export DH_VERBOSE = 1
    export DEB_BUILD_MAINT_OPTIONS = hardening=+all
    export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
    export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
    
    %:
            dh $@

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 Section 7.13, “3.0 source format”.)

[Note] Note

For this particular packaging case, the above Section 4.7, “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 diff command.

 $ cp -a debhello-0.0 debhello-0.0.orig
 $ vim debhello-0.0/Makefile
 … hack, hack, hack, …
 $ diff -Nru debhello-0.0.orig debhello-0.0 >000-prefix-usr.patch
 $ cat 000-prefix-usr.patch
diff -Nru debhello-0.0.orig/Makefile debhello-0.0/Makefile
--- debhello-0.0.orig/Makefile  2021-07-02 16:26:38.734722687 +0900
+++ debhello-0.0/Makefile       2021-07-02 16:26:38.802723496 +0900
@@ -1,4 +1,4 @@
-prefix = /usr/local
+prefix = /usr

 all: src/hello

 $ rm -rf debhello-0.0
 $ mv -f debhello-0.0.orig debhello-0.0

Please note that the upstream source tree is restored to the original state and the patch file is available as 000-prefix-usr.patch.

This 000-prefix-usr.patch is edited to be DEP-3 conformant and moved to the right location as below.

 $ cd debhello-0.0
 $ echo '000-prefix-usr.patch' >debian/patches/series
 $ vim ../000-prefix-usr.patch
 … hack, hack, hack, …
 $ mv -f ../000-prefix-usr.patch debian/patches/000-prefix-usr.patch
 $ cat debian/patches/000-prefix-usr.patch
From: Osamu Aoki <osamu@debian.org>
Description: set prefix=/usr patch
diff -Nru debhello-0.0.orig/Makefile debhello-0.0/Makefile
--- debhello-0.0.orig/Makefile
+++ debhello-0.0/Makefile
@@ -1,4 +1,4 @@
-prefix = /usr/local
+prefix = /usr

 all: src/hello

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.

 $ cd debhello-0.0
 $ dquilt new 000-prefix-usr.patch
Patch debian/patches/000-prefix-usr.patch is now on top
 $ dquilt add Makefile
File Makefile added to patch debian/patches/000-prefix-usr.patch
 … hack, hack, hack, …
 $ head -1 Makefile
prefix = /usr
 $ dquilt refresh
Refreshed patch debian/patches/000-prefix-usr.patch
 $ dquilt header -e --dep3
 … den DEP-3-Patch-Header mit einem Editor bearbeiten
 $ tree -a
.
├── .pc
│   ├── .quilt_patches
│   ├── .quilt_series
│   ├── .version
│   ├── 000-prefix-usr.patch
│   │   ├── .timestamp
│   │   └── Makefile
│   └── applied-patches
├── LICENSE
├── Makefile
├── debian
│   ├── README.Debian
│   ├── changelog
│   ├── control
│   ├── copyright
│   ├── patches
│   │   ├── 000-prefix-usr.patch
│   │   └── series
│   ├── rules
│   ├── source
│   │   ├── control
│   │   ├── format
│   │   ├── local-options
│   │   ├── options
│   │   └── patch-header
│   ├── tests
│   │   └── control
│   ├── upstream
│   │   └── metadata
│   └── watch
└── src
    └── hello.c

8 directories, 24 files
 $ cat debian/patches/series
000-prefix-usr.patch
 $ cat debian/patches/000-prefix-usr.patch
Description: set prefix=/usr patch
Author: Osamu Aoki <osamu@debian.org>
Index: debhello-0.0/Makefile
===================================================================
--- debhello-0.0.orig/Makefile
+++ debhello-0.0/Makefile
@@ -1,4 +1,4 @@
-prefix = /usr/local
+prefix = /usr

 all: src/hello

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 Section 4.8, “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.

[Note] Note

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 Section 4.9.1, “Patch durch diff -u” without generating the .pc/ directory require the upstream source tree to be restored.

Here is an example to create 000-prefix-usr.patch by the “dpkg-source --commit” command.

Bearbeiten Sie die Quellen der Originalautoren.

 $ cd debhello-0.0
 $ vim Makefile
 … hack, hack, hack, …
 $ head -n1 Makefile
prefix = /usr

Let’s commit it.

 $ dpkg-source --commit . 000-prefix-usr.patch
… Editor, um die DEP-3-Patch-Kopfzeilen zu bearbeiten
…

Schauen Sie sich das Ergebnis an.

 $ cat debian/patches/series
000-prefix-usr.patch
 $ cat debian/patches/000-prefix-usr.patch
Description: set prefix=/usr patch
Author: Osamu Aoki <osamu@debian.org>
Index: debhello-0.0/Makefile

--- debhello-0.0.orig/Makefile
+++ debhello-0.0/Makefile
@@ -1,4 +1,4 @@
-prefix = /usr/local
+prefix = /usr

 all: src/hello

 $ tree -a
.
├── .pc
│   ├── .quilt_patches
│   ├── .quilt_series
│   ├── .version
│   ├── 000-prefix-usr.patch
│   │   ├── .timestamp
│   │   └── Makefile
│   └── applied-patches
├── LICENSE
├── Makefile
├── debian
│   ├── README.Debian
│   ├── changelog
│   ├── control
│   ├── copyright
│   ├── patches
│   │   ├── 000-prefix-usr.patch
│   │   └── series
│   ├── rules
│   ├── source
│   │   ├── control
│   │   ├── format
│   │   ├── local-options
│   │   ├── options
│   │   └── patch-header
│   ├── tests
│   │   └── control
│   ├── upstream
│   │   └── metadata
│   └── watch
└── src
    └── hello.c

8 directories, 24 files

Hier erledigt der Befehl dpkg-source genau das gleiche wie dies die Sequenz der dquilt-Befehle in Section 4.9.2, “Patch durch Dquilt” tat.



[9] 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.

[10] 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.