Rebuild a Pop!_OS package from sources

       429 words, 3 minutes

I don’t like the 50/50 tiling ratio of xfwm. I have cooked a patch to modify that ratio to my likings and already applied it to my OpenBSD local port tree. But the spare laptop runs Pop!_OS. And Debian / Ubuntu based Linux distribution comes with prebuild packages ; and that’s usually great!

Getting and patching the software source to build a custom deb package is quite easy when you have the recipe. And here it is.

Fetch sources & tools

All the following was done on Pop!_OS ; because this is what’s running on that laptop right now. But the directions should work for any Debian derived distro.

Start with getting the package source and its debian-related stuff. Also get the required building environment:

$ apt source xfwm4
Reading package lists... Done
NOTICE: 'xfwm4' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/xfce-team/desktop/xfwm4.git
Please use:
git clone https://salsa.debian.org/xfce-team/desktop/xfwm4.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 1214 kB of source archives.
Get:1 http://apt.pop-os.org/ubuntu jammy/universe xfwm4 4.16.1-1 (dsc) [1908 B]
Get:2 http://apt.pop-os.org/ubuntu jammy/universe xfwm4 4.16.1-1 (tar) [1202 kB]
Get:3 http://apt.pop-os.org/ubuntu jammy/universe xfwm4 4.16.1-1 (diff) [10.4 kB]
Fetched 1214 kB in 0s (30.5 MB/s)

$ /bin/ls -1d xfwm*
xfwm4-4.16.1
xfwm4_4.16.1-1.debian.tar.xz
xfwm4_4.16.1-1.dsc
xfwm4_4.16.1.orig.tar.bz2

$ sudo apt-get build-dep xfwm4

Patch & build

From now, get into the source tree. Make the changes you want. And finally build the Debian package:

$ cd xfwm4-4.16.1/
$ cp -p ./src/client.c ./src/client.c.orig
$ vi ./src/client.c
(...)
$ diff -u2 ./src/client.c.orig ./src/client.c \
  > ~/patch-xfwm4_4.16.1-src_client_c.diff

$ dpkg-buildpackage -rfakeroot -uc -b
dpkg-buildpackage: info: source package xfwm4                                                        
dpkg-buildpackage: info: source version 4.16.1-1  
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Yves-Alexis Perez <corsac@debian.org>
dpkg-buildpackage: info: host architecture amd64  
 dpkg-source --before-build .                                                                        
 debian/rules clean
(...)
dpkg-deb: building package 'xfwm4' in '../xfwm4_4.16.1-1_amd64.deb'.
dpkg-deb: building package 'xfwm4-dbgsym' in 'debian/.debhelper/scratch-space/build-xfwm4/xfwm4-dbgsym_4.16.1-1_amd64.deb'.
        Renaming xfwm4-dbgsym_4.16.1-1_amd64.deb to xfwm4-dbgsym_4.16.1-1_amd64.ddeb
 dpkg-genbuildinfo --build=binary -O../xfwm4_4.16.1-1_amd64.buildinfo
 dpkg-genchanges --build=binary -O../xfwm4_4.16.1-1_amd64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
 dpkg-source --after-build .
dpkg-buildpackage: info: binary-only upload (no source included)

$ /bin/ls -1d ../
../xfwm4-4.16.1
../xfwm4-dbgsym_4.16.1-1_amd64.ddeb
../xfwm4_4.16.1-1.debian.tar.xz
../xfwm4_4.16.1-1.dsc
../xfwm4_4.16.1-1_amd64.buildinfo
../xfwm4_4.16.1-1_amd64.changes
../xfwm4_4.16.1-1_amd64.deb
../xfwm4_4.16.1.orig.tar.bz2

Install & run

Time has come to install the new patched package:

$ sudo dpkg -i ../xfwm4_4.16.1-1_amd64.deb
(Reading database ... 384562 files and directories currently installed.)
Preparing to unpack xfwm4_4.16.1-1_amd64.deb ...
Unpacking xfwm4 (4.16.1-1) over (4.16.1-1) ...
Setting up xfwm4 (4.16.1-1) ...
Processing triggers for bamfdaemon (0.5.6+22.04.20220217-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for man-db (2.10.2-1) ...

And this is all about it! Happy patching && packaging.