Package your software for easy installation on Ubuntu.
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.org/doc/debian-policy), and Debian Developers Reference (http://www.debian.org/doc/manuals/developers-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 [Hack #59] 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:$ mkdir
myprogram
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 zxf
myprogram-1.0.tar.gz
Create Package Files
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.0
$ dh_make -e
user@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 control file 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 rules file 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 the rules file.
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 .ex file to remove the extension and edit the file to add commands you want to execute.
Build the Package
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 -rfakeroot
The -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:$ lintian
myprogram_1.0.1_i386.changes
You can now use the instructions in "Install and Remove Standalone .deb Files" [Hack #57] to install and test your new package, and even "Create Your Own Package Repository" [Hack #65] if you want to publish it for the world to use.
Update the 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 -a
myprogram-1.0
/debian
myprogram-1.1/
Then enter the new source directory and increment the Debian changelog:$ cd
myprogram-1.1
$ dch -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
No comments:
Post a Comment