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.
[ Parent | Reply to this comment ]
[ Send Message | 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 ]
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 ]
[ Parent | Reply to this comment ]
$ 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 ]
debuild -us -uc
[ Parent | Reply to this comment ]
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 ]
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 ]
$ 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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]