# DebConf18 - Packaging Workshop
###### tags: `Debian packaging workshop`
https://debconf18.debconf.org/talks/141-packaging-workshop/
Author: "[Shih-Yuan Lee (FourDollars)](https://about.me/fourdollars)" <<fourdollars@debian.org>>
License: CC BY-SA 4.0
> This guide is also available under the URL https://bit.ly/debconf18pkg
This quide has two goals:
1 Build binary packages from source package.
2 Generate a debdiff file.
I will use **debhelper** and **ibus-chewing** as examples.
## Prerequisite
`apt install build-essential devscripts pbuilder sbuild ubuntu-dev-tools debhelper quilt`
## Source list format
https://wiki.debian.org/SourcesList
/etc/apt/sources.list
```
deb http://ftp.tw.debian.org/debian/ buster main non-free contrib
deb-src http://ftp.tw.debian.org/debian/ buster main non-free contrib
deb http://security.debian.org/debian-security buster/updates main non-free contrib
deb-src http://security.debian.org/debian-security buster/updates main non-free contrib
```
P.S. This is just an example. Please don't use it in your system.
https://www.debian.org/doc/debian-policy/ch-archive.html#archive-areas
## Download the source packages
`apt source ibus-chewing debhelper` # Download the source packages from the source list.
or
`pull-debian-source ibus-chewing stretch` # Download the source package of ibus-chewing from Debian 9.
P.S. `rmadison ibus-chewing` can check all versions in different releases
### What are the differences for these source packages?
> ibus-chewing-1.5.1/
> ibus-chewing_1.5.1-3.debian.tar.xz
> ibus-chewing_1.5.1-3.dsc
> ibus-chewing_1.5.1.orig.tar.gz
> debhelper-11.3.5/
> debhelper_11.3.5.dsc
> debhelper_11.3.5.tar.xz
https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
### Install the build dependency packages
`apt build-dep ibus-chewing`
or
`mk-build-deps -i -r ibus-chewing`
## Build the binary packages
`fakeroot debian/rules binary`
or
`dpkg-buildpackage -us -uc`
or
`debuild -us -uc`
or
Using [pbuilder](https://tracker.debian.org/pkg/pbuilder), [cowbuilder](https://wiki.debian.org/cowbuilder), [qemubuilder](https://wiki.debian.org/qemubuilder) or [sbuild](https://wiki.debian.org/sbuild) to make a clean environment to build binary packages.
### Use pbuilder-dist from ubuntu-dev-tools
`pbuilder-dist buster amd64 create` # Create the basic chroot environment
`pbuilder-dist buster amd64 build ibus-chewing_1.5.1-3.dsc` # Build the binary packages
> cd ~/pbuilder/buster_result/
> ibus-chewing_1.5.1-3_amd64.build
> ibus-chewing_1.5.1-3_amd64.buildinfo
> ibus-chewing_1.5.1-3_amd64.changes
> ibus-chewing_1.5.1-3_amd64.deb
> ibus-chewing-dbgsym_1.5.1-3_amd64.deb
`pbuilder-dist buster amd64 update` # Update the environment time to time
Troubleshoot
* [Avoiding the "ln: Invalid cross-device link" message](https://www.netfort.gr.jp/~dancer/software/pbuilder-doc/pbuilder-doc.html#lninvalidcrossdevicelink)
### Use mk-build from ubuntu-dev-tools
`mk-sbuild buster` # Create the basic chroot environment
> To CHANGE the golden image: sudo schroot -c source:buster-amd64 -u root
> To ENTER an image snapshot: schroot -c buster-amd64
> To BUILD within a snapshot: sbuild -A -d buster-amd64 PACKAGE*.dsc
> To BUILD for : sbuild -A -d buster-amd64 --host PACKAGE*.dsc
Troubleshoot
> User sylee is not currently an effective member of group sbuild. Please run:
> sudo sbuild-adduser username
> And then either log out and log in again or use `newgrp sbuild` to gain sbuild group privileges
## Make some change for Debian packages
Using `what-patch` to check the patch system.
> ~/ibus-chewing-1.5.1$ what-patch
> quilt
> $ cat ~/.quiltrc
> QUILT_PATCHES="debian/patches"
> QUILT_DIFF_ARGS="--color"
https://wiki.debian.org/debian/patches
### Using quilt to patch the package
`quilt series` # check how many patches
`quilt push -a` # Apply all patches first
`quilt new random.patch` # Add a new patch
`quilt add src/main.c` # Add some file in the patch
`quilt edit src/main.c` # Edit the file, for example, changing _("Chewing") to "DebConf18"
`quilt refresh` # Refresh the patch
`quilt diff` # See differences
`quilt pop -a` # Unapply all patches
### Modify debian/changelog
`dch -i` # Increase version/revision number and edit
`dch -e` # Edit
### Generate source packages
`dpkg-buildpackage -S -us -uc`
### Generate debdiff
`debdiff ibus-chewing_1.5.1-3.dsc ibus-chewing_1.5.1-3.1.dsc > ibus-chewing_1.5.1-3.1.debdiff`
## References
* https://wiki.debian.org/Packaging/Intro
* https://anarc.at/software/debian-development/
* https://www.debian.org/doc/devel-manuals
* [Debian Policy Manual](https://www.debian.org/doc/debian-policy/)
* [Debian Developer's Reference](https://www.debian.org/doc/manuals/developers-reference/index.en.html)