Building Debian packages of Perl modules

Posted by Steve on Wed 12 Jan 2005 at 17:34

Perl is a very widely used language which gets a lot of its power from the huge number of third party modules which available in the CPAN archive. If you want to use a perl module which hasn't been packaged for Debian you have a choice to make.

Your options are to build a Debian package yourself, or install the module "by hand", independent of the Debian packaging system.

The former is the option which I usually chosen, as it makes it simple to install the produced package on multiple machines.

(Another advantage of making Debian packages of perl modules which aren't yet available is that they'll be upgraded automatically if they are ever included in Debian in the future).

Creating simple Debian packages of perl modules is greatly simplified by the dh-make-perl package.

Install it like this:

apt-get install dh-make-perl

As an example of a module which isn't available in Debian's archive is HTML::Template::JIT - which is a handy module for caching template files, the kind of files which are used to run this very website!

If we wanted to install that using CPAN, the perl module which builds and installs modules we'd run:

perl -MCPAN -e 'shell'
install HTML::Template::JIT

Instead of that we want to build a Debian package - which we can do as follows.

First of all we download the source to the module, and unpack it:

wget http://search.cpan.org/CPAN/authors/id/S/SA/SAMTREGAR/HTML-Template-JIT-0.04.tar.gz
tar -pzxvf HTML-Template-JIT-0.04.tar.gz

Once this is done we can run the dh-make-perl command to setup a simple set of packing files, inside the module source directory.

dh-make-perl HTML-Template-JIT-0.04/

This will produce a subdirectory called debian/ which has the rules to build, install, and handle the package. Feel free to browse around in there - all of the files are documented in the Debian New Maintainer's Guide.

As defaults for a module you wish for personal use only the generated files will likely be all you need. For producing a module you wish to upload to the Debian repositories though you will need to do much more work on them, after reading the Debian Perl Policy.

Anyway, back to our module. Once the dh-make-perl command has been executed you can build the module for real:

cd HTML-Template-JIT-0.04
debuild

Once this has finished executing you should have a .deb file sat waiting for you:

skx@lappy:~/HTML-Template-JIT-0.04$ cd ..
skx@lappy:~$ ls *.deb
libhtml-template-jit-perl_0.04-1_all.deb

This module can be installed with "dpkg --install", or uploaded to your own apt repository.

When you have a new release you can go through the same steps to build a new package, which can be upgraded.

The only downside to this method of producing packages is that the dependencies will be weakened - here we've produced a package HTML::Template::JIT, now realistically this package is useless without HTML::Template (contained in the libhtml-template-perl package) but that isn't mentioned as a package dependency.

If you're keeping track of such things you should be OK, otherwise you might find unexpected breakages.

 

 


Posted by Anonymous (80.8.xx.xx) on Sun 20 Feb 2005 at 08:14
faster :
dh-make-perl --build --cpan HTML::Template::JIT

[ Parent | Reply to this comment ]

Posted by forrest (208.42.xx.xx) on Sat 28 May 2005 at 03:38
[ View Weblogs ]
What if one or more tests fail?

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Sat 28 May 2005 at 03:58
[ View Steve's Scratchpad | View Weblogs ]

Comment out 'make test' ? ;)

It might be a common occurrence, but it's never happened to me ..

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (210.177.xx.xx) on Mon 6 Jun 2005 at 05:58
print "Compile mod_persistentperl (default no)? ";

my @dirs = qw(src perperl_backend perperl);
my $macro = $write_makefile_common{macro};
my $apache_module = 0;
if ( =~ /y/i) {
die "ERROR: Command 'apxs -q CC' failed.\n"
unless $macro->{APACHE_APXS_WORKS};
print "Compiling for Apache version $macro->{APACHE_VERSION}\n";
push(@dirs, $macro->{MOD_PERSISTENTPERL_DIR});
$apache_module = 1;
}

The default build is no mod_apache support , but dh-make-perl trys with yes mod_apache support.

What is that??

[ Parent | Reply to this comment ]

Posted by jeremiah (195.198.xx.xx) on Tue 19 Jun 2007 at 10:41
[ View Weblogs ]
My guess is that this is to check and see if mod_perl is installed and build against that. With mod_perl there is a significant speed-up in cgi scripts.

[ Parent | Reply to this comment ]

