Build clang llvm

From Dmz-portal

Jump to: navigation, search



This page describes a simple way to get started with llvm/clang for Mips. Unfortunately, llvm/clang are not self-contained and require gnu toolchain to generates code for Mips.

We provide a prebuilt binary package that you can download and use. The package includes llvm/clang, gnu toolchain and alternative clang driver.

If you want to build your own custom toolchain or llvm/clang, you can use source package. This package includes all necessary default tarballs and set of build scripts. The build scripts allows to exchange components for newer/older versions.

Using a Prebuilt Package

You may simply download a prebuilt package, unpack it and set your path to it's top level bin directory and begin to use it.

  1. Download this tarball: Media:Mips_linux_toolchain_clang-bin.tar.bz2
  2. Unpack the tarball: tar vfxj Mips_linux_toolchain_clang-bin.tar.bz2
  3. Add the bin folder to the path: export PATH=$PWD/mips_linux_toolchain_clang/bin:$PATH

Using a Source Package

Various components must be installed on your computer before proceeding, if they are not already there. In general you will receive the proper warning if you are missing some component but not always so it's good to read through the list.

First, you need to download and unpack the package:

  1. Download this tarball: Media:Mips_linux_toolchain_clang.tar.bz2
  2. Unpack the tarball: tar vfxj Mips_linux_toolchain_clang.tar.bz2

There are three build scripts in the package.
Builds all executables, installs them and installs alternative driver. This script runs to build gnu linux toolchain and to build llvm/clang. The script is simple and does not support any command line options. It expects to find installation prefix path in the PREFIX environment variable.
Builds gnu toolchain only. Please refer to Gnu Linux Toolchain page for the detailed usage guide.
Builds llvm/clang for Mips only. Please refer to the following section for details.

Llvm/Clang Build Options

To get a full list of build options run the build script with help command: ./ help.


    buildall            run all building stages from unpack to check
    download            check packages and download missed ones
    cleanup             remove source, build and aux dirs
    help                print this help message

    unpack              unpack packages
    buildclang          build llvm/clang
    check               run set of simple tests

    -h, --help          print this help message
    -p, --prefix=DIR    use DIR as an installation prefix
    -d, --download=DIR  lookup packages tarballs in the DIR
    -s, --source=DIR    use DIR to unpack packages tarballs
    -b, --build=DIR     use DIR as a build directory
    -j, --jobs=NUM      run NUM make jobs simultaneously

    You can override default packages versions using the following
    environment variables. For example 'LLVM_VER=2.9'
    or 'LLVM_VER=trunk'.
    LLVM_VER            llvm version
    CLANG_VER           clang version

By default, the build script searches packages in the ./dl folder and creates the following auxiliary folders:


You should point to the installation folder using either --prefix command line option or PREFIX environment variable:

./ --prefix=DIR

If you want to use different version of components, you can override default settings using environment variables. For example, the following command builds llvm/clang using version 3.1:

LLVM_VER=3.1 \
./ --prefix=DIR

This command downloads and then builds llvm/clang using source code from llvm/clang repository trunk:

LLVM_VER=trunk \
CLANG_VER=trunk \
./ download buildall --prefix=DIR

Default component's versions are:


Running QEMU standalone and with gdb

Build a simple hello world using alternative driver:

mips_linux_gnu_gcc -g hello.c -o hello -static

Run with qemu:

qemu-mipsel hello

Run with qemu under the control of gdb

qemu-mipsel -g 1234 hello &
mips-linux-gnu-gdb hello
  target remote :1234
  break main


Pre-built executables of Gnu Linux Toolchain and llvm/clang
Script and packages to build Gnu Linux Toolchain and llvm/clang


Personal tools