Debian Packaging: From Source to Repository

Dependencies and Build Systems

A practical Debian packaging course lesson covering dependencies and build systems.

Dependencies and Build Systems

Dependencies determine what must be available to build a package and what must be installed for users to run it. Incorrect dependency metadata can make a package difficult to build or unusable after installation.

In this lesson, we will distinguish dependency types, review Debian substitution variables, and understand how debhelper coordinates build systems.

Learning Objectives

  • Distinguish build dependencies from runtime dependencies.
  • Understand common dependency fields.
  • Use debhelper substitution variables.
  • Inspect shared-library dependencies.
  • Keep package metadata minimal and correct.

1. Build Dependencies

Build dependencies are declared in the source stanza of debian/control.

For Syspeek:

1
2
3
Build-Depends:
 debhelper-compat (= 13),
 golang-any

These packages are needed to build the binary package.

The compiler and packaging helpers should not normally be installed on a user’s machine merely because they installed Syspeek.

2. Runtime Dependencies

Runtime dependencies are declared in the binary package stanza.

Our current application uses the Go standard library and is built with cgo disabled. Its binary does not require an additional Go runtime package.

We still include:

1
Depends: ${misc:Depends}

Debhelper can fill in this substitution variable with package dependencies required by its generated maintainer scripts or other helper functionality.

For dynamically linked applications, additional runtime library dependencies may be generated automatically.

3. Other Dependency Fields

Debian supports several dependency relationships:

  • Depends: packages required for the package to function.
  • Pre-Depends: packages that must be configured before the package is unpacked.
  • Recommends: packages normally installed alongside the package.
  • Suggests: packages that may be useful.
  • Build-Depends: packages needed to build the source package.
  • Build-Conflicts: packages that must not be present during a build.

Use the strongest relationship that accurately represents the requirement. Avoid adding dependencies simply because they are installed on your development machine.

4. Substitution Variables

Debhelper uses variables such as:

1
2
${misc:Depends}
${shlibs:Depends}

${misc:Depends} is commonly included in the Depends field.

${shlibs:Depends} is used when shared-library dependencies are detected by the packaging tools. It is especially relevant to dynamically linked native applications.

Do not add ${shlibs:Depends} mechanically to every package. Use it when the package’s build and dependency analysis require it.

5. Inspect Shared Libraries

For a locally built binary, inspect its dynamic dependencies:

1
ldd ./syspeek

If the binary is statically linked or does not use dynamic shared libraries, the output may say it is not a dynamic executable.

Remember that ldd is an inspection tool for trusted binaries; do not use it casually on untrusted executables.

6. Build Systems and debhelper

Debhelper can integrate with different build systems. The dh sequencer invokes helpers such as dh_auto_configure, dh_auto_build, and dh_auto_install.

Our rules file overrides the build and install steps because the application is intentionally simple:

1
2
3
4
5
override_dh_auto_build:
	CGO_ENABLED=0 go build -trimpath -buildvcs=false -o syspeek .

override_dh_auto_install:
	install -D -m 0755 syspeek debian/syspeek/usr/bin/syspeek

For projects using Make, CMake, Meson, or other build systems, debhelper may be able to detect and drive the build system automatically.

7. Check Build Dependencies

From the source directory:

1
dpkg-checkbuilddeps

This checks whether the build dependencies declared in debian/control are installed.

A clean build environment is especially useful here: it tests whether the declared dependency list is sufficient.

8. What We Learned

We reviewed build and runtime dependencies, common dependency relationships, substitution variables, and debhelper build-system integration.

The key rule is simple: declare actual requirements, not incidental properties of your workstation.

Exercises

  1. Explain why golang-any is a build dependency.
  2. Inspect a dynamically linked executable with ldd.
  3. Find a package that uses ${shlibs:Depends} and inspect its generated dependency list.
  4. Run dpkg-checkbuilddeps in your build environment.

What’s Next?

Next, we will look at installation paths, file permissions, configuration files, and systemd integration. We will also decide which of those features Syspeek genuinely needs.

Next: systemd, Configuration, and Permissions