Arch Build System (日本語)

From ArchWiki
Revision as of 13:21, 17 May 2013 by Kusakata (talk | contribs)
Jump to navigation Jump to search

ro:ABS zh-CN:Arch Build System zh-TW:Arch Build System Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

この記事では Arch Build System の概要と、初心者のためのウォークスルーを提供しています。完全なリファレンスガイドではありません!ABS の簡単な手引きは、ABS FAQ を見て下さい。より詳しい情報が必要な場合は、man ページを参照してください。

Note: ABS の同期は日に一度行われます。そのためリポジトリで利用可能になっているものとラグが生じることがあります。

Arch Build System について

ABS とは Arch Build System の略で、FreeBSD などで採用されている ports に似ています。ABS はソースコードから .pkg.tar.xz 形式のバイナリパッケージを作成することができます。作られたパッケージは pacman によって、通常の(配布されている)バイナリパッケージと同様に管理することができます。

ports システムとは

'Ports' は BSD 系 UNIX によって採用されている、ソースコードからのソフトウェアのビルドを自動化するシステムです。port を使ってソフトウェアのソースコードのダウンロード・展開、パッチの適用、コンパイル、インストールを行います。'port' はただの小さなディレクトリで、それぞれの 'port' に対応する個々のソフト名が付けられており、中にはソフトウェアのビルド・インストールのための情報が書かれたファイルが入っています。ソフトウェアをインストールしたい時は、port のフォルダまで移動し make もしくは make install clean と入力するだけでパッケージのダウンロードからコンパイル、インストールまでを自動的に行います。

ABS の特徴

ABS も Ports に似たシステムで、/var/abs ディレクトリ下に、カテゴリ - パッケージ名の順番で、ツリー状のフォルダ群 (ABS ツリー) を保存しています。これには Arch Linux の公式ソフト すべてのパッケージが含まれます (Ports と同様に、ソースコードやバイナリパッケージを含んでいないのでサイズはそんなに大きくありません)。パッケージ名 (例えば、'ABS') のフォルダを開いたとします。すると、中にはソフトウェアパッケージやソースはなく、代わりに PKGBUILD というファイルが含まれています。PKGBUILD は簡潔な Bash スクリプトで、ソースコードのダウンロード元や、コンパイル、パッケージ作成に必要なコマンドが記述してあります。ABS の makepkg を実行することで、ソフトウェアはコンパイル・パッケージングされビルド用ディレクトリにパッケージが作成されます。後は pacman を使って、ソフトウェアを簡単に管理することが可能です。

ABS の概要

'ABS' という言葉は総称 (umbrella term) として使われることがあります。ABS は複数のものから構成されているからです; そのため、技術的には正確ではありませんが、'ABS' はツールキットとして以下のツールを意味します:

ABS ツリー
The ABS directory structure; an SVN hierarchy under /var/abs/ on your (local) machine. It contains many subdirectories, named for all available official Arch Linux software from repositories specified in /etc/abs.conf, but not the packages themselves. The tree is created after installing the abs package with pacman and subsequently running the abs script.
A Bash script that contains the URL of the source code along with the compilation and packaging instructions.
ABS shell command tool which reads the PKGBUILDs, automatically downloads and compiles the sources and creates a .pkg.tar* according to the PKGEXT array in makepkg.conf. You may also use makepkg to make your own custom packages from the AUR or third-party sources. (See the Creating Packages wiki article.)
pacman is completely separate, but is necessarily invoked either by makepkg or manually, to install and remove the built packages and for fetching dependencies.
The Arch User Repository is separate from ABS but AUR (unsupported) PKGBUILDs are built using makepkg to compile and package up software. In contrast to the ABS tree on your local machine, the AUR exists as a website interface. It contains many thousands of user-contributed PKGBUILDs for software which is unavailable as an official Arch package. If you need to build a package outside the official Arch tree, chances are it is in the AUR.

Why would I want to use ABS?

The Arch Build System is used to:

  • Compile or recompile a package, for any reason
  • Make and install new packages from source of software for which no packages are yet available (see Creating Packages)
  • Customize existing packages to fit your needs (enabling or disabling options, patching)
  • Rebuild your entire system using your compiler flags, "à la FreeBSD" (e.g. with pacbuilder)
  • Cleanly build and install your own custom kernel (see Kernel Compilation)
  • Get kernel modules working with your custom kernel
  • Easily compile and install a newer, older, beta, or development version of an Arch package by editing the version number in the PKGBUILD

ABS is not necessary to use Arch Linux, but it is useful for automating certain tasks of source compilation.

How to use ABS

Building packages using abs consists of these steps:

  1. Install the abs package with pacman.
  2. Run abs as root to create the ABS tree by synchronizing it with the Arch Linux server.
  3. Copy the build files (usually residing under /var/abs/<repo>/<pkgname>) to a build directory.
  4. Navigate to that directory, edit the PKGBUILD (if desired/necessary) and do makepkg.
  5. According to instructions in the PKGBUILD, makepkg will download the appropriate source tarball, unpack it, patch if desired, compile according to CFLAGS specified in makepkg.conf, and finally compress the built files into a package with the extension .pkg.tar.gz or .pkg.tar.xz.
  6. Installing is as easy as doing pacman -U <.pkg.tar.xz file>. Package removal is also handled by pacman.

