DeveloperWiki:Building in a Clean Chroot
This article is part of the DeveloperWiki.
Building in a clean chroot prevents missing dependancies in packages, whether due to unwanted linking or packages missing in the depends array in the PKGBUILD. It also allows you to build a package for the stable repositories (core, extra, community) while having packages from [testing] installed on your system.
Setting Up A Chroot
The devtools package provides tools for creating and building within clean chroots. To make a clean chroot, firstly create the directory you want it to reside in. For the purposes of this article this will be called <chrootdir>. The create your chroot using
sudo mkarchroot -C <pacman.conf> -M <makepkg.conf> <chrootdir>/root base base-devel sudo
The -C and -M flags are optional, but it is recommended to provide these with clean pacman.conf and makepkg.conf files (directly from the pacman package) during first creation of clean chroot to ensure lack of user specific adjustments.
Edit the <chrootdir>/root/etc/makepkg.conf file to set the packager name and any makeflags. Also adjust the mirror list in <chrootdir>/root/etc/pacman.d/mirrorlist and enable [testing] in <chrootdir>/root/etc/pacman.conf is wanted.
Building in the Chroot
Firstly, make sure your chroot is up to date with:
sudo mkarchroot -u <chrootdir>/root
Then, to build a package in your chroot run
sudo makechrootpkg -c -r <chrootdir>
The -c flag ensures the chroot is cleaned before building starts.
Handling Major Rebuilds
The cleanest way to handle a major rebuild is to create a new chroot and build your first package (typically the package you are doing the rebuild for). Then create a local repo in you chroot. To do this:
mkdir <chrootdir>/root/repo chmod 777 <chrootdir>/root/repo
The chmod statement allows you to copy package files and create the local repo as your user rather than root.
cp <package> <chrootdir>/root/repo repo-add local.db.tar.gz <package>
Then add the local repo to <chrootdir>/root/etc/pacman.conf
[local] Server = file:///repo
and update your repo
mkarchroot -u <chrootdir>/repo
With every additional package rebuilt, copy the package to the local repo directory, add it to the repo database and update your chroot.