Build mips clang llvm

From Dmz-portal

Jump to: navigation, search

Contents

Overview

This page describes various ways how to build native MIPS LLVM/Clang bundle intended for running on MIPS hosts.

Prerequisites

Before you begin to build LLVM/Clang make sure you have installed gcc and CodeSourcery Toolchain for cross-compilation. Also you might require to install additional software LLVM/Clang Requirements.

Let's define some shortcuts for directories:

$CLANG_SRC
LLVM/Clang source code root directory
$CLANG_BLD
build directory
$CLANG_INSTALL
directory to install built LLVM/Clang package
$CLANG_TC
LLVM/Clang binaries used for cross-compilation (i.e. clang++ is in the $CLANG_TC/bin folder)
$MIPS
MIPS toolchain root directory (i.e. mips-linux-gnu-gcc is in the $MIPS/bin folder)

First you need to checkout LLVM/Clang source code.

$ svn co http://llvm.org/svn/llvm-project/llvm/trunk $CLANG_SRC
$ svn co http://llvm.org/svn/llvm-project/cfe/trunk $CLANG_SRC/tools/clang
$ svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk $CLANG_SRC/projects/compiler-rt
$ svn co http://llvm.org/svn/llvm-project/test-suite/trunk $CLANG_SRC/projects/test-suite

Build on MIPS hosts

Building LLVM/Clang on a MIPS hosts is a standard but a very long procedure.

# Configure makefiles to build llvm/clang using gcc
$ mkdir $CLANG_BLD
$ cd $CLANG_BLD
$ $CLANG_SRC/configure \
    --prefix=$CLANG_INSTALL \
    --enable-optimized \
    --with-extra-options="-mips32r2" \
    CC=/usr/bin/gcc CXX=/usr/bin/g++

# Configure makefiles to build llvm/clang using clang
$ mkdir $CLANG_BLD
$ cd $CLANG_BLD
$ $CLANG_SRC/configure \
    --prefix=$CLANG_INSTALL \
    --enable-optimized \
    --with-extra-options="-mips32r2" \
    CC=/usr/local/bin/clang CXX=/usr/local/bin/clang++
$ make && make install

Cross-compilation on x86 hosts

Using gcc

Cross-compilation of LLVM/Clang on x86 hosts using gcc is straightforward too but takes much less time than building on a MIPS host.

$ $CLANG_SRC/configure \
    --prefix=$CLANG_INSTALL \
    --build=i686-pc-linux-gnu \
    --host=mipsel-unknown-linux-gnu \
    --enable-optimized \                  # turn on optimization
    --enable-keep-symbols \               
    --with-extra-options="-mips32r2 -EL" \
    --with-extra-ld-options="-mips32r2 -EL" \
    CC=$MIPS/bin/mips-linux-gnu-gcc \
    CXX=$MIPS/bin/mips-linux-gnu-g++ \
    RANLIB=$MIPS/bin/mips-linux-gnu-ranlib \
    AR=$MIPS/bin/mips-linux-gnu-ar
$ make && make install

Using clang

$ OPT="-target mipsel-linux-gnu -mips32r2 -gcc-toolchain ${MIPS}"
$ $CLANG_SRC/configure \
    --prefix=$CLANG_INSTALL \
    --build=i686-pc-linux-gnu \
    --host=mipsel-linux-gnu \
    --enable-optimized \                  # turn on optimization
    "--with-extra-options=${OPT}" \
    "--with-extra-ld-options=${OPT}" \
    CC=$CLANG_TC/bin/clang \
    CXX=$CLANG_TC/bin/clang++ \
    RANLIB=$MIPS/bin/mips-linux-gnu-ranlib \
    AR=$MIPS/bin/mips-linux-gnu-ar \
    build_alias=i686-unknown-linux-gnu host_alias=mipsel-linux-gnu
$ make && make install
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox