Arch Build System (正體中文)

From ArchWiki
Revision as of 16:47, 14 December 2008 by Byte (talk | contribs) (/etc/abs/abs.conf: rm all traces of [unstable])
Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Arch Build System (正體中文)#)

ABS 是什麼?

ABS (Arch Build System),Arch 構建系統。它是一套像(BSD)Ports 一樣的體系,能從 source(源代碼) 來構建一個軟件。Pacman 是 Arch 下特定的二進制安裝包管理工具(也包括管理那些從 ABS 構建的二進制安裝包),而 ABS 則是 Arch 下特定的編譯工具,將源代碼編譯為一個可供安裝的 .pkg.tar.gz 包。

什麼是像(BSD)Ports 一樣的體系?

'Ports' 體系被用於 FreeBSD (和其它 BSD 作業系統),它允許下載,解包,修補,編譯和安裝source(源代碼) 包。 'port' 僅僅是用戶電腦上,以要安裝的相應軟件來命名的一個小目錄,它包含一些文件,以指導從軟體的來源處下載安裝一個包,一般都是找到那個目錄/port,然後依次用命令 "make" 和 “make install”,'Ports' 體系就會開始下載,編譯和安裝那個軟體了。

ABS 的概念與之相似

ABS 是由目錄樹組成(ABS Tree),位於 /var/abs 之下,包含了不少子目錄。這些子目錄都在某個類別裡面,並分別以其安裝包的名字來命名。你可以將這些以安裝包的名字來命名子目錄,稱為 'ABS',就如同這樣稱呼 'port' 一樣。這些 ABS,或子目錄,並不包含軟體安裝包,也沒有它們的源代碼,而是含有一個 PKGBUILD 文件 (有時也含有其它一些文件)。 PKGBUILD 是一個簡單的文本文件,含有編譯與打包的指令,也含有下載適當源碼包的URL地址。 ABS 體系中最重要的組成部分就是 PKGBUILDs 了。


Running 'abs' as root creates the ABS tree. If you wanted to build nano from source, for instance, you would copy /var/abs/core/base/nano to a build directory, navigate to the build directory and do makepkg. It's as simple as that. Makepkg will attempt to read and execute the instructions contained within the PKGBUILD. The source tarball will automatically be downloaded, unpacked, compiled according to CFLAGS specified in /etc/makepkg.conf, and finally squeezed into a package with the extension .pkg.tar.gz, as per the instructions in the PKGBUILD. Installing is as easy as doing pacman -U nano.pkg.tar.gz. Package removal is also handled by pacman.

The PKGBUILD and other files may, of course, be customized to suit your needs, and you may choose to use the ABS makepkg function to make your own custom packages from sources outside the ABS tree itself. (See the prototype PKGBUILD and install files under /var/abs/core/)

With the ABS Tree in place, an Arch user has all available Arch packages at their fingertips, to compile from source.



  • You may also use the pacman makepkg tool, in conjunction with your own custom PKGBUILDs to create packages for yourself, or to share with the community. Again, the resulting foo.pkg.tar.gz packages are cleanly installable with pacman.
  • ABS tools allow you to utilize the AUR, or Arch User Repository, which is full of pre-written PKGBUILDs for your convenience.

ABS 系統的概況

'ABS' may be used as an umbrella term, since it includes and relies on several other components. Therefore, though not technically accurate, 'ABS' can refer to the following structure and tools as a complete toolkit:

  • The ABS tree: The ABS directory structure under /var/abs/. It contains many subdirectories, named for all available Arch software packages, but not the packages themselves.
  • ABS: The actual directories named for the buildable software and containing the PKGBUILD.
  • PKGBUILDs: Text files residing under the ABS directories, with instructions for building packages and the URL of the sources.
  • The AUR: The Arch User Repository. The AUR contains user-contributed PKGBUILDs for software which may be unavailable as an official Arch package.
  • makepkg: Shell command which reads the PKGBUILDs, compiles the sources and creates a .pkg.tar.gz.
  • Pacman: Pacman is completely separate, but is necessarily invoked either by makepkg or manually, to install and remove the built packages, and for fetching dependencies.

我為什么要用到 ABS?

The Arch Build System (ABS for short) is used to

  • Make new packages from source, of software for which no packages are yet available (See The Arch package making HOW-TO - with guidelines)
  • Build and share these custom packages via the AUR
  • Customize existing packages to fit your needs (enabling or disabling options)
  • Rebuild your entire system using your compiler flags, "a la FreeBSD"
  • Cleanly build and install your own custom kernel. (See Kernel Compilation)
  • Get kernel modules working with your custom kernel.

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

