2023-09-23

How to build a Debian metapackage for personal use

I don't like having lots of manually installed packages that I'm not sure I need on my Debian system. One way I get such packages is when I'm compiling software such as FreeCad, and I install the build dependencies with a command like the one that is listed here. (That command doesn't actually work on Debian unstable, I got my list of packages to install from here.) When you run a command like that, all those packages are marked as manually installed. I had the idea to build a metapackage that depends on those packages, so if I decide I won't be building FreeCad again I can uninstall the metapackage and if nothing else depends on those packages they can be removed with sudo apt autoremove.

Most of this is based on the packaging intro tutorial on the Debian wiki. Check that out if you want more details. This howto will give just enough information to get this metapackage built, because that is the extent of my experience so far. ;-)

Install the packages you will need

sudo apt install build-essential devscripts debhelper

(Here you might think about building a metapackage for building metapackages. Very meta.)

Make the directory structure and switch into it

mkdir -p ~/deb/build-dependencies/debian/; cd ~/deb/build-dependencies/

In this structure, deb/ will be where the final .deb file will end up. Under that, build-dependencies/ is the package directory, which since this is a metapackage, will be empty except for the debian/ directory, where the package metadata files will go.

Generate a changelog in the right format

dch --create -v 1 --package build-dependencies

The -v 1 switch sets the package version to 1. This will make a debian/changelog file. I got a warning neither DEBEMAIL nor EMAIL environment variable is set. Press Enter to accept the warning and your editor will pop up to edit the created file. You can delete the (Closes: #XXXXXX) bit and edit the last line that has your name and email address if you want. The email address does not need to be valid (since I won't be uploading this to Debian), but there does need to be something there else the package won't build.

The copyright file needs to exist, but it can be empty

touch debian/copyright

Now the interesting file: debian/control

The first part, Source: build-dependencies, is the source package metadata. The second part, Package: freecad-dependencies, is the binary package metadata. The binary package is what you actually install, and you can make more than one binary package from one source package by providing several Package: binary-package-name sections.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Source: build-dependencies
Maintainer: Mark Penner
Section: misc
Priority: optional
Build-Depends: debhelper-compat (= 13)

Package: freecad-dependencies
Architecture: any
Depends: cmake,
         libboost-date-time-dev,
         libboost-dev,
         libboost-filesystem-dev,
         libboost-graph-dev,
         libboost-iostreams-dev,
         libboost-program-options-dev,
         libboost-python-dev,
         libboost-regex-dev,
         libboost-serialization-dev,
         libboost-thread-dev,
         libcoin-dev,
         libdouble-conversion-dev,
         libglew-dev,
         liblz4-dev,
         libopencv-dev,
         libeigen3-dev,
         libgts-bin,
         libgts-dev,
         libkdtree++-dev,
         libmedc-dev,
         libmetis-dev,
         libocct-data-exchange-dev,
         libocct-ocaf-dev,
         libocct-visualization-dev,
         libpyside2-dev,
         libqt5opengl5-dev,
         libqt5svg5-dev,
         libqt5xmlpatterns5-dev,
         libqt5x11extras5-dev,
         libshiboken2-dev,
         libspnav-dev,
         libvtk9-dev,
         libx11-dev,
         libxerces-c-dev,
         libzipios++-dev,
         lsb-release,
         occt-draw,
         pybind11-dev,
         pyqt5-dev-tools,
         pyside2-tools,
         python3-dev,
         python3-matplotlib,
         python3-ply,
         python3-pyside2.qtcore,
         python3-pyside2.qtgui,
         python3-pyside2.qtsvg,
         python3-pyside2.qtuitools,
         python3-pyside2.qtwidgets,
         python3-pyside2.qtxml,
         python3-requests,
         qtbase5-dev,
         qttools5-dev,
         qtwebengine5-dev,
         swig
Description: FreeCad build dependencies
 Metapackage to install dependencies for building FreeCad.

debian/rules is a Makefile with instructions to build the package

1
2
3
#!/usr/bin/make -f
%:
	dh $@

Remember Makefiles use tabs not spaces!

Build the package

debuild

The package will be built and placed in the directory above the one you're in. (deb/freecad-dependencies_1_amd64.deb is the built binary package on my machine.)

Install

Now if all the dependencies are already installed, you can run sudo debi to install the package. It will find the package in the directory above and install it with dpkg. However, dpkg will not install dependencies for you. Since I made this package specifically to install dependencies, I ran sudo apt install ../freecad-dependencies_1_amd64.deb. That installed all the dependencies, and also the dependencies of dependencies.

Celebrate a cleaner manually installed packages list!

If any of those packages were already installed, you can mark them as automatically installed with:

sudo apt-mark auto cmake libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-thread-dev libcoin-dev libdouble-conversion-dev libglew-dev liblz4-dev libopencv-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libmetis-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libpyside2-dev libqt5opengl5-dev libqt5svg5-dev libqt5xmlpatterns5-dev libqt5x11extras5-dev libshiboken2-dev libspnav-dev libvtk9-dev libx11-dev libxerces-c-dev libzipios++-dev lsb-release occt-draw pybind11-dev pyqt5-dev-tools pyside2-tools python3-dev python3-matplotlib python3-ply python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qtsvg python3-pyside2.qtuitools python3-pyside2.qtwidgets python3-pyside2.qtxml python3-requests qtbase5-dev qttools5-dev qtwebengine5-dev swig

Next

Now if when I try to compile FreeCad I need other packages installed, I can just add them to debian/control, build the package again, and reinstall.

Tags: Debian packaging