Arch Build System: Unterschied zwischen den Versionen

Aus wiki.archlinux.de
Zeile 90: Zeile 90:
* '''replaces''' : Das neue Paket ersetzt das Alte. In unserem Fall wird <i>mffoo (my first foo)</i> nicht mehr unterstützt und wird durch <i>foo</i> ersetzt.
* '''replaces''' : Das neue Paket ersetzt das Alte. In unserem Fall wird <i>mffoo (my first foo)</i> nicht mehr unterstützt und wird durch <i>foo</i> ersetzt.
* '''backup''' : Dateien, die gesichert werden (als .pacsave), wenn das Programm deinstalliert wird.
* '''backup''' : Dateien, die gesichert werden (als .pacsave), wenn das Programm deinstalliert wird.
* '''install''' : Spezifiziert ein Installationsskript, das im Paket enthalten ist. (Muss sich mit PKGBUILD im selben Ordner befinden)
* '''install''' : Spezifiziert ein Installationsskript, das im Paket enthalten ist. (Muss sich mit PKGBUILD im selben Verzeichnis befinden)
* '''source''' : Die Bezugsquelle des Quelltextes. Kann sowohl ein lokales Paket, als auch ein remote "http" oder "ftp" Paket sein. Der Dateiname wird aus <i>pkgname</i> und <i>pkgver</i> erstellt, damit der Pfad nicht bei jeder neuen Version angepasst werden muss.
* '''source''' : Die Bezugsquelle des Quelltextes. Kann sowohl ein lokales Paket, als auch ein remote "http" oder "ftp" Paket sein. Der Dateiname wird aus <i>pkgname</i> und <i>pkgver</i> erstellt, damit der Pfad nicht bei jeder neuen Version angepasst werden muss.
* '''md5sums''' : MD5 Summen der Quelltexte um beschädigte Dateien auszuschließen.
* '''md5sums''' : MD5 Summen der Quelltexte um beschädigte Dateien auszuschließen.

Version vom 8. August 2006, 17:50 Uhr

Einführung

Das Arch Build System (ABS) wird genutzt um:

  • Neue Pakete für Software zu erstellen, für die noch keine Pakete vorhanden sind
  • Vorhande Pakete an die eigenen Bedürfnisse anzupassen
  • Das komplette System mit eigenen Compiler-flags neuzubauen, "a la gentoo" (Und so Kernel Module mit eigenem Kernel nutzbar machen!)


ABS ist nicht notwendig um Arch Linux zu nutzen, aber es ist nützlich.

Dieses How-To versucht dir eine Übersicht über ABS und Arch Pakete zu geben, es ist keine komplette Referenz! Wenn du mehr willst, solltest du einen Blick in die man-pages werfen.

Vorbereitung

Um ABS zu nutzen, musst du zuerst die Programme "cvsup" und "wget" installieren:

pacman -Sy cvsup wget

Oder, wenn du die Pakete z.B. im Verzeichnis 'foo' gespeichert hast:

cd foo
pacman -A  cvsup-*.pkg.tar.gz  wget-*.pkg.tar.gz

Was ist ein Paket ?

Ein Paket ist eine Datei, die meist foo.pkg.tar.gz genannt ist.

Es ist nicht mehr, als ein gz komprimiertes tar-Archiv, das folgendes enthält:

  • Die zu installierenden Dateien
  • .PKGINFO : enthält alle Metadaten, die pacman für den Umgang mit Paketen, Abhängigkeiten etc. benötigt.
  • .FILELIST : enthält alle Dateien des Archives. Nötig um ein Paket zu deinstallieren oder um ggf. Abhängigkeitskonflikte festzustellen
  • .INSTALL : enthält Befehle, die nach dem Installieren/Upgraden/Deinstallieren ausgeführt werden. (Nur vorhanden, wenn es in PKGBUILD definiert wurde)

Was ist PKGBUILD und was enthält es?

Wie schon gesagt, enthält PKGBUILD die Metadaten über ein Paket. Es ist eine einfache Textdatei, die z.B. so aussehen könnte:

