Build Package

With the Debian directory ready, you should be able to build the package now. This guide focuses on building unsigned, signed, binary, and source packages; install package to test run; and removing test package. As per guide, you can use various methods to build your package. In this guide however, we'll be using the commonly used tool: debuild.

You must not assume the deb package is working fine. Follow the New Maintainer Guide clearly.

Assemble Your Package Directory

Before building, you must assemble the package directory properly. Otherwise, the build fails. You need to create a directory in this format:

<package name>-<version>

Example:

fennec-0.5.0

Copy all the files into this folder, including the Debian directory. Ensure the changelog is updated.

Build the Unsigned Binary Package

Command

Now, let's build the unsigned binary package for testing. Get into the package directory and execute the debuild instruction.

$ cd <package name>-<version>
$ debuild -us -uc

If you're using a custom Lintian profile or data, then append the Lintian argument as well. Here's an example:

$ debuild -us -uc --lintian-opts --include-dir /path/to/lintian-data --profile ubuntu


Study the Build Log

Keep in mind that there is a argument order for debuild tool. Read its help instruction for more details. As you build, watch for Lintian warning. Example:

 dpkg-buildpackage -rfakeroot -us -uc
dpkg-buildpackage: info: source package fennec
dpkg-buildpackage: info: source version 0.5.0+debian
dpkg-buildpackage: info: source distribution stable
dpkg-buildpackage: info: source changed by ZORALab Enterprise <tech@zoralab.com>
 dpkg-source --before-build fennec-0.5.0
dpkg-buildpackage: info: host architecture amd64
 fakeroot debian/rules clean
dh clean
   dh_testdir
   dh_auto_clean
   dh_clean
 dpkg-source -b fennec-0.5.0
dpkg-source: info: using source format '3.0 (native)'
dpkg-source: info: building fennec in fennec_0.5.0+debian.tar.xz
dpkg-source: info: building fennec in fennec_0.5.0+debian.dsc
 debian/rules build
dh build
   dh_testdir
   dh_update_autotools_config
   dh_auto_configure
   debian/rules override_dh_auto_build
make[1]: Entering directory '/home/holloway/src/gitlab.com/zoralab/fennec/tmp/fennec-0.5.0'
mv fennec.sh fennec
make[1]: Leaving directory '/home/holloway/src/gitlab.com/zoralab/fennec/tmp/fennec-0.5.0'
   dh_auto_test
   create-stamp debian/debhelper-build-stamp
 fakeroot debian/rules binary
dh binary
   create-stamp debian/debhelper-build-stamp
   dh_testroot
   dh_prep
   dh_auto_install
   dh_install
   dh_installdocs
   dh_installchangelogs
   dh_installman
   dh_perl
   dh_link
   dh_strip_nondeterminism
   dh_compress
   dh_fixperms
   dh_installdeb
   dh_gencontrol
dpkg-gencontrol: warning: Depends field of package fennec: unknown substitution variable ${shlibs:Depends}
   dh_md5sums
   dh_builddeb
dpkg-deb: building package 'fennec' in '../fennec_0.5.0+debian_all.deb'.
 dpkg-genbuildinfo
 dpkg-genchanges  >../fennec_0.5.0+debian_amd64.changes
dpkg-genchanges: info: including full source code in upload
 dpkg-source --after-build fennec-0.5.0
dpkg-buildpackage: info: full upload; Debian-native package (full source is included)
Now running lintian...
Finished running lintian.

Successfully signed dsc, buildinfo, changes files

If you see something as above, it means you built a clean and proper package. If you see something like:

Now running lintian...
E: fennec source: invalid-standards-version 0.5.0
Finished running lintian.

It means your package has invalid values or settings. You should search the Lintian tag in the list, study it properly, and then fix it accordingly. There are 3 main types of responses:

  • E - stands for error. You must fix this issue.
  • W - stands for warning. You're recommended to fix this issue.
  • I - stands for info. Minor issue like spelling or wording detected. It's best to fix it.

By common practice, there shouldn't be any reporting issues.

Expected Outcome

If there is no critical issue detected by the Lintian, you should get the packages right next to the package directory. Here is an example:

tmp
├── fennec-0.5.0
├── fennec_0.5.0+debian_all.deb
├── fennec_0.5.0+debian_amd64.build
├── fennec_0.5.0+debian_amd64.buildinfo
├── fennec_0.5.0+debian_amd64.changes
├── fennec_0.5.0+debian.dsc
└── fennec_0.5.0+debian.tar.xz

