Requirements: The requirements from „Packaging From Scratch“ plus debhelper and dh-make
As a packager, you will rarely create packages from scratch as
we have done in the previous section. As you can imagine, many of
the tasks and information in the rules
file,
for instance, are common to packages. To make packaging
easier and more efficient, you can use
debhelper to help with these tasks.
Debhelper is a set of Perl scripts (prefixed with
dh_) that automate the process of
package-building. With these scripts, building a Debian package
becomes quite simple.
In this example, we will again build the GNU Hello package, but this time we will be comparing our work to the Ubuntu hello-debhelper package. Again, create a directory where you will be working:
mkdir ~/hello-debhelper cd ~/hello-debhelper wget http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz mkdir ubuntu cd ubuntu
Then, get the Ubuntu source package:
apt-get source hello-debhelper cd ..
Like the previous example, the first thing we need to do is unpack the original (upstream) tarball.
tar -xzvf hello-2.1.1.tar.gz
Instead of copying the upstream tarball to
hello_2.1.1.orig.tar.gz
as we did in the
previous example, we will let dh_make
do the work for us. The only thing you have to do is rename the
source folder so it is in the form of
<packagename>-<version> where
packagename is lowercase. In this case, just untarring the
tarball produces a correctly named source directory so we can move
into it:
cd hello-2.1.1
Um die anfängliche "Debian-isierung" des Quellcodes zu realisieren werden wir dh_make einsetzten.
dh_make -e your.maintainer@address -f ../hello-2.1.1.tar.gz
dh_make wird Ihnen dann einige Fragen stellen:
Type of package: single binary, multiple binary, library, kernel module or cdbs?
[s/m/l/k/b] s
Maintainer name : Captain Packager
Email-Address : packager@coolness.com
Date : Thu, 6 Apr 2006 10:07:19 -0700
Package Name : hello
Version : 2.1.1
License : blank
Type of Package : Single
Hit <enter> to confirm: Enter
Führen Sie nur einmal dh_make -e aus. Wenn Sie es nach dem ersten Ausführen nochmal aufrufen, wird es nicht richtig arbeiten. Um eine Änderung vorzunehmen oder ein Fehler auszumerzen, entfernen Sie das Quellverzeichnis und entpacken Sie den Upstream Tarball erneut. Dann können Sie in das Quellverzeichnis übergehen und es nochmal probieren.
Running dh_make -e does two things:
Es erstellt die hello_2.1.1.orig.tar.gz
Datei in dem Stammverzeichnis,
erstellt die essentiellen Dateien die für debian/
gebraucht werden und viele Vorlagen (.ex), die Sie eventuell gebrauchen könnten.
The Hello program is not very
complicated, and as we have seen in „Packaging From Scratch“, packaging it does not require much
more than the basic files. Therefore, let us remove the
.ex
files:
cd debian rm *.ex *.EX
For hello, you will also not need
README.Debian
(README file for specific
Debian issues, not the program's README), dirs
(used by dh_installdirs to create
needed directories), docs
(used by
dh_installdocs to install program
documentation), or info
(used by
dh_installinfo to install the info
file) files into the debian
directory. For more
information on these files, see „dh_make example files“.
At this point, you should have only
changelog
, compat
,
control
, copyright
, and
rules
files in the
debian
directory. From „Packaging From Scratch“, the only file that is new is
compat
, which is a file that contains the
debhelper version (in this case 4) that
is used.
You will need to adjust the
changelog
slightly in this case to reflect
that this package is named
hello-debhelper rather than just
hello:
hello-debhelper (2.1.1-1) dapper; urgency=low * Initial release -- Captain Packager <packager@coolness.com> Thu, 6 Apr 2006 10:07:19 -0700
By using debhelper, the only
things we need to change in control
are the
name (substituting hello for
hello-debhelper) and adding
debhelper (>= 4.0.0) to the
Build-Depends field for the source
package. The Ubuntu package for
hello-debhelper looks like:
Source: hello-debhelper Section: devel Priority: extra Maintainer: Capitan Packager <packager@coolness.com> Standards-Version: 3.6.1 Build-Depends: debhelper (>= 4) Package: hello-debhelper Architecture: any Depends: ${shlibs:Depends} Conflicts: hello Provides: hello Replaces: hello Description: The classic greeting, and a good example The GNU hello program produces a familiar, friendly greeting. It allows non-programmers to use a classic computer science tool which would otherwise be unavailable to them. . Seriously, though: this is an example of how to do a Debian package. It is the Debian version of the GNU Project's `hello world' program (which is itself an example for the GNU Project). . This is the same as the hello package, except it uses debhelper to make the deb. Please see debhelper as to what it is.
We can copy the copyright
file and the
postinst
and prerm
scripts from the Ubuntu
hello-debhelper package, as they have
not changed since „Packaging From Scratch“. We will also
copy the rules
file so we can inspect
it.
cp ../../ubuntu/hello-debhelper-2.1.1/debian/copyright . cp ../../ubuntu/hello-debhelper-2.1.1/debian/postinst . cp ../../ubuntu/hello-debhelper-2.1.1/debian/prerm . cp ../../ubuntu/hello-debhelper-2.1.1/debian/rules.
Die letzte Datei die wir uns anschauen ist die rules
Datei, an der man die Macht von debhelper Skripten sehen kann. Die debhelper Version von rules
ist ein bisschen kleiner (54 Zeilen statt 72 Zeilen in der Version von „rules“).
Die debhelper Version sieht folgendermaßen aus:
#!/usr/bin/make -f package = hello-debhelper CC = gcc CFLAGS = -g -Wall ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) CFLAGS += -O2 endif #export DH_VERBOSE=1 clean: dh_testdir dh_clean rm -f build -$(MAKE) -i distclean install: build dh_clean dh_installdirs $(MAKE) prefix=$(CURDIR)/debian/$(package)/usr \ mandir=$(CURDIR)/debian/$(package)/usr/share/man \ infodir=$(CURDIR)/debian/$(package)/usr/share/info \ install build: ./configure --prefix=/usr $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" touch build binary-indep: install # There are no architecture-independent files to be uploaded # generated by this package. If there were any they would be # made here. binary-arch: install dh_testdir -a dh_testroot -a dh_installdocs -a NEWS dh_installchangelogs -a ChangeLog dh_strip -a dh_compress -a dh_fixperms -a dh_installdeb -a dh_shlibdeps -a dh_gencontrol -a dh_md5sums -a dh_builddeb -a binary: binary-indep binary-arch .PHONY: binary binary-arch binary-indep clean checkroot
Notice that tasks like testing if you are in the right directory
(dh_testdir), making sure you are
building the package with root privileges
(dh_testroot), installing documentation
(dh_installdocs and
dh_installchangelogs), and cleaning up
after the build (dh_clean) are handled
automatically. Many packages much more complicated than
hello have rules
files no bigger because the debhelper
scripts handle most of the tasks. For a complete list of
debhelper scripts, please see „List of debhelper scripts“. They are also well documented
in their respective man pages. It is a
useful exercise to read the man page (they are well written and
not lengthy) for each helper script used in the above
rules
file.
Now that we have gone through the files in the
debian
directory for
hello-debhelper, we can build the
source (and binary) packages. First, let us move back into the
source directory:
cd ..
Now we build the source package using debuild, a wrapper script for dpkg-buildpackage:
debuild -S
the binary package, using pbuilder:
sudo pbuilder build ../*.dsc
und zu guter Letzt: Prüfen Sie mit lintian das Quellpaket auf häufige Fehler:
cd .. lintian -i *.dsc