2 \qauthor{\LARGE{Jeremiah Foster}}
4\chapter{Creating Debian packages from CPAN}
7CPAN is a well-known and useful archive of Perl modules, a pearl in the Perl
8world. While it serves many Perl developers and users, it cannot by its very
9nature cater for further distribution because it does not know what form that
10distribution has to take. In other words, how is cpan supposed to know if it
11needs to morph into a specif\hbox{}ic format to allow a module to be installed on a
12specif\hbox{}ic platform? It cannot and should not, it should provide instead a stable
13API and a distributed database allowing for easy packaging ``downstream'', which
14is what it does. One can install from source if one prefers, or with the cpan
15and cpanp tools, but sometimes you need or want a more complete and f\hbox{}lexible
16system for installing software.
18As we move downstream, we get closer to the user and the user's system. Hic sunt
19dracones, you need to be pretty careful about how and what you install lest you
20create instability and bugs. Cpan tries to handle installation elegantly by
21installing dependencies with whatever module you are installing. This is a
22``Good Thing\texttrademark'', it helps the end-user immeasurably and helps to
23avoid ``dependency hell''; a painful state which describes the situation of
24having some of your needed software installed, but not all of it.
26Since a cpan module is agnostic to its f\hbox{}inal destination and tries to be as
27cross-platform as possible, it will not know about the specif\hbox{}ic peculiarities of
28the operating system upon which it is to reside. In fact, one might argue a good
29deal of cpants is directed at this problem, determining the quirks of the OS.
30Workarounds include the inclusion of multiple operating-system-specif\hbox{}ic tools
33A better solution might be ``package management'' which allows for a cpan module
34to be wrapped in a way that allows for simpler installation. This is of course
35operating system specif\hbox{}ic and rightly so, the OS needs to determine how to
36install, where to install, and what. So cpan can just do its thing while the OS
37communicates directly with cpan, gets the required module(s), any Perl
38dependencies, and does the installation work. The OS then checks to see if there
39are operating system required dependencies above and beyond the Perl
40dependencies, satisf\hbox{}ies those dependencies, resulting in a single call to the
41package manager to install software without having to search the internet for
42some arbitrary .so f\hbox{}ile.
44This article aims to explain this packaging process for Debian and Debian
45derived operating systems such as Ubuntu, allowing for Perl modules to be
46installed as debs and even submitted to Debian itself. The Debian system has
47many users, receives security notif\hbox{}ications, is known for its stability, and
48gets regular updates. These are things your Perl modules will automatically get
49as well when you submit them to Debian.
51There is a dedicated group of Debian hackers, both ``Debian Developers'' and
52non-developers, who maintain Perl modules in Debian. I am one of those who works
53on the Debian-Perl team\cite{debs_cpan-debian_perl_team} and would like to
54describe the development of debs from cpan, including some of its gory details,
55so that others can be familiar with ``best practices'' of packaging software for
58Let us begin with a tool called dh-make-perl, shall we? Dh-make-perl (the dh
59stands for Debian helper) is a wrapper around the cpan tool, plus a whole lot
60more. We call it the same way as we would call cpan, with a module name. It then
61goes to cpan for the source of our deb because the goal of a deb is to have the
62source code separate and pristine. Debian makes no changes to the upstream
63source for packaging. Occasionally someone in Debian might patch the source to
64f\hbox{}ix a bug, but in Debian-Perl we try to use patch to patch things and always try
65to pass our patch upstream at least into RT, Perl's bug tracker.
67Choosing something to package is actually quite important. I will choose
68Test::F\hbox{}ile because I f\hbox{}ind it useful and have some familiarity with it - two
69things one needs to generate the interest and motivation when there are bug
70reports or new features. Packaging is actually considerable work over time, a
71stale package is both a potential security risk and quickly forgotten.
73Now we use our f\hbox{}irst tool, the powerful dh-make-perl. I will show the call to
74dh-make-perl and then go through it a bit since I am going to pass a lot of
75arguments just to show some features.
78 basicstyle=\footnotesize\ttfamily,
86 keywordstyle=\color{red},
92 framexrightmargin=9pt,
93 %backgroundcolor=\color{lightgray},
94 showstringspaces=false
96\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dh-make-perl,caption=dh-make-perl command]{}
97dh-make-perl --cpan Test::File --desc "Test file attributes with perl." --arch all --version 1.25 -e jeremiah@jeremiahfoster.com --dh 7 --requiredeps --build
100We call dh-make-perl with a bunch of parameters. This of course is not
101necessary, you can make your call much smaller, but I want to show some of these
102parameters because they make life a little easier and you may want to use them.
103Of course the canonical source of dh-make-perl parameters and functions is in
104the man page for dh-make-perl, this is good to check on occasion since it has
105been getting updated recently\cite{debs_cpan-git_dh_make_perl}.
107The f\hbox{}irst parameter, or really argument to dh-make-perl, is the {-}{-}cpan f\hbox{}lag
108which tells dh-make-perl to go and get the module from cpan as opposed to
109f\hbox{}inding it locally. From the man page: ``If neither {-}{-}cpan nor a directory
110is given as argument, dh-make-perl tries to create a Perl package from the data
111in .'' i.e. the current directory. So if you have a module you want to install
112locally or for some reason do not want to push up to Debian, you can create
113local debs for your own local machines or mirror, no need to push them
114downstream as it were.
116Next we give the name of our module in the same way we would if we were using
117cpan, i.e. Foo::Bar. The {-}{-}desc switch tells dh-make-perl what to use for
118Debian's short description and the {-}{-}arch f\hbox{}lag is for the architecture. Here
119we are using all because perl works on all the architectures that Debian
120of\hbox{}f\hbox{}icially (and unof\hbox{}f\hbox{}icially) supports.
122Shockingly enough the {-}{-}version f\hbox{}lag provides a way to inform dh-make-perl
123about the version of the package we are packaging, so this is the current
124version of Test::F\hbox{}ile; -e is the email address f\hbox{}lag, it wants an email address
125after it; {-}{-}dh is a call to debhelper itself and after {-}{-}dh you have to
126specify the version of debhelper you want to use. This is a little tricky
127because dif\hbox{}ferent versions of debhelper create dif\hbox{}ferent artefacts, specif\hbox{}ically
128dif\hbox{}ferent debian/rules f\hbox{}iles. So you want most likely to use version 7 for
129debhelper. To paraphrase the dh-make-perl man page, {-}{-}dh will set desired
130the debhelper version. If ``ver'' is 7, the generated debian/rules f\hbox{}ile is
131minimalist, using the auto-mode of debhelper. This minimalist version is what
132you want, unless you are going to package an XS module or need to do some crazy
133stuf\hbox{}f at build time.
135Fortunately we do not have to mess about with our debian/rules f\hbox{}ile, so I am
136going to continue discussing the rest of the arguments to dh-make-perl, but I
137want to say that there is a great deal to discuss regarding debian/rules and you
138would do well to consider reading about it in the Debian developers'
139documentation in places like the New Maintainer's
140Guide\cite{debs_cpan-new_maint_guide-rules}. If you are reading this in front of
141a Debian command line, you can simply do an ``aptitude install maint-guide'' to
142get the documentation.
144The {-}{-}requiredeps f\hbox{}lag tells dh-make-perl to require Perl dependencies, that
145is to say, if we do not f\hbox{}ind all the modules needed to build, we should fail to
146build our deb. This is really good because it makes your deb package more
147portable and all the Perl module dependencies will get installed when you
148install your package on another machine, very convenient. For this call to work
149you need to have apt-f\hbox{}ile installed on the machine on which you are building the
150package. Apt-f\hbox{}ile is an excellent tool, written in Perl (of course!). It allows
151you to search for f\hbox{}iles in Debian packages, even packages that are not installed
152on your system. This means that apt-f\hbox{}ile is really the canonical tool to f\hbox{}ind
153things in Debian or Ubuntu packages. A quick example: say we wanted to install
154libtest-more-perl and we called aptitude to install it thusly, ``aptitude
155install libtest-more-perl''. Aptitude says:
157\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:apt-install,caption=aptitude install libtest-more-perl output]{}
158E: Unable to locate package libtest-more-perl
161But we are certain that this fundamental perl module is in Debian! Haven't we
162seen Test::More output in fact? Indeed we have, but this module does not exist
163on its own. Debian has included it with the package perl-modules because it is
164such a fundamental tool, and so much else in Debian requires it. So looking for
165it with ``dpkg -L libtest-more-perl'' will produce these rather unhelpful
168\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-search,caption=dpkg -L libtest-more-perl output]{}
169Package ``libtest-more-perl'' is not installed.
172But in fact, when we search with ``apt-f\hbox{}ile search Test/More.pm'' (which is the
173format we need to specify since we are looking at the f\hbox{}ile system) we will f\hbox{}ind
174that apt-f\hbox{}ile f\hbox{}inds it for us:
176\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:apt-file,caption=apt-file search Test/More.pm output]{}
177perl-modules: /usr/share/perl/5.10.0/Test/More.pm
180This output tells us that the f\hbox{}ile Test/More.pm is under /usr/share/perl/5.10.0
181and it is in the Debian package perl-modules. This is a handy and reliable way
182to f\hbox{}ind if the Perl module you are looking for is already packaged in Debian.
183All of these commands were issued on a Debian testing system.
185F\hbox{}inally we pass {-}{-}build which ``builds only a binary package (by calling
186`fakeroot debian/rules binary') and does not sign the package. It is meant for a
187quick local install of a package, not for creating a package ready for
188submission to the Debian archive.'' So says the man page for dh-make-perl. I
189like to build the package with dh-make-perl because then certain build problems
190come to the fore sooner. It is not a requirement to build the package with
193Once we have run dh-make-perl, we watch all sorts of interesting output f\hbox{}ly by,
194like output from cpan, the test suite of our module, etc. The debhelper build
195process takes over after cpan has worked its magic and we get a f\hbox{}inished two
196f\hbox{}iles and a directory when we are done. They are:
198\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dh-make-perl-output,caption=dh-make-perl output]{}
199File: libtest-file-perl_1.25_all.deb
200File: libtest-file-perl_1.25.orig.tar.gz
206\section{The anatomy of a package}
207\label{s:debs_cpan:anatomy}
209You would be tempted to say ``Well I have built my deb, I'm done!'' Doing a dpkg
210{-}{-}contents libtest-f\hbox{}ile-perl\_1.25\_all.deb ought to show this output on our new
213\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-contents,caption=dpkg {-}{-}contents libtest-file-perl output]{}
214drwxr-xr-x root/root 0 2009-02-09 15:39 ./
215drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/
216drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/
217drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/man/
218drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/man/man3/
219-rw-r--r-- root/root 4142 2009-02-09 15:39 ./usr/share/man/man3/Test::File.3.gz
220drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/perl5/
221drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/perl5/Test/
222-rw-r--r-- root/root 27027 2008-06-10 19:59 ./usr/share/perl5/Test/File.pm
223drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/doc/
224drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/
225-rw-r--r-- root/root 69 2007-02-09 02:30 ./usr/share/doc/libtest-file-perl/README
226-rw-r--r-- root/root 1476 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/copyright
227drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/examples/
228-rw-r--r-- root/root 69 2007-02-09 02:30 ./usr/share/doc/libtest-file-perl/examples/README
229-rw-r--r-- root/root 164 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/changelog.gz
230drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/
231drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/
232drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/auto/
233drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/auto/Test/
234drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/auto/Test/File/
235-rw-r--r-- root/root 195 2009-02-09 15:39 ./usr/lib/perl5/auto/Test/File/.packlist
236drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl/
237drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl/5.10/
238-rw-r--r-- root/root 214 2009-02-09 15:39 ./usr/lib/perl/5.10/perllocal.pod
241But in fact we are not done, we need to build the deb with dpkg-buildpackage and
242we need to modify some of the f\hbox{}iles in the Debian directory. F\hbox{}irst we will start
243by modifying the f\hbox{}iles in the Debian directory to make sure we have a proper
244package. The f\hbox{}irst thing we need to do is to change the name of our directory.
245Debian has a requirement that says the package name has to be lowercase which
246means that our directory has to be lower case. So we move Test-F\hbox{}ile to
247libtest-f\hbox{}ile-perl-1.25. This format is the standard format for Debian Perl
248packages. While one might say it is not the most beautiful format, it has its
249strengths. Those strengths are that the format informs the user it is a library
250package, part of a larger system which might require dependencies. It has the
251suf\hbox{}f\hbox{}ix -perl which indicates that it is a Perl library. There are a few modules
252in Debian which are not labelled this way, and there is no absolute law saying
253you have to call your module this way, but if you do not you are in fact doing
254the user a grave disservice, because anyone who is used to Debian or Debian
255derivatives will search for a module as libfoo-bar-perl and they will not f\hbox{}ind
256your module if it is not so labelled.
258So once we have moved Test-F\hbox{}ile-1.25 to libtest-f\hbox{}ile-perl-1.25 we will change
259into that directory and take a look around. We f\hbox{}ind that it is just like the
260untarred module from CPAN only with the addition of a Debian directory. We will
261take a closer look at the Debian directory now which is at the heart of
262packaging. According to the New Maintainer's
263guide\cite{debs_cpan-new_maint_guide} ``The most important of them are
264`control', `changelog', `copyright' and `rules', which are required for all
265packages.'' Let us start by taking a look at the control f\hbox{}ile:
268 basicstyle=\footnotesize\ttfamily,
269 commentstyle=\textit,
276 keywordstyle=\color{red},
281 framexleftmargin=9pt,
282 framexrightmargin=9pt,
283 %backgroundcolor=\color{lightgray},
284 showstringspaces=false
287\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:control-file,caption=control]{}
288Source: libtest-file-perl
291Build-Depends: debhelper (>= 7)
292Build-Depends-Indep: perl (>= 5.6.0-12), libtest-manifest-perl (>= 1.14)
293Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
294Uploaders: Jeremiah C. Foster <jeremiah@jeremiahfoster.com>
295Standards-Version: 3.8.0
296Homepage: http://search.cpan.org/dist/Test-File/
297Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libtest-file-perl/
298Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libtest-file-perl/
300Package: libtest-file-perl
302Depends: ${perl:Depends}, ${misc:Depends}, libtest-manifest-perl (>= 1.14)
303Description: Test file attributes with Perl.
304 Test::Files provides a collection of test utilities for file attributes.
306 Some file attributes depend on the owner of the process testing the file in
307 the same way the file test operators do. For instance, root (or super-user or
308 Administrator) may always be able to read files no matter the permissions.
310 Some attributes don't make sense outside of Unix, either, so some tests
311 automatically skip if they think they won't work on the platform. If you have
312 a way to make these functions work on Windows, for instance, please send me a
315 This description was "automagically" extracted from the module by dh-make-perl.
318I will move quickly through the f\hbox{}irst lines of the control f\hbox{}ile but I would like
319to point out lines 4 and 5 where Build-Depends and Build-Depends-Indep are
320def\hbox{}ined. This is where the magic at the core of aptitude lies, and why the apt
321system is so powerful. Here we def\hbox{}ine the relationships between packages in the
322operating system and within Perl which will be satisf\hbox{}ied at build time. These
323dependencies were calculated by dh-make-perl but there are other mechanisms to
324do this as well and sometimes we will even need to do this by hand. Looking in
325the source directory for the package and even the META.yml and Makef\hbox{}ile.PL can
326reveal dependencies that might otherwise be missed. Usually dh-make-perl gets it
327right however and this is not necessary.
329In our Build-Depends line we are saying we depend on debhelper and we will not
330be able to build our package unless this dependency is satisf\hbox{}ied, it is an
331absolute dependency. The apt system will check automatically for dependencies on
332your dependencies, so you only specify the dependencies you need for your
333package, you do not have to rummage around to f\hbox{}ind out what they depend on.
334Build-Depends is only for dependencies required to build a binary package on
335your architecture, it is not a complete selection of build-time relationships.
336In our package, we also need Build-Depends-Indep which def\hbox{}ines other packages
337that our package will need to run, not just to build.
339This is fairly esoteric stuf\hbox{}f, and Perl largely abstracts the ``building'' of
340binaries away from the Perl programmer in the interest of simplicity and ease of
341use. You can dig into this stuf\hbox{}f if you want, there is much more to learn about
342building Perl both on the Perl side and on the Debian side, but since it is a
343rather large subject area I am going to gloss over the really hairy details and
344refer you to the Debian policy\cite{debs_cpan-debian_policy} and your own Google
345prowess to get more info than that I have presented here.
347Most of the other stuf\hbox{}f in the debian/control f\hbox{}ile is pretty self-explanatory;
348resources for the source code, who was responsible for the package uploading,
349etc. I would like to direct you to the last line where we see some packaging
350boilerplate which ought to be removed, i.e. line 28.
352If we now turn our attention to debian/copyright we can see the power of Free
353Software and copyright. The Debian Free Software Guidelines require that a
354copyright be assigned so that a licence can be enforced. Perl is under the
355Artistic licence, a licence that has won important legal victories in the United
356States, and also under the GPL. This dual licensing is ef\hbox{}fective but only when
357there is a copyright specif\hbox{}ied and many Perl hackers forget to do this. I would
358like to encourage you to document your copyright, even if you received the
359copyright by default when you authored new code, this makes it easier to package
360your software. Here is what our copyright f\hbox{}ile looks like:
362\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:copyright-file,caption=copyright]{}
364 http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=196
365Upstream-Maintainer: brian d foy <bdfoy@cpan.org>
366Upstream-Source: http://search.cpan.org/dist/Test-File/
367Upstream-Name: Test-File
368Disclaimer: This copyright info was automatically extracted
369 from the Perl module. It may not be accurate, so you better
370 check the module sources in order to ensure the module for its
371 inclusion in Debian or for general legal information. Please,
372 if licensing information is incorrectly generated, file a bug
376Copyright: brian d foy <bdfoy@cpan.org>
378License: Artistic | GPL-1+
381Copyright: 2009, Jeremiah C. Foster <jeremiah@jeremiahfoster.com>
382Licence: Artistic | GPL-1+
385 This program is free software; you can redistribute it and/or modify
386 it under the terms of the Artistic Licence, which comes with Perl.
387 On Debian GNU/Linux systems, the complete text of the Artistic Licence
388 can be found in `/usr/share/common-licences/Artistic'
391 This program is free software; you can redistribute it and/or modify
392 it under the terms of the GNU General Public Licence as published by
393 the Free Software Foundation; either version 1, or (at your option)
395 On Debian GNU/Linux systems, the complete text of the GNU General
396 Public Licence can be found in `/usr/share/common-licences/GPL'
399This f\hbox{}ile is pretty straight-forward. We will remove the boilerplate from lines
4006 through 11 and then f\hbox{}ill in the exact date of the copyright for the software,
401in this case we'll have to go to cpan and f\hbox{}ind out that it is 2008, but after
402that we are done with the copyright f\hbox{}ile.
404The compat and watch f\hbox{}iles play minor roles in our package building drama. The
405watch f\hbox{}ile is a tool to check to see if there have been any new releases, it
406gets used by a tool called uscan which allows one to update a new cpan module
407into an existing Debian package quickly. The compat f\hbox{}ile is merely a
408``compatibility'' number for some of the other Debian tools, I will leave that
414\section{Building the package with dpkg-buildpackage}
415\label{s:debs_cpan:building}
417Now it is time to look at the main build tool for building Perl debs,
418dpkg-buildpackage. There are plenty of build tools in Debian and there seems to
419be a new one every month. For example there is now one called git-buildpackage
420and for all I know it may be great. I like dpkg-buildpackage so that is what I
421am going to tell you about.
423As with every build tool there are ten thousand options, but I am just going to
424describe the juicy parts. I call dpkg-buildpackage like this:
427 basicstyle=\footnotesize\ttfamily,
428 commentstyle=\textit,
435 keywordstyle=\color{red},
440 framexleftmargin=9pt,
441 framexrightmargin=9pt,
442 %backgroundcolor=\color{lightgray},
443 showstringspaces=false
445\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-buildpackage,caption=dpkg-buildpackage command]{}
446dpkg-buildpackage -rfakeroot -D -kjeremiah@jeremiahfoster.com
449What we have right after the call is the f\hbox{}lag -r with the word fakeroot right
450after it, that is the command used to gain root. The -D is for checking
451conf\hbox{}licts and dependencies which I highly recommend although you can do it
452without checking dependencies but that would most likely not be portable.
453F\hbox{}inally, -k and my email address is the key I use to sign the package.
455This tool is a Perl tool, of course, and if you look at the source you will see
456the name Ian Jackson in the copyright section. Ian Jackson is the guy who
457started Debian, he is in fact the Ian of Debian with his wife Debra being the
458deb part. You can also see that this f\hbox{}ile is not very well documented, no pod
459for example, which is a shame. There are other modules also being pulled into
460this one, modules like dpkg and dpkg::Version which is useful for checking
461version numbers of packages. Why won't you f\hbox{}ind these packages on cpan? Good
462question. It is one of my long term goals to expose all these tools to cpan and
463get the public to examine them and help with development and documentation. The
464developers in Debian seem to think these tools are only relatively interesting
465to a Debian developer, which may be true, but I suspect it is valuable to have
466tools that work on such a fundamental level with Debian packages since Debian is
467so widespread. Then people can either use them themselves or even devise tools
468on top of them that might be useful, like the cpan2dist tool in cpanplus. I can
469also see these tools as potentially being useful for a distribution agnostic
470linux packaging program. In any case, I think Debian should follow the best
471practices of the Perl community either way and make the tools available and I
472intend to do that work if someone does not beat me to it.
474In the meantime, what happened when we built our package? Since we passed -D to
475check dependencies, dpkg-buildpackage called dpkg-checkbuilddeps and found that
476we cannot build our package because we are missing a dependency; Test::Manifest.
477You can run dpkg-checkbuilddeps separately and this is the output:
479\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-checkbuilddeps,caption=dpkg-checkbuilddeps output]{}
480dpkg-checkbuilddeps: Unmet build dependencies: libtest-manifest-perl (>= 1.14)
483The above line tells us that the Perl module Test::Manifest needs to be included
484for and that it already exists in Debian as the package libtest-manifest-perl.
485Marvel at the power of the apt system! It saved us a journey to dependency hell.
486We simply install libtest-manifest-perl and try to build again\ldots
488This time, success! Dpkg-buildpackage will ask me for my key passphrase, which I
489give it, and it signs the package for me. Now if we look in our dir we have:
491\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:post-dpkg-checkbuilddeps,caption=Directory after successful dpkg-checkbuilddeps run]{}
492libtest-file-perl-1.25
493libtest-file-perl_1.25-1_all.deb
494libtest-file-perl_1.25-1.dsc
495libtest-file-perl_1.25-1_i386.changes
496libtest-file-perl_1.25-1.tar.gz
499Hooray! We have our deb, signed and sealed. You can install it now with dpkg -i
500libtest-f\hbox{}ile-perl\_1.25-1\_all.deb but before we pass it out far and wide, let
501us take one f\hbox{}inal step and build it in a ``clean room'' or a minimal Debian
502install. This we can use as a baseline and assume that if it builds and installs
503here it can build and install anywhere. To do this we are going to use pbuilder
504which is a ``personal package builder''. It creates a chroot, downloads a
505minimal Debian install, adds your package and any dependencies and builds a deb
506for you. If that works, you can be reasonably sure it will work out in the
507greater wide world of the Debian installed base.
512\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-1,caption=pbuilder command]{}
513sudo pbuilder build libtest-file-perl_1.25-1.dsc
516I will go through an arbitrary selection of pbuilder's output:
518\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-1,caption=pbuilder output]{}
519I: using fakeroot in build.
520Current time: Wed Feb 11 16:22:37 CET 2009
521pbuilder-time-stamp: 1234365757
522Building the build Environment
523 -> extracting base tarball [/var/cache/pbuilder/base.tgz]
526The base tarball gets unpackaged to create the build environment (f\hbox{}igure
527\ref{cl:debs_cpan:pbuilder-1}).
529\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-2,caption=pbuilder process continued]{}
530Get:1 http://ftp.debian.org sid Release.gpg [189B]
531Get:2 http://ftp.debian.org sid Release [80.6kB]
532Get:3 http://ftp.debian.org sid/main Packages/DiffIndex [2038B]
533Get:4 http://ftp.debian.org sid/main 2009-02-10-2012.30.pdiff [5047B]
536Here (f\hbox{}igure \ref{cl:debs_cpan:pbuilder-2}) pbuilder updates the base Debian
537install with the latest dif\hbox{}fs of packages so your clean room is up-to-date. You
538can update it manually as well and change the distribution you want to use, I
539prefer to use testing but you might want to use stable.
541\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-3,caption=pbuilder process continued]{}
543 -> copying [libtest-file-perl_1.25-1.dsc]
544 -> copying [./libtest-file-perl_1.25-1.tar.gz]
548pbuilder pulls in our source for the package (f\hbox{}igure
549\ref{cl:debs_cpan:pbuilder-3}).
551\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-4,caption=dpkg-buildpackage takes over]{}
552dpkg-buildpackage: source package libtest-file-perl
553dpkg-buildpackage: source version 1.25-1
554dpkg-buildpackage: source changed by Jeremiah C. Foster <jeremiah@jeremiahfoster.com>
555dpkg-buildpackage: host architecture i386
558dpkg-buildpackage takes over and does its stuf\hbox{}f.
560\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-5,caption=Test failure!]{}
561Test::Manifest::test_harness found [t/load.t t/pod.t t/pod_coverage.t t/normalize.t t/test_files.t t/owner.t t/rt/30346.t]
563t/pod.............skipped
564 all skipped: Test::Pod 1.00 required for testing POD
567Aha! I missed a useful tool. Since Test::Pod gets called while running tests, I
568should add it to Build-Depends-Indep in the debian/control f\hbox{}ile to get these
569tests to run. Of course it builds without it, but it is better to run all our
570tests as the original developer envisioned. Once I add that module and the
571module Test::Pod::Coverage which is also used in tests to the debian/control
572f\hbox{}ile, all the tests pass and the package gets built. This is a pretty good
573indication that this package will build on someone else's machine.
575To conf\hbox{}irm that we are in accordance with policy we ought to run the package
576through lintian, the Debian policy checker. I run it with the -i and -I f\hbox{}lags
577which provides much more verbose output, it has a {-}{-}pedantic switch as well.
578We might run it against our deb like this:
580\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:lintian-command,caption=lintian command]{}
581lintian -i -I libtest-file-perl_1.25-1_all.deb
584And get output like this:
586\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:lintian-output,caption=lintian output]{}
587E: libtest-file-perl: perl-module-in-core-directory usr/lib/perl/5.10/
589N: Packaged modules must not be installed into the core Perl directories as
590N: those directories change with each upstream Perl revision. The vendor
591N: directories are provided for this purpose.
593N: Refer to Debian Perl Policy section 3.1 (Site Directories) for details.
595N: Severity: important, Certainty: certain
596\end{lstlisting}\cite{debs_cpan-debian_perl_policy}
598These warnings are good to have, were you to submit your package for inclusion
599in Debian the expectation is that your package is ``lintian clean'' which means
600without warnings from lintian. Now we can submit this to Debian or put it in our
601own personal deb repo with conf\hbox{}idence.
603The package goes through some automatic building on a variety of architectures,
604sits in a queue for about ten days, then gets put into the Debian ``testing''
605distro. Anyone who has Debian testing sources in the /etc/apt/sources.list will
606now be able to install it just by calling aptitude. Now your package or software
607is available to millions of users. Congratulations.