Install tools

To use the ABS, you first need to install abs from the official repositories.

This will grab the abs-sync scripts, various build scripts, and rsync (as a dependency, if you do not already have it).

Before you can actually build anything, however, you will also need basic compiling tools. These are handily collected in the package group base-devel. This group can be installed with pacman.


As root, edit /etc/abs.conf to include your desired repositories.

Remove the ! in front of the appropriate repositories. For example:

REPOS=(core extra community !testing)

ABS tree

The ABS tree is an SVN directory hierarchy located under /var/abs and looks like this:

| -- core/
|     || -- acl/
|     ||     || -- PKGBUILD
|     || -- attr/
|     ||     || -- PKGBUILD
|     || -- abs/
|     ||     || -- PKGBUILD
|     || -- autoconf/
|     ||     || -- PKGBUILD
|     || -- ...
| -- extra/
|     || -- acpid/
|     ||     || -- PKGBUILD
|     || -- apache/
|     ||     || -- PKGBUILD
|     || -- ...
| -- community/
|     || -- ...

The ABS tree has exactly the same structure as the package database:

  • First-level: Reposistory name
  • Second-level: Package name directories
  • Third level: PKGBUILD (contains information needed to build a package) and other related files (patches, other files needed for building the package)

The source code for the package is not present in the ABS directory. Instead, the PKGBUILD file contains a URL that will download the source code when the package is built. So the size of abs tree is quite small.

Download ABS tree

As root, run:

# abs

Your ABS tree is now created under /var/abs. Note the appropriate branches of the ABS tree now exist and correspond to the ones you specified in /etc/abs.conf.

The abs command should be run periodically to keep in sync with the official repositories. Individual ABS package files can also be downloaded with:

# abs <repository>/<package>

This way you do not have to check out the entire abs tree just to build one package.


/etc/makepkg.conf specifies global environment variables and compiler flags which you may wish to edit if you are using an SMP system, or to specify other desired optimizations. The default settings are for i686 and x86_64 optimizations which will work fine for those architectures on single-CPU systems. (The defaults will work on SMP machines, but will only use one core/CPU when compiling -- see makepkg.conf.)

Set the PACKAGER variable in /etc/makepkg.conf

Setting the PACKAGER variable in /etc/makepkg.conf is an optional but highly recommended step. It allows a "flag" to quickly identify which packages have been built and/or installed by YOU, not the official maintainer! This is easily accomplished using expac available from the community repo:

Showing All Packages (including those from AUR)
$ grep myname /etc/makepkg.conf
PACKAGER="myname <>"
$ expac "%n %p" | grep "myname" | column -t
archey3 myname
binutils myname
gcc myname
gcc-libs myname
glibc myname
tar myname
Showing Only Packages Contained in Repos

This example only shows packages contained in the repos defined in /etc/pacman.conf:

$ . /etc/makepkg.conf; grep -xvFf <(pacman -Qqm) <(expac "%n\t%p" | grep "$PACKAGER$" | cut -f1)

Create a build directory

It is recommended to create a build directory where the actual compiling will take place; you should never modify the ABS tree by building within it, as data will be lost (overwritten) on each ABS update. It is good practice to use your home directory, though some Arch users prefer to create a 'local' directory under /var/abs/, owned by a normal user.

Create your build directory. e.g.:

$ mkdir -p $HOME/abs

Copy the ABS from the tree (/var/abs/<repository>/<pkgname>) to the build directory.

Build package

In our example, we will build the slim display manager package.

Copy the slim ABS from the ABS tree to a build directory:

$ cp -r /var/abs/extra/slim/ ~/abs

Navigate to the build directory:

$ cd ~/abs/slim

Modify the PKGBUILD to add or remove support for components, to patch or to change package versions, etc. (optional):


Run makepkg as normal user (with -s switch to install with automatic dependency handling):

$ makepkg -s
Note: Before complaining about missing (make) dependencies, remember that the base group is assumed to be installed on all Arch Linux systems. The group "base-devel" is assumed to be installed when building with makepkg. See #Install tools.

Install as root:

# pacman -U slim-1.3.0-2-i686.pkg.tar.xz

That's it. You have just built slim from source and cleanly installed it to your system with pacman. Package removal is also handled by pacman with pacman -R slim.

The ABS method adds a level of convenience and automation, while still maintaining complete transparency and control of the build and installation functions by including them in the PKGBUILD.


Essentially, the same steps are being executed in the traditional method (generally including the ./configure, make, make install steps) but the software is installed into a fake root environment. (A fake root is simply a subdirectory within the build directory that functions and behaves as the system's root directory. In conjunction with the fakeroot program, makepkg creates a fake root directory, and installs the compiled binaries and associated files into it, with root as owner.) The fake root, or subdirectory tree containing the compiled software, is then compressed into an archive with the extension .pkg.tar.xz, or a package. When invoked, pacman then extracts the package (installs it) into the system's real root directory (/).