sudo mkdir -pv /var/lib/debbuild/aarch64/root
sudo debootstrap --arch arm64 byzantium /var/lib/debbuild/aarch64/root
sudo mount --bind /dev /var/lib/debbuild/aarch64/root/dev
sudo mount --bind /proc /var/lib/debbuild/aarch64/root/proc
sudo mount --bind /sys /var/lib/debbuild/aarch64/root/sys
mkdir -pv ~/Documents/dev/packages
sudo mkdir -pv /var/lib/debbuild/aarch64/root/var/lib/packages
sudo mount --bind ~/Documents/dev/packages \
/var/lib/debbuild/aarch64/root/var/lib/packages
-
To rebuild existing Debian packages, I had to add
deb-src
entries to my/etc/apt/sources.list
. -
As an exercise, I’ve tried rebuilding the
glibc
package as is. However, just cloninghttps://salsa.debian.org/glibc-team/glibc.git
isn’t enough, because the upstream sources are missing.
-
Setting up a clean chroot for package testing is actually manageable. For the necessary steps, see the 2023-09-07 entry. I can now test packages like so:
sudo mount --bind ~/Documents/dev/packages \ /var/lib/debbuild/aarch64/root/var/lib/packages sudo chroot /var/lib/debbuild/aarch64/root
-
To recreate (i.e. reset) a Debian source package, remove the source package directory, then run:
dpkg-source --extract DSC_FILE
-
To record a patch, go to the source package directory, then run:
dpkg-source --commit . foo.patch
This will create a
debian/patches/foo.patch
file and add it todebian/patches/series
.
Learning to modify Debian source packages and to add and backport patches. My findings:
-
It’s helpful to embrace, and get familiar with,
quilt
.man quilt
has proved extremely helpful. -
It’s essential to read and understand
man dpkg-source
, especially the--extract
and--build
commands and the entireFormat: 3.0 (quilt)
section. -
Mental model for
quilt
and for working with source packages: it’s not unlike Git. Thedebian
directory is like a repository, the.pc
directory is a little like an index, and the rest is just a working tree. -
Working with a source package has several stages:
-
Extracting. Materializes the working tree and the
debian
directory. May apply some or all patches, but that’s not too important.
Command line:dpkg-source --extract glibc-widevine_*.dsc
-
Doing the actual work. For example, step through the patches, add new patches, and refresh patches.
Command lines:quilt {applied,top,next,push,pull,new,import,refresh}
-
Building. Takes the current state of the
debian
directory and rolls it into a source package, i.e. a set of tarballs.
Command line:dpkg-source --build .
-
-
The state of the working tree is not too important.
My first attempt at building a forked Debian package named
libc6-widevine
, derived from libc6
, failed with the following
error message:
dpkg-deb: building package 'locales' in '../locales_2.31-13+deb11u6_all.deb'.
touch /media/sdcard/home/purism/Documents/dev/packages/glibc-widevine-2.31/stamp-dir/binaryinst_locales
Running debhelper for libc6
dh_testroot
dh_installdirs -plibc6
dh_installdirs: error: Requested unknown package libc6 via -p/--package, expected one of: libc-bin libc-dev-bin libc-devtools libc-l10n glibc-doc glibc-source locales locales-all nscd libc6-widevine libc6-dev-widevine libc6-dbg-widevine libc6-udeb-widevine libc6.1-widevine libc6.1-dev-widevine libc6.1-dbg-widevine libc6.1-udeb-widevine libc0.3-widevine libc0.3-dev-widevine libc0.3-dbg-widevine libc0.3-udeb-widevine libc0.1-widevine libc0.1-dev-widevine libc0.1-dbg-widevine libc0.1-udeb-widevine libc6-i386 libc6-dev-i386 libc6-sparc libc6-dev-sparc libc6-sparc64 libc6-dev-sparc64 libc6-s390 libc6-dev-s390 libc6-amd64 libc6-dev-amd64 libc6-powerpc libc6-dev-powerpc libc6-ppc64 libc6-dev-ppc64 libc6-mips32 libc6-dev-mips32 libc6-mipsn32 libc6-dev-mipsn32 libc6-mips64 libc6-dev-mips64 libc0.1-i386 libc0.1-dev-i386 libc6-x32 libc6-dev-x32 libc6-xen libc0.3-xen libc6.1-alphaev67
dh_installdirs: error: unknown option or error during option parsing; aborting
make: *** [debian/rules.d/debhelper.mk:18: /media/sdcard/home/purism/Documents/dev/packages/glibc-widevine-2.31/stamp-dir/binaryinst_libc6] Error 25
dpkg-buildpackage: error: fakeroot debian/rules binary subprocess returned exit status 2
debuild: fatal error at line 1182:
dpkg-buildpackage -us -uc -ui -i -b failed
The failing line in debian/rules.d/debhelper.mk
says:
dh_install -p$(curpass)
After I tried to fix the problem, Lintian found the following issues:
E: glibc-widevine changes: changed-by-invalid-for-derivative Claudia Pellegrino <[email protected]> (should use @puri.sm email addresses)
W: locales: debian-news-entry-has-unknown-version 2.7-3
W: locales-all: debian-news-entry-has-unknown-version 2.7-1
W: libc6-dbg-widevine: empty-binary-package
W: libc6-dev-widevine: empty-binary-package
W: libc6-widevine: empty-binary-package
W: libc-bin: maintscript-calls-ldconfig postinst
W: libc6-udeb-widevine udeb: unknown-field libc6-udeb-widevine_2.31-13+deb11u6_arm64.udeb Conflicts
W: glibc-doc: wrong-name-for-upstream-changelog usr/share/doc/glibc-doc/ChangeLog.ports-mips.gz
N: 15 hints overridden (15 warnings); 32 unused overrides
Finished running lintian.
Tried to tighten the feedback loop by building on the Framework laptop:
OS=byzantium
ARCH=x86_64 # or `aarch64` for on-device builds
PKGVER=2.31-13+deb11u8
# Set up Debian
sudo debootstrap --arch amd64 "${OS?}" "/var/lib/debbuild/${OS?}/${ARCH?}/root"
# Set up PureOS (replace with `--arch arm64` for on-device builds)
sudo debootstrap --arch amd64 "${OS?}" \
"/var/lib/debbuild/${OS?}/${ARCH?}/root" https://repo.pureos.net/pureos
sudo mkdir -pv "/var/lib/debbuild/${OS?}/${ARCH?}/root/var/lib/packages"
sudo mount --bind ~/Documents/dev/packages \
"/var/lib/debbuild/${OS?}/${ARCH?}/root/var/lib/packages"
printf '%s %s\n' 'en_US.UTF-8' 'UTF-8' 'de_DE.UTF-8' 'UTF-8' \
| sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" tee /etc/locale.gen
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get install locales
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" /usr/sbin/locale-gen
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get update
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get install \
bat binutils debian-keyring devscripts equivs git \
git-buildpackage vim packaging-dev quilt
# Check available versions of the binary package
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" rmadison libc6 \
--architecture arm64
printf 'deb-src %s %s %s\n' \
'https://repo.pureos.net/pureos' byzantium main \
| sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" tee \
/etc/apt/sources.list.d/byzantium.src.list
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt update
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" env -C /var/lib/packages \
apt source --download-only glibc
sudo rm -rf "/var/lib/debbuild/${OS?}/${ARCH?}/root/var/lib/packages/glibc-2.31"
mkdir -pv ~/Documents/dev/packages/glibc-2.31
# Modify the following line if there’s no tag yet (use a branch instead)
git -C ~/Documents/dev/packages/glibc-widevine checkout \
"debian/${PKGVER?}+widevinecdm1"
git -C ~/Documents/dev/packages/glibc-widevine archive @ \
| tar -x -C ~/Documents/dev/packages/glibc-2.31
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C /var/lib/packages PATH=/bin:/usr/bin:/sbin:/usr/sbin \
mk-build-deps --install --remove glibc-2.31/debian/control
# Skip the following line if there are no changes in the widevinecdm part
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C /var/lib/packages/glibc-2.31 \
DEBFULLNAME="${DEBFULLNAME}" DEBEMAIL="${DEBEMAIL}" \
EDITOR=/usr/bin/vim dch --local +widevinecdm
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C /var/lib/packages/glibc-2.31 dpkg-source --build .
sudo rm -rf "/var/lib/debbuild/${OS?}/${ARCH?}/root/var/lib/packages/glibc-2.31"
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C /var/lib/packages \
dpkg-source --extract "glibc_${PKGVER?}+widevinecdm1.dsc"
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C /var/lib/packages/glibc-2.31 \
DEB_BUILD_OPTIONS='nocheck parallel=4' debuild -i -us -uc -b
# Install (x86_64)
sudo chroot "/var/lib/debbuild/${OS?}/x86_64/root" \
env -C /var/lib/packages PATH=/bin:/usr/bin:/sbin:/usr/sbin \
dpkg -i libc{6,6-dev,6-dev-i386,6-dev-x32,6-i386,6-x32,-dev-bin}_"${PKGVER?}+widevinecdm1_amd64.deb"
# Install (aarch64)
sudo chroot "/var/lib/debbuild/${OS?}/aarch64/root" \
env -C /var/lib/packages PATH=/bin:/usr/bin:/sbin:/usr/sbin \
dpkg -i libc{6,6-dev,-dev-bin}_"${PKGVER?}+widevinecdm1_arm64.deb"
# Uninstall (x86_64)
sudo chroot "/var/lib/debbuild/${OS?}/x86_64/root" \
env -C /var/lib/packages apt install \
libc{6,6-dev,6-dev-i386,6-dev-x32,6-i386,6-x32,-dev-bin}="${PKGVER?}"
# Uninstall (aarch64)
sudo chroot "/var/lib/debbuild/${OS?}/aarch64/root" env -C /var/lib/packages \
apt install libc{6,6-dev,-dev-bin}="${PKGVER?}"
OS=byzantium
ARCH=x86_64 # or `aarch64` for on-device builds
PKGNAME=funiculi
PKGVER=0.1.3
# Set up Debian
sudo debootstrap --arch amd64 "${OS?}" "/var/lib/debbuild/${OS?}/${ARCH?}/root"
# Set up PureOS (replace with `--arch arm64` for on-device builds)
sudo debootstrap --arch amd64 "${OS?}" \
"/var/lib/debbuild/${OS?}/${ARCH?}/root" https://repo.pureos.net/pureos
sudo mkdir -pv "/var/lib/debbuild/${OS?}/${ARCH?}/root/var/lib/packages/${PKGNAME?}"
sudo mount --bind ~/Documents/dev/"${PKGNAME?}" \
"/var/lib/debbuild/${OS?}/${ARCH?}/root/var/lib/packages/${PKGNAME?}"
printf '%s %s\n' 'en_US.UTF-8' 'UTF-8' 'de_DE.UTF-8' 'UTF-8' \
| sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" tee /etc/locale.gen
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get install locales
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" /usr/sbin/locale-gen
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get update
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get install \
bat binutils debian-keyring devscripts equivs gdebi git \
git-buildpackage vim packaging-dev quilt
# Skip the following command if the `debian` directory already exists
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C "/var/lib/packages/${PKGNAME?}" \
DEBFULLNAME="${DEBFULLNAME}" DEBEMAIL="${DEBEMAIL}" \
dh_make -n -p "${PKGNAME?}_${PKGVER?}"
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C '/var/lib/packages' PATH=/bin:/usr/bin:/sbin:/usr/sbin \
mk-build-deps --install --remove "${PKGNAME?}/debian/control"
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C "/var/lib/packages/${PKGNAME?}" \
DEB_BUILD_OPTIONS='nocheck parallel=4' debuild -i -us -uc -b
# Install
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" \
env -C /var/lib/packages PATH=/bin:/usr/bin:/sbin:/usr/sbin \
gdebi "${PKGNAME?}_${PKGVER?}_all.deb"
# Uninstall
sudo chroot "/var/lib/debbuild/${OS?}/${ARCH?}/root" apt-get remove "${PKGNAME?}"