HOWTO: Create a .deb package
Jul 03 2017
2 minutes read

HOWTO: Create a .deb package

This is basic tutorial on how to get started with building debian packages. It mostly assumes that that the package you are trying to build is either using make or some other simple build system.

To get some more details about options and other advanced methods and tooling to build .deb packages, see this post. It is a tutorial to build a debian package.

I started off with building the package for a scons based project, astroid. While scons works fine when you are manually trying to compile and install the project, it lacks some important functionality that makes packaging a project based off it difficult. Of the other problems with this build system, the most prominent one is that it doesn’t honor some environment flags like CFLAGS and CPPFLAGS or LD_FLAGS, which means the package maintainer has to add more code to make the build system honor these.

Also, scons doesn’t allow specifying a DESTINATION directory to install and installs by default only the directory specified by --prefix (e.g. —prefix=/usr will result in package installed at /usr/bin). This becomes a problem because when you try to create a .deb package, you need to install everything under debian/projectname.

  • This thread was very helpful for me to get started on writing build script for ubuntu.
  • There are options to make things work for other project by using this recipe.

The command I am using to build the package is debuild -us -uc . Here is a copy of the debian/rules script which is the most important one to build:

#!/usr/bin/make -f

DEB_SCONS_OPTIONS := --prefix=/usr --destdir=$(CURDIR)/debian/astroid/usr

        dh $@

        $(SCONS) $(DEB_SCONS_OPTIONS) -j 4 build

        rm -rf .sconf_tem/ .sconsign.dblite config.log

        $(SCONS) $(DEB_SCONS_OPTIONS) install

Note that this is a Makefile so everything in indented with a single TAB character.

I also had to modify the SConstruct file, which is nothing but a python file without any extensions and is sort of like a scons config file for the project.

Back to posts