Build Environment Table of Contents Installing the build environment Using the installer script Alternative: Using a snapshot release Configuration /etc/resolve.conf /dev/ Locales .bashrc Installing native applications Building native applications With the Arch Linux Mobile project we provide a rather unusual build environment. Instead of using a cross-compiling toolchain which is being integrated in the host system we are using the target system emulated on the host system. The setup to enable this is similar to the operation of scratchbox.

For the build system you will first install the basic Arch Mobile system to your hard-drive (yes, that's the same system which runs on the target arm device, i.e. it contains only binaries compiled for an arm processor). Using Qemu's user mode and the binfmt_misc kernel mechanism we are able to create a transparent emulation. Which means that is is possible to excute arm binaries the same way i686 binaries are executed.

This way we can chroot into the target system and pretend we were running on an arm-based platform. This environment is the same as the one that is to be used on the target device itself and can be used like that. Especially calling gcc in this environment will create arm binaries instead of i686 or x86_64 binaries. So one does not need to configure the build system of a package to do cross-compilation anymore. This simplifies the process of creating target packages significantly.

The downside of this approach is speed. As binaries compiled for arm have to be emulated their execution speed is severly decreased. For example emulating gcc increases compilation time around 5-times. To address this issue we install host (i686 or x86_64) executables in the emulated environment. This way the (slow) arm executables can be overridden by their (fast) native counterparts, e.g. gcc is then as fast/slow as it is in the non-emulated case.

So the key difference to a traditional cross-compilation approach is that all compilation takes places in a emulated target environment ( (with certain executables replaced by host tools) instead of excplictly telling the build system to do cross-compilation in the host environment.


it's simple! maximum compability to the target device separation of host and build system Disadvantages:

QEMU can introduce bugs more diskspace needed speed penality some packages cannot be compiled with native tools (i.e. gcc due to bootstrapping) Installing the build environment

Installation of the build environment is hardly different from installing on a target device. The additional steps are to to install Qemu in the chroot and optionally installing native replacement tools. You can choose between the installer script or a snapshot based installation. The former will create a bleeding edge installation and is simpler while the latter does not need root access for installation.

Indepently of the installation method you choose, you need to tell kernel to use Qemu for running arm binaries by executing the following as root:

$ mount -t binfmt_misc none /proc/sys/fs/binfmt_misc $ echo ”:arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\ \x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\ \xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\ \xff\xff\xff\xff\xfe\xff\xff\xff\ :/usr/bin/qemu-static-arm:” > /proc/sys/fs/binfmt_misc/register Note: You can add these lines to one of your startup scripts (e.g. /etc/rc.local) if you want to preserve this even after rebooting.

Using the installer script

Note: The install script isn't stable. We try not to break your system, but as this script needs root access it is possible that it does. Read the script if you are paranoid. You have been warned.

First you have to get our installer script. This is available via our Git repository here: [source:util/archmobile].

Now you have to install the Arch Linux base system enhanced with a few developer tools. To do so create a target directory and call the installer script as following:

$ mkdir archbuild $ ./archmobile –build archbuild If everything went well you can now chroot into your fresh build environment using:

$ ./archmobile -e archbuild Note: If you don't want to have the archmobile script installed for entering the build environment you can do a simple chroot /bin/bash -l call or add alias to your .bashrc / .zshrc: alias gochroot='sudo nice -n 19 chroot /patch/to/your/buildenv /bin/bash -l'.

Alternative: Using a snapshot release

The first step is to download the snapshot release tarball. Get it from After that unpack it to a directory of your liking, we chose work here.

$ mkdir work $ tar -C work -xvjf archmobile-*.tar.bz2 Next step is to install a static version of qemu, since you cannot use pacman for that yet, you have to download the package yourself and unpack it in the newly created directory.

$ wget`uname -m`/build/qemu-0.12.2-1-`uname -m`.pkg.tar.gz $ tar -C work -xvzf qemu-* At this point we can chroot into the new environment and use pacman to install the native gcc toolchain. For this we add the repository that contains the native packages for your host platform.

$ echo -e ”[build]\nServer =`uname -m`/build/” » etc/pacman.conf $ chroot . /bin/bash -l $ pacman -Sy gcc-native You are done and after chroot'ing into the root directory again you are able to compile arm packages with quasi-native speed. If you like to install further native package replacements, try pacman -Ss native in the chroot.

Note: Always make sure that chroot /bin/bash -l is used to enter the chroot. If not the special profile.d/ scripts will not be executed and native tools will not be used.


Since we chroot into our build environment there's no boot process and thus some initialization has to be done manually. A decent way is to put all the stuff you would make by hand in archbuild/root/.bashrc. If not stated otherwise we are chrooted in the build environment.


To make the internet connection work, copy /etc/resolv.conf from your host system to your build environment:

# cp /etc/resolv.conf archbuild/etc /dev/

Some, not all, configure scripts may need access to real /dev/urandom or other special device. You can't use udev inside chroot, instead, you should mount existing /dev/ directory under your build environment:

mount –bind /dev/ /patch/to/your/build/environemnt/dev You can add this to /etc/rc.local.


Add your prefered locales to /etc/locale.gen and run {locale-gen}. To add english locales use the following commands:

# echo -e “en_US.UTF-8 UTF-8\nen_US ISO-8859-1” » /etc/locale.gen # locale-gen .bashrc

Just copy it to /root/.bashrc and be sure to source it every time you chroot into the build environment.

Note: If you are using zsh instead of bash there's also a .zshrc example available.

# Have a nicer prompt. export PS1=”[\u@\h $] ”

# Set a clean path. export PATH=”/bin:/bin:/usr/bin:/sbin:/usr/sbin”

# Prefer native applications if available. export PATH=”/usr/arm-softfloat-linux-gnueabi/bin:$PATH”

# Fake linux terminal. export TERM=linux

# Set correct locales. export LC_ALL=en_US.utf8 export LC_LANG=en_US.utf8

# Set correct $HOME. export HOME=/root

# Rather common aliases. alias ls='ls –group-directories-first –color=auto' alias bye=exit alias nano=vi alias ..='cd ..' Happy building!

Note: Due to bug #98 touch isn't usable in the chroot with a x86-64 host PC. Use coreutils-native's touch as a workaround.

Installing native applications

To get some decent speed from your build environment it is necessary to install native packages.

To do so, just add the following repository to your /etc/pacman.conf. Be sure to replace $CARCH with your host system's architecture.

[build] Server =$CARCH/build After using pacman -Sy you can install native applications. To indicate native applications -native is appended to the package, e.g. gcc-native.

To list all native applications use pacman -Sl build.

Building native applications

If you want to create native packages yourself there are a few adjustments necessary to Arch Linux standard PKGBUILDs.

All package files (except libraries) should go to /usr/arm-softfloat-linux-gnueabi. Files outside of this directory or its subsequent directories are not allowed. Libraries should go to /usr/lib/$CARCH. Native binaries should link against /usr/lib/$CARCH/ LDFLAGS=”-Wl,-dynamic-linker,/usr/lib/$CARCH/”

buildenvironment.txt · Last modified: 2014/10/29 21:07 by archmobile
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki