Skip to content

toolchain_build_instructions

dileks edited this page Apr 24, 2011 · 47 revisions

Intro

This document describes how to build a llvm/clang based toolchain from lll-project GIT repositories. Currently, we support only X86_32 and X86_64 architectures.

Preps before build

Preps #1: Create a project-directory

PRJ_DIR="$HOME/src/lll-project"
mkdir -p $PRJ_DIR

Preps #2: Clone the llvm / clang / libcxx repositories

cd $PRJ_DIR
git clone https://github.com/lll-project/llvm

cd llvm/tools
git clone https://github.com/lll-project/clang

WARNING: In the future we plan to support libc++ from clang project (current status: experimental)

cd clang/runtime
git clone https://github.com/lll-project/libcxx

Preps #3: Some useful variables

export LANG=C
export LC_ALL=C

MAKE="make"

CC_FOR_BUILD="gcc"
CXX_FOR_BUILD="g++"

Build and install the toolchain

Some useful variables for the build

Here, a "classic" /opt installation is intended:

BUILD_DIR="$PRJ_DIR/llvm-build"

PREFIX="/opt/llvm"

HINT: If /opt directory is not an option for you (or not accessible), use PREFIX=$HOME/install instead.

Configure #1: Use configure

CONFIGURE_OPTS="--enable-optimized --enable-assertions --enable-targets=host-only"

cd $BUILD_DIR

../llvm/configure --prefix=$PREFIX $CONFIGURE_OPTS

Configure #2: Use cmake (BROKEN with libcxx)

CMAKE_OPTS="-DCMAKE_BUILD_TYPE=RELEASE -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=X86"

cd $BUILD_DIR

cmake ../llvm -DCMAKE_INSTALL_PREFIX=$PREFIX $CMAKE_OPTS

NOTE: There is no 1:1 replacement for "--enable-targets=host-only" configure-option. "X86" as target is used for both X86_32 and X86_64.

HINT: How to get a list of all available cmake variables?

cd $BUILD_DIR
cmake ../llvm -LA

Start toolchain build

MAKE_JOBS="2"

$MAKE CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD -j$MAKE_JOBS 2>&1 | tee ../build_toolchain.log

Install toolchain

cd $BUILD_DIR

root# $MAKE install 2>&1 | tee ../install_toolchain.log

Last steps: Integrate toolchain binaries and libraries

Toolchain libs: Configure and update dynamic linker run-time bindings

For Debian systems create a new llvm-with-clang.conf file:

[ /etc/ld.so.conf.d/llvm-with-clang.conf ]
# LLVM and clang lib configuration
/opt/llvm/lib

Update dynamic linker run-time bindings:

root# ldconfig

Toolchain binaries: Use via $PATH

Finally, export the PATH variable by adding the toolchain-bin directory:

PREFIX="/opt/llvm"
export PATH=$PATH:$PREFIX/bin