This HOWTO tries to solve the common problems related to package building
- Prevent installing unwanted cruft on your system by doing the build process on a chroot (as a sandboxed, jailed) environment
- Making sure that the package works for other people too who are trying it
- Automatically downloaded dependencies make process smoother
- (Easier to automate larger scale building process and testing)
pbuilder is a tool which is
"used for creating and maintaining chroot environment and building Debian package in the chroot environment".
l'll be doing all the configuration locally only, by overriding the defaults. Another way is to make pbuilder settings to /etc/pbuilderrc
and create your hooks on /etc/pbuilder/hook.d accordingly
Installing
- Install necessary packages
Code:
sudo aptitude install pbuilder devscripts
- Create the pbuilder environment
Code:
sudo pbuilder create
Now we have ready chroot environment for package building using Ubuntu defaults from /etc/pbuilderrc
(You can test environment by doing sudo pbuilder login. Command exit will leave the environment)
- Override the default pbuilder settings
These are the file contents.
Code:
## Overrides /etc/pbuilderrc
# Default distribution
#DISTRIBUTION=feisty
COMPONENTS="main restricted universe multiverse"
# Repositories
MIRRORSITE=http://archive.ubuntu.com/ubuntu
#OTHERMIRROR="deb ${MIRRORSITE} ${DISTRIBUTION}-updates ${COMPONENTS}|deb ${MIRRORSITE} ${DISTRIBUTION}-security ${COMPONENTS}"
# For build results
BUILDRESULT=${HOME}/pbuilder/result
# Hooks for chroot environment
HOOKDIR=${HOME}/pbuilder/hook.d
# Mount directories inside chroot environment
BINDMOUNTS=${BUILDRESULT}
# Bash prompt inside pbuilder
export debian_chroot="pbuild$$"
# For D70results hook
export LOCALREPO=${BUILDRESULT}
# Always include source package
#DEBBUILDOPTS="-sa"
- Create a hook that allows to include local packages as dependencies. This feature is ofter necessary
when the package you're building depends on other package(s) which is not found on Ubuntu repositories.
Code:
mkdir -p ~/pbuilder/result
mkdir ~/pbuilder/hook.d
nano ~/pbuilder/hook.d/D70results
These are the file contents
Code:
#!/bin/sh
echo "Executing hook: $0"
cd ${LOCALREPO}
dpkg-scanpackages . /dev/null > Packages
echo "deb file:${LOCALREPO} ./" >> /etc/apt/sources.list
apt-get update
This code block creates a list of the packages in ${LOCALREPO} folder for APT to use as repository.
Hook is always executed inside the chroot environment before the build phase, and packages are available
for APT to use on dependency resolving.
- Make the hook file executable
Code:
chmod +x ~/pbuilder/hook.d/D70results
- Update the chroot environment, so that new modules (repositories) are included too.
(Also, If you later need to change your chroot environment, use this command)
Code:
sudo pbuilder update --override-config
Building packages
- Building the packages should be as easy as
Code:
mkdir -p ~/packages/mypackage
cd ~/packages/mypackage
apt-get source mypackage
Then either
Code:
sudo pbuilder build mypackage_x.x.x.dsc
or
Code:
cd mypackage-x.x.x
pdebuild --use-pdebuild-internal
- Succefully built packages are placed on ${BUILDRESULT} folder
- These packages are also used as dependencies, so if you get weird behaviour when building other packages,
clean the contents of this folder and try again
Updating the base build environment
- You should update the build environment when new updates are released for the base system
Code:
sudo pbuilder update --autocleanaptcache
A real life example: nautilus
Code:
# enable Ubuntu source repositories on /etc/apt/sources.list
mkdir -p ~/packages/nautilus
cd ~/packages/nautilus
apt-get source nautilus
sudo pbuilder build nautilus_2.14.1-0ubuntu9.dsc
#or alternatively do pdebuild --use-pdebuild-internal on nautilus folder
Notes
- Prefer pbuilder instead of pdebuild wrapper
- pbuilder uses .orig.tar.gz and .diff.gz to build the package.
- If you change anything inside the source folder, source package must be rebuilt for pbuilder (or use pdebuild instead).
- To rebuild source package
Code:
dpkg-source -b folder
- /usr/share/doc/pbuilder/examples contains some nice example hooks, especially C10shell which is invoked when something goes wrong on build process.
You can find the build target files in /tmp/buildd. - If you want to pass DEB_BUILD_OPTIONS to pbuilder and you're using sudo, you must prevent reset of certain environment variables. Using visudo, add definition
Code:
Defaults env_keep+="DEB_* BUILD* PATH"
- Default dependency resolution logic using apt-get is quite slow. To make it way more faster, change the resolver to gdebi. Add to your ~/.pbuilderrc
Code:
# use gdebi for dependency resolution
PBUILDERSATISFYDEPENDSCMD=/usr/lib/pbuilder/pbuilder-satisfydepends-gdebi
- pdebuild doesn't support hooks.
- pdebuild ignores BUILDRESULT variable set on /etc/pbuilderrc. You can specify it using --buildresult. see pdebuild man page for details.
- if you want to improve pbuilder's speed, check out package called cowdancer
- Useful way to clean out obsolete packages from pbuilder cache
Code:
sudo pbuilder update --autocleanaptcache
References
[edit]
- Debian version of pbuilder doesn't currently have support for COMPONENTS option
- added OTHERMIRROR to ~/.pbuilderrc. This allows to use additional Ubuntu repositories. Not enabled by default.
If you enable it, use pbuilder update --overrideconfig to make the changes apply - added PBUILDERSATISFYDEPENDSCMD to ~/.pbuilderrc. Makes dependency resolution very fast by using gdebi instead (In Ubuntu package only)