(Re)building De{bi,vu}an packages from source

This is nothing new; there are plenty of notes out on the Internet about how to build Debian packages from source.

This page is just brief notes on what you need to have installed before it will work.

They are based on Devuan Beowulf 3 (ie: Debian Buster 10).

  • dpkg-dev
    • This will automatically also bring in:
      • binutils binutils-common binutils-x86-64-linux-gnu libbinutils libdpkg-perl patch
    • You need this before you can even run apt-get source package
    • If your only purpose is to able to look at the source code (perhaps to find out quite why/when some error message gets generated) then this is all you need
  • build-dep (not an installable package)
    • Debian has a convenient facility for installing anything that building a given package is going to need, so you don't have to work it out for yourself, or wait for multiple compiler errors and install each thing you find is missing
    • The command is apt build-dep package
      • If you haven't yet installed the compiler toolchain needed to build any package, then this will also do that for you
  • build-essential
    • This will install a C/C++ compiler and various libraries, which are probably needed for building most packages (unless they're written in some obscure language)
  • It's probably a good idea also to install fakeroot so that you can build packages as a non-root user (which is generally recommended)
  • Building the package
  • If you don't want to make any changes to the source code, you can actually use apt to download it and build it in one go:
    • apt-get source --compile package
  • If you do want to make some changes, and then build the modified version, this is the time to do those edits, and then you can build the modified package with either of the following commands:
    • debuild -b -uc -us
    • dpkg-buildpackage -b -uc -us
      • Both of these commands should be run from the top-level directory of the source code (which should contain things like configure, Makefile, INSTALL, LICENSE, README, although note that not all source packages do include all of these files)

Notes on specific packages

Installing packages after building them

If you build something simple, it may result in a single .deb binary package which you can install using dpkg -i package.deb

If you build something complicated, it may result in quite a few .deb binary packages (for example, FreeSwitch creates about 350!), which contain dependencies between them, and dpkg has no clue about dependencies.

Therefore you need to create a Debian Repository on your local machine, and point sources.list at it.

It's not entirely trivial (for example, a directory containing the files), but it's not overly-complicated either. Whatever you do, don't start reading the Debian documentation on Repositories and what they need to contain - that is vastly over-complex.

If you do want official Debian documentation on how to set up a local repository, this list of tools is a better place to start.

Someone wrote a short article in 2018 which looks encouraging, but when you try this out, aptitude complains that The repository does not have a Release file.

There's also a tool named aptly which looks promising, but so far hasn't created what I need.

Solution

It's not complicated after all.

  1. Create the directory where you want your .deb files to be fetched from
  2. Copy the newly-built .deb files into this directory
  3. Change into this directory
  4. Create the Packages file
  5. Create the Release file
  6. Add the repository to sources.list
  7. Update the available packages
mkdir -p /usr/local/repo/FreeSwitch
rsync -Pav *.deb /usr/local/repo/FreeSwitch
cd /usr/local/repo/FreeSwitch
dpkg-scanpackages . >Packages
apt-ftparchive release . >Release
echo 'deb     [trusted=yes] file:/usr/local/repo/FreeSwitch/ /' >/etc/apt/sources.list.d/local.FreeSwitch.list
aptitude update

If you'd like to have the repository available over the network, I can think of two obvious ways of achieving this:

  1. Set up an NFS share containing a directory as described above, and point sources.list at that share on any machine which needs to use it
  2. Copy the directory to a web server which is accessible either on a LAN or over the Internet and then point sources.list at that in the usual way:
    deb     [trusted=yes] http://my.web.server/repo/FreeSwitch/ /

Go up
Return to main index.