Ubuntu is built on Debian and uses the .deb package format to ensure that all
software is installed in a consistent way. If you want to make your
software really easy to install on Ubuntu, you need to know how to put
it into a Debian package.
There is a large variety of helper tools and build suites to assist with creating Debian packages, and just about as many approaches to streamlining package creation as there are package maintainers. To fully understand how Debian packages work, start by exploring the Debian New Maintainers Guide (http://www.debian.org/doc/maint-guide), Debian Policy Manual (http://www.debian.or...c/debian-policy), and Debian Developers Reference (http://www.debian.or...opers-reference), which, between them, run to many hundreds of pages of detailed information.
This hack is a quick-and-dirty introduction to show you how to
build a basic binary package as quickly as possible. It assumes that the
program you want to package is in a source tarball named myprogram-version.tar.gz and can be installed
with a simple procedure such as:
$./configure$make$sudo make install
The procedure for packaging libraries and other types of software can be more involved, so consult the Debian references mentioned earlier for more information.
Start by installing some of the developer tools:
$sudo apt-get install fakeroot debhelper build-essential \\lintian dh-make devscripts
Create a directory to work in so all your files stay neat:
$mkdirmyprogram
Copy the source tarball into the
myprogram directory and extract it (the
directory that this process creates must have a version number in it, as
in myprogram-1.0):
$tar zxfmyprogram-1.0.tar.gz
You now have both a tarball and an extracted copy of the source code. Go into the extracted source code directory and run dh_make to set up sample files for you:
$cd$myprogram-1.0dh_make -euser@example.com-f../myprogram-1.0.tar.gz
dh_make will ask you what
sort of package you want to create. In this case, it's a single binary
package, so select that option (s,
not b). dh_make will then create a debian directory containing all the files
necessary to build the package, and the email address you provided
will automatically be inserted into the package changelog. Now go into
the newly created debian
directory and customize some of the files as necessary, but don't run
dh_make again: it needs to run only
when the package is first set up, and running it again in an already
configured package will almost certainly break it. Here are the files
you may want to change:
- control
The
controlfile contains meta information about the package. Most of the fields in the file should be self-explanatory, so change any entries as necessary and put in short and long descriptions for the package. Note that any blank lines in the long description need to contain a single period.- rules
The
rulesfile is a makefile that is executed at package build time to compile the package source into a binary. The file will have been automatically configured by dh_make to suit a typical build process, but if your package requires any unusual steps to be performed, you may need to edit the appropriate section of therulesfile.- preinst
- postinst
- prerm
- postrm
Because package installation and removal can sometimes require arbitrary commands to be run, the Debian package format provides support for four optional scripts that are run before and after installation, and before and after removal. If you want to use any of them, rename the appropriate
.exfile to remove the extension and edit the file to add commands you want to execute.
Now that the package source directory has been set up,
you can build the actual package. This needs to be done from inside
the extracted source directory, so if you are still inside the
debian directory after
customizing the package scripts, you need to cd .. to
back up one level, then run
dpkg-buildpackage:
$ dpkg-buildpackage -b -uc -rfakerootThe -b option specifies that
only a binary package should be built. If you also want to build a
source package, leave off that option. The -uc option specifies that the
changes file in the package should not be
GPG-signed, so if you have a GPG key and want to sign the package, you
can leave off that option as well. The -rfakeroot option specifies that
fakeroot should be used to create the temporary
build environment.
Once that process has finished, you will have a couple of new
files outside your source directory, including a package named
myprogram-1.0_i386.deb or similar. Before
going any further, you can use a program called lintian to run some automatic checks on the
package to make sure there are no obvious mistakes.
lintian performs hundreds of checks to make sure
the package complies with the official Debian policy and packaging
guidelines, so even though it may generate warnings that you don't
care about for packages you create for personal use, it's still a
great way to check that you haven't missed any important steps.
Run lintian with the path to
the changes file that was created
along with your new package:
$lintianmyprogram_1.0.1_i386.changes
You can now install and test your new package.
When the software itself is released as a new version,
you need to build a new package to suit. Start by copying the new
source tarball into your working directory alongside the original
version, and then extract it. You should now have two source
directories and two tarballs. Copy your customized debian directory from the old source
directory to the new one:
$cp -amyprogram-1.0/debianmyprogram-1.1/
Then enter the new source directory and increment the Debian changelog:
$cd$myprogram-1.1dch -i
The dch -i
command will throw you into an editor and automatically place a new
entry at the top of the package changelog; it will also auto-complete
your name and email address as well as increment the version number.
If the new version number is not correct, just edit it to suit the new
upstream version number, write a brief explanation for the new
release, and save and exit the editor.
Now rerun the command to build the package:
$ dpkg-buildpackage -b -uc -rfakeroot
Like all books in the "Hacks" series, Ubuntu Hacks includes 100 quick tips and tricks for all users of all technical levels. Beginners will appreciate the installation advice and tips on getting the most out of the free applications packaged with the Ubuntu Linux distribution, while intermediate and advanced readers will learn the ins-and-outs of power management, wireless roaming, 3D video acceleration, server configuration, and much more.




Help