This how-to tries to give you an overview of ABS and Arch packages; it's not a complete reference guide! If you want more, you should try to read the man pages.


To use abs, you first need to install abs from the core repository; this can be done simply by:

pacman -Sy abs

This will grab any necessary dependencies.


edit /etc/abs.conf to include your desired repositories:

nano /etc/abs.conf

Remove the ! in front of the appropriate repos, e.g.:

REPOS=(core extra community !testing)

創建 ABS 樹

As root, do:


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/abs.conf.

The abs command should also be used to periodically sync and update your ABS Tree.


Edit /etc/makepkg.conf to specify environment variables and CFLAGS:

nano /etc/makepkg.conf


When you run abs for the first time, it synchronizes the ABS tree with the Arch server using the cvs system. So what exactly is the ABS tree? It is located under /var/abs and looks like this:

| -- core/
|     ||-- autoconf/
|     ||-- automake/
|     ||-- ...
| -- devel/
| -- ...
| -- extra/
|      || -- daemons/
|      ||      || -- acpid/
|      ||      ||      || -- PKGBUILD
...    ...    ...    ...

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

  • first-level directory represents categories
  • second-level directories represents the ABS themselves, whose names actually correspond to the packages you want to build
  • PKGBUILD files contain all information needed concerning the package
  • Further, an ABS directory can contain patches and/or other files needed for building the package.

It is important to understand that the actual source code for the package is not present in the ABS directory. Instead, the PKGBUILD file contains a URL from which ABS will automatically download from.


You must create a build directory, where the actual compiling will take place. This is where you'll do everything; you should never modify the ABS Tree by building within it. It is good practice to use your home directory, though some Arch users prefer to create a 'local' directory under /var/abs/, owned by normal user. Copy the ABS from the tree (var/abs/branch/category/pkgname) to the build directory, /path/to/build/dir.

Create your build directory. e.g.:

mkdir /home/yourusername/abs/local

NOTE: The first download of the abs tree is the biggest, then only minor updates are needed, so don't be afraid about the data to download if you've got only a 56k connection; it's only text files and is compressed during the transfer.

Now that you know what the ABS tree is, how can we use it ?


If you're not familiar with compiling from source, you should know that most packages (but not all) can be built from source in this traditional way:

  • Download source tarball from remote server, using web browser, ftp, wget or alternate method.
  • decompress the source file:
  tar -xzf foo-0.99.tar.gz
  tar -xjf foo-0.99.tar.bz2
  • enter the directory
cd foo-0.99
  • configure the package: generally, there is a little script called configure in the source directory that is used to configure the package (add or remove support for things, choose the install destination, etc.) and check that your computer has all the software needed by the package. It can be run by:
./configure [[option]]

You should first try the help to better understand how it works:

./configure --help

If a --prefix option is not passed to the script, most scripts will use /usr/local as the install path, but others will use /usr. For the sake of consistency, it is generally advised to pass the --prefix=/usr/local option. It is good practice to install personal programs in /usr/local, and to have the ones being managed by the distro, in /usr. This ensures personal program versions can coexist with those being managed by the distro's package manager- in Arch's case, pacman.

./configure --prefix=/usr/local
  • compile the sources:
  • install
make install
  • Uninstalling would be accomplished by entering the source directory and running:
make uninstall

However, you should always read the INSTALL file to know how the package should be built and installed! Not all packages use the configure; make; make install system!

The above traditional method of compiling source tarballs can, of course, still be used on Arch Linux, but ABS offers a streamlined, simple, and elegant alternative, as you shall see.

構建軟體功能,ABS 之道

ABS is an elegant tool which allows for powerful assistance and customization for the build process, and creates a package file for installation. The ABS method involves copying an ABS from the Tree to a build directory, and doing makepkg. In our example, we will build the slim display manager package.

  • 1. Copy the slim ABS from the Tree to a build directory.
cp -r /var/abs/extra/x11/slim /home/yourusername/abs/local
  • 2. Navigate to the build directory
cd /home/yourusername/abs/local/slim
  • 3. Do makepkg, which will automatically download the source tarball, unpack, compile, and create foo.pkg.tar.gz The -i option invokes pacman to automatically install the resulting slim.pkg.tar.gz package file
makepkg -i

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- (pacman -R slim)

Alternatively, you may do makepkg without the -i option, and manually install with pacman by doing:

 pacman -U slim.pkg.tar.gz
  • 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.

See ABS PKGBUILD Explained for a complete overview of a sample PKGBUILD.

更多 ABS 相關資訊