Creating Debian packages
========================
-A simple method to create the debian package is the following:
+Simple method
+-------------
+
+A simple method to create a native Debian package is the following:
apt install build-essential cmake ninja-build python3
make create-orig-tgz
dpkg-buildpackage -uc -us
-To create the package for different distribution and/or architecture
-sbuild is recommended. Setup the sbuild chroot as documented at
-https://wiki.debian.org/sbuild. Then run:
+Sbuild method - native
+----------------------
+
+You can also use the sbuild tool to create the native package. The
+advantage is that the build happens in a clean environment, ensuring
+that only distribution-provided packages are used for building.
+
+Setup the sbuild chroot as documented at
+https://wiki.debian.org/sbuild and then build the package with:
make create-orig-tgz
sbuild
-To cross-build the package for different architecture, first install
+Sbuild method - cross
+---------------------
+
+Cross-compilation for different architecture is more complex,
+especially in case of Ubuntu Xenial. Se let's start with simpler
+variant - Debian Stretch.
+
+### Debian Stretch ###
+
+For Debian Stretch, setup the chroot as above and install
qemu-user-static to both your host system and the build chroot:
sudo apt-get install qemu-user-static
sbuild-apt <chroot-name> apt-get install qemu-user-static
-Then build the package:
+Then build the package with:
make create-orig-tgz
sbuild --host=arm64
+
+### Ubuntu Xenial (TX2) ###
+
+Setup the chroot as above. Ubuntu Xenial does not have
+qemu-user-static package so copy the static binaries from your host:
+
+ sudo apt-get install qemu-user-static
+ cp /usr/bin/qemu-aarch64-static /path/to/your/chroot/xenaial/usr/bin
+
+Then modify /etc/apt/sources.list to contain the URL of arm64 package
+repository. This is the sources.list that I use:
+
+ deb [arch=amd64] http://cz.archive.ubuntu.com/ubuntu xenial main universe
+ deb-src http://cz.archive.ubuntu.com/ubuntu/ xenial main universe
+
+ deb [arch=arm64] http://ports.ubuntu.com/ xenial main universe
+
+Furthermore, Xenial has too old packages to cross build LLVM. For that
+reason, we backport the following packages: `cmake_3.7.2-1` from
+Debian Stretch and `ninja-build_1.8.2-1` from Debian unstable. Just
+download the corresponding source packages (from e.g.
+https://packages.debian.org/source/stretch/cmake) and run
+
+ sbuild -d xenial cmake_3.7.2-1.dsc
+ sbuild -d xenial ninja-build_1.8.2-1.dsc
+
+Then install the created packages into the xenial chroot.
+
+Then build the package by
+
+ make create-orig-tgz
+ sbuild --host=arm64 -d xenial --add-depends="libc6-dev, libstdc++-5-dev" --build-failed-commands='%s'
+
+The `--build-failed-commands` switch ensures that a shell is run if
+the build fails to allow investigating the problem.