Pbuilder Compilation Build Tool use detailed introduction

Source: Internet
Author: User
Tags file permissions root directory

1. Introduction

Pbuilder (personal Debian Package builder) is a professional tool for maintaining Debian packages in the Ubuntu environment, creating a clean build environment for each Deb package, automatically parsing and installing dependency packs, and not polluting the host system.

2. Using the Pbuilder process

(1) Create a pure build environment with pbuild creation, and you can specify the version of the Debian environment you want to simulate by using parameters

(2) Download the SRC package of the target Deb package using Apt-get source

(3) Use Pbuilder build to compile target source package, parameter is the DSC file of SRC Package

(4) Go back to step (2) and continue compiling more packages

3. Main functions of Pbuilder (excerpt from manual page)

(1)--create

Create a compiled build environment for the specified Debian release, which will eventually be packaged as base.tgz.

(2)--update

Update base.tgz.

(3)--build

Compiles the specified source package and specifies the source package by passing in the dsc-file.

(4)--clean

Clears the contents of Buildplace and Aptcache.

(5)--login

Chroot (ie login) to build the compilation environment. It should be noted that the exit will be automatically clean after the user all operations will not be saved, so this command is for debugging purposes only.

(6)--excute

First login to the build environment, and then execute the specified program. The path to the target program needs to be specified in the parameter, which is replicated to the build environment for execution.

(7)--debuild

In the Debian source directory (that is, the unpacked Debian source package), the source package is compiled, and the debian/directory is required in the current directory. Pbuilder--debuild is equivalent to Pdebuild.

4. Principle of Pbuilder

(1) Related documents

Pbuilder related scripts have/usr/sbin/pbuilder,/usr/lib/pbuilder/*,/usr/bin/pdebuild.

The associated temp directory is/var/cache/pbuilder.

Pbuilder variables such as Buildplace, mirrorsite,buildresult, distribution, etc. are defined in the configuration file, which have/etc/pbuilder/*,/usr/share/ PBUILDER/PBUILDERRC,/ETC/PBUILDERRC, ~/. PBUILDERRC. The Pbuilder-loadconfig scripts show that these files are prioritized in order to increase:/usr/share/pbuilder/pbuilderrc</ETC/PBUILDERRC < ~/. PBUILDERRC, that is, the former configuration can be covered by the latter, and finally, all parameters can be overridden by command-line arguments.

(2) The entity of the Pbuilder create command is pbuilder-createbuildenv.

It creates a root environment that simulates the specified Debian release. The root directory is packaged in buildplace/base.tar.gz and can be reused when you compile the Deb package.

(2.1) The script first creates the underlying root directory of the Debian system and installs the basic Deb package, which is actually done with the help of Debootstrap. The root directory environment is placed in the buildplace.

You can customize the Debian system created by the Debootstrap, such as--arch=arch to specify the target architecture,--include=packages specify the additional download installation package,--variant=minbase| Buildd|fakechroot|scratchbox can specify the bootstrap script used, different scripts created by different Debian environment, the main difference is installed Deb package is different, the default is Minbase, if you want to create a compilation build environment, the general selection Buildd. Debootstrap currently supported Debian system distributions see http://neuro.debian.net/pkgs/debootstrap.html

(2.2) Copy some important configuration files (hosts, hostname, resolv.conf) to the target environment, create and configure/etc/apt, add apt keyring to the target environment.

(2.3) Chroot to the target environment, mount the directory required for the runtime, such as/proc,/dev/,/dev/pts,/selinux, and user-specified directories that require the bind mount.

(2.4) in the target environment, perform apt-get update and install Build-essential,dpkg-dev and other packages.

(2.5) The runtime directory that is mounted before unloading.

(2.6) Package the Buildplace as base.tgz.

When errors occur in each of these steps, the buildplace is emptied to avoid polluting the host system.

(3) The entity of the Pbuilder build is pbuilder-buildpackage.

It creates a temporary compilation build environment based on existing base.tgz, and compiles the source package in this environment.

(3.1) The script first extracts the base.tgz into the temporary directory Buildplace, copies the important configuration files in the host system, if the user specifies to overwrite the default apt source, reconfigure the/ETC/APT in the temporary environment, and then mount the runtime directory for/Proc.

(3.2) Create temporary directories and files, such as Buildresult,pbuilder_build_logfile, required at compile time.

(3.3) chroot check and install the dependent packages required for the compiled source package, the user-specified additional packages.

Check and install the work of the dependent package, completed through the Pbuilder-satisfydepends script. By parsing the build-depends, BUILD-DEPENDS-INDEP, BUILD-CONFLICTS,BUILD-CONFLICTS-INDEP and other regions in the DSC file, the script gets the dependency and conflict packets needed to compile the target source package, Using this information, an empty Deb package pbuilder-satisfydepends-dummy is created, and aptitude install is used to install the Dunmmy package, which resolves the problem of dependency packs and conflict packs.

(3.4) According to the parameters in the Dsc-file, copy the source file to the temporary environment (that is, BUILDPLACE/TMP/BUILDD), and modify file permissions, and if the user specified Inputfile, then copied in. Finally chroot to the temporary environment, extract the source package.

(3.5) Call the Dpkg-buildpackage compiled source package in a chroot manner.

(3.6) Unloading the contents of the runtime.

(3.7) Copy the compiled Deb package from BUILDPLACE/TMP/BUILDD to Buildresult, and the default is/var/cache/pbuilder/result/.

(3.8) Clear buildplace.

5. Pbuilder Use examples

(1) Installation Pbuilder

sudo apt-get installpbuilder debootstrap devscripts

(2) Configure the source used by Pbuilder

echo "Mirrorsite=http://192.168.0.123/ubuntu" >>/ETC/PBUILDERRC

(3) Create a compilation environment

The easiest way to do this is to:

sudo pbuilder Create

At this point, Pbuilder creates a compilation environment using the default parameters in PBUILDERRC.

You can also customize by command line parameters:

sudo pbuilder create--distribution raring--debootstrapopts--arch=amd64--debootstrapopts--variant=buildd

The Ubuntu raring compilation environment for the AMD64 schema is created.

(4) Download and compile the source package

To compile BC, for example, the easiest way to do this is to:

Apt-get source-d BC

sudo pbuilder BUILDBC_1.06.95-4UBUNTU1.DSC

Can also manually unpack the source code, into the source directory compiled:

Apt-get source-d BC

Dpkg-source-xbc_1.06.95-4ubuntu1.dsc

CD bc-1.06.95

sudo pdebuild

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.