Go to TogaWare.com Home Page.
GNU/Linux Desktop Survival Guide
by Graham Williams
Google

Building Packages from Source


You can download the source code for any Debian package from the Debian archive. You can then modify it, if you wish, and then generate your own deb file for installation. Or perhaps, like Gentoo, you are interested in building the package with your local compilation optimisations to suit your system specifically. This is all quite easy with Debian.

The steps involved include:

  1. Obtain the source;
  2. Unpack the source;
  3. Apply the patches;
  4. Compile the source code;
  5. Build the Debian package.

To obtain the source of a Debian package you will need one or more deb-src lines in your /etc/apt/sources.list file. The following is a good start:

  deb-src http://ftp.debian.org/debian unstable main contrib non-free

Generally you can add the `-src' to copies of pre-existing `deb' lines.

To obtain and unpack the source Debian package, and have the Debian patches applied, use:

  $ wajig source <package names>                (apt-get source)

Note that you can list several packages and grab all of their sources at once.

The source command downloads a tar.gz file, a dsc file, and possibly a diff file for the package. The tar.gz file contains the source code and associated files. The dsc file contains test information that is used by the packaging system. The diff file contains changes, as a patch file, made by the Debian maintainer of the package. The source command will also extract the contents of the .tar.gz archive into a subdirectory consisting of the package name and version, and applies the patches contained in the diff file.

You could reverse the patching using, for example, if the package we obtained was most_4.9.5-1.deb:

  $  zcat most_4.9.5-1.diff.gz | patch -R -p0

To go one step further and also configure and compile the package, and then generate a default Debian deb package from the source code then use:

  $ wajig build <package names>         (apt-get source -b)

This will allow you to apply any optimisations during the compilation process to suit your own environment. This is similar to Gentoo, allowing for automatic optimisation and customisation to suit the user. To tune the build edit the file /etc/apt/apt-build.conf.

If you need to modify the source to the package (e.g., the package most) in some way and thus need to rebuild the deb package, the steps would be:

  $ wajig update
  $ wajig source most
  $ cd most_4.9.5

Now modify the source code to your own liking, then generate the Debian package with:

  $ fakeroot dpkg-buildpackage -b -uc -us

This leaves a new most_4.9.5-1_i386.deb in the parent directory, and you can install it directly:

  $ cd ..
  $ wajig install most_4.9.5-1_i386.deb

Copyright © 1995-2006 [email protected]
Contribue and access the PDF Version