Posted by Anonymous (217.132.xx.xx) on Sat 24 Sep 2005 at 21:05
Use the "notest" option?
$ dh-make-perl --help

Usage:
/usr/bin/dh-make-perl [ --build ] [ --install ] [ SOURCE_DIR | --cpan MODULE ]
Other options: [ --desc DESCRIPTION ] [ --arch all|any ] [ --version VERSION ]
[ --cpan-mirror MIRROR ] [ --exclude|-i [REGEX] ] [ --notest ]

[ Parent | Reply to this comment ]

Posted by Anonymous (62.236.xx.xx) on Wed 14 Jun 2006 at 20:41
One note: if debuild says "Could not find a signing program (pgp or gpg)!" and you don't need signing, try to run debuild like this:
debuild -us -uc

[ Parent | Reply to this comment ]

Posted by Anonymous (202.165.xx.xx) on Thu 17 Jul 2008 at 03:35

For CPAN modules based on Module::Install, dh-make-perl seems to fail to find proper dependencies. In this case, one has to edit the file debian/control manually, as in     http://svn.openfoundry.org/openapi/trunk/debian/control

If the CPAN module wants to install configure files to places like /etc/..., then it's required to manually create the file "conffiles" under debian/, as in     http://svn.openfoundry.org/openapi/trunk/debian/conffiles

And then modify the debian/rules makefile's "install" rule to put the default config files to $(TMP)/etc/..., as in     http://svn.openfoundry.org/openapi/trunk/debian/rules

Another hack I have to do against rules' "install" rule is that I have to remove the perllocal.pod file manually from $(TMP), since inclusion of this file in the .deb file will cause conflicts like this:

  dpkg: error processing libjson-xs-perl_2.22-1_i386.deb (--install):
    trying to overwrite `/usr/lib/perl/5.8/perllocal.pod', which is also in package libtext-table-perl

For modules which require doing some post-installation processing, we should create the file debian/postinst and put shell commands into it.

-agentzh

[ Parent | Reply to this comment ]

Posted by Anonymous (194.109.xx.xx) on Wed 23 Jul 2008 at 19:25
I've made a little tutorial for myself; thought it might help others too:

Howto convert Perl CPAN modules into DEBIAN packages?

First get debuild and dh-make-perl:
$ sudo apt-get install devscripts dh-make-perl

Debian Perl policy states that architecture independent packages may not install files in /usr/lib (like perllocal.pod, or .packlist).
Therefore we have to edit some files that dh-make-perl is using for making it work:
$ mkdir ~/.dh-make-perl
$ cp -v /usr/share/dh-make-perl/rules.MakeMaker.noxs ~/.dh-make-perl
$ vim rules.MakeMaker.noxs

Now comment this line: #rmdir --ignore-fail-on-non-empty --parents $(TMP)/usr/lib/perl5
and add the following line:
rm -rfv $(TMP)/usr/lib

Now everything's in place and we can start building deb packages ourselves:

Download a CPAN module:
$ wget http://search.cpan.org/CPAN/authors/id/T/TM/TMTM/Text-CSV-Simple- 1.00.tar.gz
$ tar xvfz Text-CSV-Simple-1.00.tar.gz
$ cd Text-CSV-Simple-1.00/

Now create the environment for debuild and resolve dependencies using apt-file:
$ dh-make-perl

Now build the package without signing it:
$ debuild -us -uc

Test if everything's working:
$ make test

Verify that no references to /usr/lib were made:
$ dpkg -c ../libtext-csv-simple-perl_1.00-1_all.deb

Install the package:
$ sudo dpkg -i ../libtext-csv-simple-perl_1.00-1_all.deb

Greetings,

Patrick of SPM Development

[ Parent | Reply to this comment ]

Posted by Anonymous (158.94.xx.xx) on Thu 2 Jun 2011 at 16:29
From the tutorial by Patrick, I got:

$ cp -v /usr/share/dh-make-perl/rules.MakeMaker.noxs ~/.dh-make-perl

cp: cannot stat `/usr/share/dh-make-perl/rules.MakeMaker.noxs': No such file or directory

How much does this business of 'architecture independent packages may not install files in /usr/lib' matter?

Thanks

[ Parent | Reply to this comment ]

Posted by Anonymous (85.26.xx.xx) on Mon 6 Dec 2010 at 13:30
Thank you.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 525 votes ~ 7 comments )

 

 

Related Links