# $Id: PKGBUILD,v 1.12 2003/11/06 08:26:13 dorphell Exp $
# Maintainer: judd <jvinet@zeroflux.org>
# Contributor: Judd Vinet <jvinet@zeroflux.org>
pkgname=foo
pkgver=0.99 # note: if the pkgver had been '0.99-10' then use an underscore. like '0.99_10'
pkgrel=1
pkgdesc="short description of foo"
arch=(i686 x86_64)
url="http://www.foo.org"
groups=
provides=
depends=('qt' 'python')
makedepends=('guile')
conflicts=('yafoo')
replaces=('mffoo')
backup=('etc/foo/foo.conf')
install=('foo.install')
source=(http://www.foo.org/download/$pkgname-$pkgver.tar.gz)
md5sums=('2c0cca3ef6330a187c6ef4fe41ecaa4d35175bee593a7cc7d6205584a94d8625')

build() {
  cd $startdir/src/$pkgname-$pkgver
  ./configure --prefix=/usr
  make || return 1
  make prefix=$startdir/pkg/usr install
}

Erklärung für jede Zeile:

  • # text : Kommentare
  • # $Id: PKGBUILD,v ... : Das CVS-Tag für dieses Paket (Vom Archlinux-CVS System erstellt).
  • # Maintainer : Der Verantwortliche für dieses Paket in den offiziellen Repo's.
  • # Contributor : Der Verfasser der ersten PKGBUILD für dieses Paket.
  • pkgname : Der Paketname
  • pkgver : Die Paketversion
  • pkgrel : Die Releasenummer des Arch Paketes. Wird geändert, wenn das PKGBUILD verändert wurde, sie unterscheided sich also von der Paketversion.
  • pkgdesc : Eine Kurzbeschreibung des Paketes. Du siehst sie, in der Paket Datenbank
  • arch : Die Architekturen, auf denen das Paket kompiliert und getestet wurde.
  • url : Die Homepage des Programmes
  • groups : Wird genutzt um Pakete zu Gruppen zusammen zu fassen. Wenn du z.B. KDE installieren willst, werden alle Pakete installiert, die zur Gruppe 'KDE' gehören
  • provides : Wird genutzt, wenn das Paket ein anderes Paket enthält. z.B. enthält 'kernel-scsi' 'kernel'
  • depends : Liste der Abhängigkeiten um das Programm auszuführen.
  • makedepends : Liste der Abhängigkeiten um das Programm zu kompilieren.
  • conflicts : Pakete, die nicht zusammen mit diesem Programm installiert sein können. In unserem Fall steht foo in Konflikt zu yafoo (yet another foo).
  • replaces : Das neue Paket ersetzt das Alte. In unserem Fall wird mffoo (my first foo) nicht mehr unterstützt und wird durch foo ersetzt.
  • backup : Dateien, die gesichert werden (als .pacsave), wenn das Programm deinstalliert wird.
  • install : Spezifiziert ein Installationsskript, das im Paket enthalten ist. (Muss sich mit PKGBUILD im selben Verzeichnis befinden)
  • source : Die Bezugsquelle des Quelltextes. Kann sowohl ein lokales Paket, als auch ein remote "http" oder "ftp" Paket sein. Der Dateiname wird aus pkgname und pkgver erstellt, damit der Pfad nicht bei jeder neuen Version angepasst werden muss.
  • md5sums : MD5 Summen der Quelltexte um beschädigte Dateien auszuschließen.

Nun die Funktionen:

  • build : Alle Schritte, die nötig sind um das Paket zu kompilieren. (Darauf gehen wir später besser ein).

Wie du siehst enthält PKGBUILD alle Informationen die von der Paketverwaltung gebraucht werden könnten. Es ist das Herzstück von pacman und ABS.

Es sind auch Installationsdateien vorhanden. Unser PKGBUILD gibt 'foo.install' als Installationsdatei an. Es könnte z.B. folgendes enthalten:

post_install() {
/bin/true
}

post_upgrade() {
/bin/true
}

pre_remove() {
/bin/true
}

op=$1
shift

$op "$@"

Erklärungen:

  • post_install : Wird nach der Installation ausgeführt. Es wird ein Argument übergeben:
    • Die Paketversion
  • post_upgrade : Wird ausgeführt, nachdem alle Dateien aktualisiert wurden Es werden zwei Argumente übergeben:
    • Die neue Paketversion
    • Die alte Paketversion
  • pre_remove : Wird ausgeführt, bevor Dateien gelöscht werden (beendet z.B. daemonen) und übergibt ein Argument:
    • Die Paketversion

Damit die Installationsdateien funktionieren, müssen diese drei Zeilen am Ende jeder Installationsdatei vorhanden sein.

Die build Funktion

Wenn du dich nicht mit dem Bauen von Paketen auskennst, solltest du wissen, dass die meisten Pakete über den 'Dreisatz' gebaut werden können:

  • Paketdateien dekomprimieren :
  tar -xzf foo-0.99.tar.gz
  tar -xjf foo-0.99.tar.bz2
  • In das Verzeichnis wechseln
cd foo-0.99
  • Paket konfigurieren : normalerweise ist ein kleines Script configure im Quelltextverzeichniss vorhanden. Es wird genutzt um das Paket zu konfigurieren (hinzufügen von Unterstützungen, Installationsverzeichnis festlegen, ...)
  • configure the package : generally, there is a little script called configure in the source directory which is used to configure the package (add or remove support for things, choose the install destination, ...) 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
  • compile the sources :
make
  • install
make install

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

So let's take a look at a "standard" build function :

build() {
  cd $startdir/src/$pkgname-$pkgver
  ./configure --prefix=/usr
  make || return 1
  make prefix=$startdir/pkg/usr install
}

What we do is :

  • enter the directory where sources were uncompressed :
cd $startdir/src/$pkgname-$pkgver

But if you try to build your package, be carefull that this is the right directory : sometimes the uncompressed directory might be named differently :

tar -xzf foo-0.99.tar.gz

and a ls might return :

  .
  ..
  foo-0.99.tar.gz
  foo/

and not :

  .
  ..
  foo-0.99.tar.gz
  foo-0.99/
  • configure the package, and tell it to install in the /usr directory :
  ./configure --prefix=/usr
  • compile
  make || return 1
  • install the software but not in /usr, in $startdir/pkg/usr so that pacman has control of the files.
  make prefix=$startdir/pkg/usr install

What we want to do is build the package not to install it, so instead of installing to the standard place (/usr), we tell make to put all files in our special directory : $startdir/pkg/usr. Thus, makepkg can look and see which files the package installs, and then compress them into the Arch package.

NOTE: It is sometimes the case where prefix is not used in the Makefile; often DESTDIR is used instead. If the package is built with autoconf/automake, use DESTDIR, this is what is documented in the manuals. Check if the generated filelist is a lot shorter than it should be, and if so, try building with make DESTDIR=$startdir/pkg install. If that does not work, you'll have to look further into the install commands that are executed by "make <...> install=".

The ABS tree

When you run abs for the first time :

root @ localhost # abs

it synchronizes what can be called "the ABS tree" whith the arch server using the cvs system. So what exactly is the ABS tree ? It is located under /var/abs and looks like this :

|-
| -- base/
|-
|     ||-- autoconf/
|-
|     ||-- automake/
|-
|     ||-- ...
|-
| -- devel/
|-
| -- ...
|-
| -- extra/
|-
|      || -- deamons/
|-
|      ||      || -- acpid/
|-
|      ||      ||      || -- PKGBUILD
...    ...    ...    ...

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

  • first level directory represent categories
  • second level directories represent the packages
  • PKGBUILD files contains every information needed concerning the package

However, there is one special directory : local. This directory is yours, this is where you'll do everything : you should never modify the rest of the tree.

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 it's compressed during the transfer

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

First use of ABS : customizing a package

This situation can arise more often than you may think : official packages are compiled choosing a certain number of --enable or --disable options, and these are not necessarily the ones you would have chosen.

To illustrate it, I'll take an example : foo The foo package is built with arts support disabled. Imagine that we want to enable arts. Here is how to do it :

  • find where is the foo package located. you can do this by :

search for foo at [1] use the find command :

  find /var/abs -name "foo"

use the slocate command :

  slocate foo | grep ^/var/abs

In any case, you'll find that foo is part of extra and multimedia (for example)

  • copy the foo PKGBUILD file to /var/abs/local/foo
  mkdir /var/abs/local/foo
  cp /var/abs/extra/multimedia/foo/* /var/abs/local/foo
  cd /var/abs/local/foo
  • modify the PKGBUILD file : we'll add support for arts :
  build() {
    cd $startdir/src/$pkgname-$pkgver
    ./configure --prefix=/usr
    make || return 1
    make prefix=$startdir/pkg/usr install
  }

becomes :

  build() {
    cd $startdir/src/$pkgname-$pkgver
    ./configure --enable-arts --prefix=/usr
    make || return 1
    make prefix=$startdir/pkg/usr install
  }
  • launch makepkg :
  makepkg
  • install the new package using one of the following commands (-A for install, -U to upgrade an already installed package):
  pacman -A foo-*.pkg.tar.gz
  pacman -U foo-*.pkg.tar.gz

Compiler Flags and Customizing makepkg

The configuration file for makepkg is /etc/makepkg.conf. Here you can set environment variables for gcc and make, as well as some for makepkg itself. The following is an example of /etc/makepkg.conf.

# The FTP/HTTP download utility that makepkg will use to acquire sources
export FTPAGENT="/usr/bin/wget --continue --passive-ftp --tries=3 --waitretry=3"

# Information passed to gcc about what type of computer this is.
export CARCH="i686"
export CHOST="i686-pc-linux-gnu"

# Flags passed to gcc when a package is being compiled
export CFLAGS "-march athlon-tbird -O2 -pipe"
export CXXFLAGS "-march athlon-tbird -02 -pipe"

# Flags passed to make when a package is being compiled
export MAKEFLAGS="-j 2"

# Enable colorized output messages
export USE_COLOR="y"

# The remaining variables only affect the behavior of makepkg
# Enable fakeroot for building packages as a non-root user.
# See 'man fakeroot' for more information on fakeroot
export USE_FAKEROOT="y"

# The directory where all packages will be placed (default is ./)
export PKGDEST=/home/packages

# Base of the ABS tree (default is /var/abs)
export ABSROOT=/var/abs

# Set this if you want your name to show up in the packages you build
export PACKAGER="John Doe <nowhere@microsoft.com>"

A word of caution: Users should be sure of any changes they may make to the variables CFLAGS, CXXFLAGS, and MAKEFLAGS as they can cause packages to be unstable or impossible to compile. Also, the average Arch Linux user will not need to change the values for CARCH, CHOST, and USE_FAKEROOT.

References for gcc and make flags

Other uses of ABS

Well here are two more wiki pages, whose goal is to go deeper in ABS :