Requirements: The requirements from la section intitulée « Packaging From Scratch » plus debhelper and dh-make
En tant qu'empaqueteur, vous créerez rarement des paquets de zéro comme nous venons de le faire dans la section précédente. Comme vous pouvez l'imaginer, plusieurs des tâches et uen grande partie de l'information dans le fichier rules sont communs aux paquets. Afin de faciliter et de rendre plus efficace la mise en paquets, vous pouvez utiliser debhelper pour vous aider dans ces tâches. Dephelper est un ensemble de scripts Perl (préfixés par dh_) qui automatisent le processus de construction de paquets. Avec ces scripts, la construction d'un paquet Debian devient passablement simple.
Dans cet exemple, nous allons à nouveau construire le paquet GNU Hello, mais cette fois, nous allons comparer notre travail avec le paquet Ubuntu hello-debhelper. À nouveau, créons un répertoire dans lequel nous allons travailler.
mkdir ~/hello-debhelper cd ~/hello-debhelper wget http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz mkdir ubuntu cd ubuntu
Ensuite, rapatrions le paquet source Ubuntu :
apt-get source hello-debhelper cd ..
Comme dans l'exemple précédent, la première chose que nous devons faire et de décompresser l'archive tar originale (amont - upstream).
tar -xzvf hello-2.1.1.tar.gz
Au lieu de copier l'archive tar amont vers hello_2.1.1.orig.tar.gz comme nous l'avons fait dans l'exemple précédent, nous allons laisser dh_make faire le travail pour nous. La seule chose à faire est de renommer le paquet source afin qu'il soit de la forme <nom_de_paquet>-<version> ou nom_de_paquet est en minuscules. Dans ce cas, déballer simplement l'archive produit un répertoire source correctement nommé et nous pouvons nous y placer :
cd hello-2.1.1
To create the initial "debianization" of the source we will use dh_make.
dh_make -e your.maintainer@address -f ../hello-2.1.1.tar.gz
dh_make will then ask you a series of questions:
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
Only run dh_make -e once. If you run it again after you do it the first time, it will not work properly. If you want to change it or made a mistake, remove the source directory and untar the upstream tarball afresh. Then you can migrate into the source directory and try again.
Running dh_make -e does two things:
Creates the
hello_2.1.1.orig.tar.gz file in the parent
directory,
Crée les fichiers de base utilisés dans debian/ et plusieurs fichiers de gabarit (template) (.ex) qui peuvent être utiles.
Le programme Hello n'est pas très compliqué, et comme nous l'avons vu dans la section intitulée « Packaging From Scratch », la mise en paquet ne demande pas beaucoup plus que les fichiers basiques. À cet effet, retirons les fichiers .ex :
cd debian rm *.ex *.EX
Pour hello, vous aurez aussi besoin des fichiers README.Debian (fichier README (en français : LISEZ-MOI) pour les choses spécifiques à Debian, pas le README du programme), dirs (utilisé par dh_installdirs pour créer les répertoires nécessaires), docs (utilisé par dh_installdocs pour installer la documentation du programme) ou info (utilisé par dh_installinfo pour installer le fichier d'information) dans le répertoire debian. Pour plus d'information sur ces fichiers, voyez la section intitulée « dh_make example files ».
À ce moment, vous ne devriez avoir que les fichiers changelog, compat, control, copyright, et rules dans le répertoire debian. Depuis la section intitulée « Packaging From Scratch », le seul nouveau fichier est compat, qui est un fichier contenant la version du debhelper (dans ce cas 4) utilisé.
Vous devrez ajuster légèrement le changelog dans ce cas pour refléter que ce paquet s'appelle hello-debhelper au lieu de juste hello (NdT : en anglais, toujours !) :
hello-debhelper (2.1.1-1) dapper; urgency=low * Initial release -- Captain Packager <packager@coolness.com> Thu, 6 Apr 2006 10:07:19 -0700
En utilisant debhelper, les seules choses à changer dans control sont le nom (remplacer hello par hello-debhelper) et ajouter debhelper (>= 4.0.0) au champ Build-Depends pour le paquet source. Le paquet Ubuntu pour hello-debhelper ressemble à :
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.
Nous pouvons copier le fichier copyright et les scripts postinst et prerm du paquet Ubuntu hello-debhelper, puisqu'ils n'ont pas changé depuis la section intitulée « Packaging From Scratch ». Nous allons aussi copier le fichier rules afin de pouvoir l'inspecter.
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.
The last file we need to look at is rules,
where the power of
debhelper scripts can be seen. The
debhelper version of
rules is somewhat smaller (54 lines as
opposed to 72 lines in the version from la section intitulée « rules »).
The debhelper version looks like:
#!/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 la section intitulée « 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
and finally check the source package for common mistakes using lintian:
cd .. lintian -i *.dsc