Test the Package - Install

Unless you're building for different architecture with explicit instruction, this is good enough for testing your package settings. To test the package. Simply use dpkg instruction to install the compiled deb package. Following the example above, the instruction should be like:

$ sudo dpkg -i tmp/fennec_0.5.0+debian_all.deb

These are the things you should observe:

  1. The installation carries out successfully.
  2. If there are dependent packages, use "$ sudo apt install -i" to install those dependencies.
  3. Check every files listed in debian/install is moved correctly.
  4. Test the expected usability.

If all things are good. You can proceed to the next stage.


If the package is broken...

Don't panic. Fix the issue, update the changelog and recompile again. With the new version, use --force-overwrite argument to force install the new version. Example command:

$ sudo dpkg -i --force-overwrite tmp/fennec_0.5.1+debian_all.deb

Keep doing it until you fix all the installation issue.

Test the Package - Uninstall

Once you've tested the installation process, it's time to uninstall it. Use dpkg --remove command to remove your test package. Following the example above (my package name is fennec), you should have:

$  sudo dpkg --remove fennec
  • Take note that for remove, you should use the package name, not the deb filename.

These are the things you need to check:

  1. Are the files listed in debian/install removed cleanly?
  2. Are the user-specific configuration files removed as expected?


If the package is broken...

Don't panic. Fix the issue, update the changelog and recompile again. Force-overwrite the new installation and test the uninstall process again. If all else still fails, DON'T UPSTREAM IT. To clean up your system use this nuclear command as your last option:

$  sudo dpkg --remove --force-remove-reinstreq fennec
  • NOTE: when I said nuclear, I meant it. It can damage your system. Use this only as a last option.
  • If all else still fails, do a in-depth analysis on why the package fails miserably.

Test the Package - Update

If you have an earlier version of your package, you should install it now. Then use dpkg to install the latest version you had built. This is for testing the updating process. YOU MUST NOT FAIL THIS PROCESS. Almost all the software life-cycle depends on this update process.


If the package is broken...

Don't panic, follows the Install and Uninstall sections above until you fix the issue.

Build Signed Binary Package

Now that we have our package tested and cleared the known bugs, it's time to build the signed version. You'll need to setup your private GnuPG key that has its public key synchronized with your upstream server. Once done, you can:

  1. Remove all the previously built artifacts.
  2. Use the -k argument instead to state the use of GnuPG signing.

The command, following the example above, should be as follows depending on whether the usage of custom Lintian data and profile:

$ debuild -k[MYGPGID]
$ debuild -k[MYGPGID] --lintian-opts --include-dir /path/to/lintian-data --profile ubuntu

This builds the signed binary version. Run all the test again to test it is working fine. You shouldn't be facing too much obstacles by now.

Build Singed Source Only Package

Most open-source upstream server wants source-only package. This means that they're looking for .changes file, not .deb. In this case, since our package is now cleared of installation, update, uninstall process bugs, we can safely build the source only package. You can:

  1. Optionally, remove all the previously built artifact.
  2. Append -S after -k argument. It stands for source-only.

The command, following the example above, should be as follows depending on your usage for custom Lintian data and profile:

$ debuild -k[MYGPGID] -S
$ debuild -k[MYGPGID] -S --lintian-opts --include-dir /path/to/lintian-data --profile ubuntu

If you did not remove your previous signed binary package artifact, the output should be:

tmp/
├── fennec-0.5.0
├── fennec_0.5.0+debian_all.deb
├── fennec_0.5.0+debian_amd64.build
├── fennec_0.5.0+debian_amd64.buildinfo
├── fennec_0.5.0+debian_amd64.changes
├── fennec_0.5.0+debian.dsc
├── fennec_0.5.0+debian_source.build
├── fennec_0.5.0+debian_source.buildinfo
├── fennec_0.5.0+debian_source.changes
└── fennec_0.5.0+debian.tar.xz

You should see that there are extra _source files and a .changes. These are the files (bolded) open-source upstream server is looking for. They will rebuild your package based on the received changes.

That's all about builds. If no error occurs during testing for all 3 builds, congratulations! You had successfully built your first deb software package.

Beyond this topic are advanced options, like customizing the debian/rules build rules and adding pre/post install/remove scripts for your package.