I often receive emails telling me that Dotdeb is a great tool, but that some useful packages are missing, such as some PECL extensions. I wish I could maintain many and many packages, but I don’t think it’s a good idea for the Dotdeb’s overall quality and for my free time ;) Sorry for that.

Then, this article will show you how to build packages from your favorite PECL extensions in a strict Debian way, using the dh-make-php package.

Imagine we want to package the Fileinfo extension for PHP5…

First, install all the needed packages (libmagic-dev is only needed here to build Fileinfo) :

# apt-get install dh-make-php php5-dev build-essential libmagic-dev debhelper

Then, export some needed environment variables, download the package

# export DEBFULLNAME="Firstname Lastname"
# export DEBEMAIL="your@email.tld"
# pecl download fileinfo
downloading Fileinfo-1.0.4.tgz ...
Starting to download Fileinfo-1.0.4.tgz (5,835 bytes)
.....done: 5,835 bytes
File /tmp/Fileinfo-1.0.4.tgz downloaded

Ok, let’s summon the magical dh-make-pecl command with the appropriate arguments :

# dh-make-pecl --phpversion 5 --prefix php5- Fileinfo-1.0.4.tgz
Creating debian source package: php-fileinfo-1.0.4
Upstream is: Ilia Alshanetsky
Guessing Maintainer: Firstname Lastname

No error message… Great! dh-make-pecl did its job, e.g. unarchived the tarball and created the php-fileinfo-1.0.4/debian/ subdirectory that contains all the packaging stuff. " –phpversion 5" restricts the building process to PHP5 packages (PHP4 is obsolete!) and " –prefix" sets the prefix in the package’s name.

Let’s build the package!

# cd php-fileinfo-1.0.4/
# ./debian/rules binary
xsltproc --nonet --novalid debian/changelog.xsl package.xml > debian/Changelog
touch build-stamp
dh_testdir
...
dh_md5sums
dh_builddeb
dpkg-deb: building package `php5-fileinfo' in `../php5-fileinfo_1.0.4-1_i386.deb'.

That’s it! Let’s take a look at the content of the package…

# dpkg -c ../php5-fileinfo_1.0.4-1_i386.deb
drwxr-xr-x root/root         0 2008-09-20 10:10 ./
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/lib/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/lib/php5/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/lib/php5/20060613+lfs/
-rw-r--r-- root/root     10296 2008-09-20 10:10 ./usr/lib/php5/20060613+lfs/fileinfo.so
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/share/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/share/doc/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/share/doc/php5-fileinfo/
-rw-r--r-- root/root       202 2008-09-20 10:09 ./usr/share/doc/php5-fileinfo/README.Debian
-rw-r--r-- root/root        26 2004-02-13 01:06 ./usr/share/doc/php5-fileinfo/CREDITS
-rw-r--r-- root/root      3466 2008-09-20 10:09 ./usr/share/doc/php5-fileinfo/copyright
-rw-r--r-- root/root       159 2008-09-20 10:09 ./usr/share/doc/php5-fileinfo/changelog.Debian.gz
-rw-r--r-- root/root       865 2005-11-24 23:07 ./usr/share/doc/php5-fileinfo/fileinfo.php
-rw-r--r-- root/root       149 2008-09-20 10:10 ./usr/share/doc/php5-fileinfo/changelog.gz

and its metadata :

# dpkg -I ../php5-fileinfo_1.0.4-1_i386.deb
 new debian package, version 2.0.
 size 12740 bytes: control archive= 4848 bytes.
     940 bytes,    31 lines   *  config               #!/bin/sh
     607 bytes,    20 lines      control
     522 bytes,     7 lines      md5sums
    1218 bytes,    58 lines   *  postinst             #!/bin/sh
     206 bytes,     8 lines   *  postrm               #!/bin/sh
    1773 bytes,    63 lines   *  prerm                #!/bin/sh
    8758 bytes,    67 lines      templates
 Package: php5-fileinfo
 Version: 1.0.4-1
 Section: web
 Priority: optional
 Architecture: i386
 Depends: libc6 (>= 2.3.6-6), libmagic1, debconf (>= 0.5) | debconf-2.0, php5 | php5-cli
 Installed-Size: 100
 Maintainer: Firstname Lastname
 Source: php-fileinfo
 Description: Fileinfo module for PHP 5
  libmagic bindings
  .
  This extension allows retrieval of information regarding vast
  majority of file.
  This information may include dimensions, quality, length etc...
  .
  Additionally it can also be used to retrieve the mime type for a
  particular
  file and for text files proper language encoding.
  .

Great job! Now install the package and enjoy…

For more information and specific needs, take a look at " dh-make-pecl" and " man dh-make-pecl".

Note : this article has been translated to Belorussian.