<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>

    <div class="title hideforedit">
        <h1 id="title">
            Step 1: 
        </h1>
    </div>
    <div class="text">
        <div id="page-top">
            <div id="topic">
                <div id="pageText">
                    <div id="section_1">
                        <span id="Build_Settings"></span>
                        <h2 class="editable">
                            <span>Build Settings</span></h2>
                        <pre>BASE_ARCH=<strong>arm</strong></pre>
                        <p>
                            <br />
                            Set up the target triple variable.</p>
                        <pre>target=<strong>arm-none-linux-gnueabi</strong>
</pre>
                        <p>
                            Set up a toolchain to build the projects. There is an example for the 
                            CodeSourcery toolchain.</p>
                        <pre># Cross toolchain (CodeSourcery)
CODESOURCERY_ROOT=<u>/home/vkutuzov/CodeSourcery/arm-2009q1</u>
CODESOURCERY_SYSROOT=${CODESOURCERY_ROOT}/arm-none-linux-gnueabi/libc
</pre>
                        <p>
                            If a custom toolchain is supposed to use, update those variables accordingly.</p>
                        <pre># Cross toolchain (Custom)
CODESOURCERY_ROOT=<u>/opt/crosstool/build/cross_tool</u>
CODESOURCERY_SYSROOT=/opt/crosstool/build/target_root</pre>
                        <p>
                             </p>
                        <pre># This variable points to the external tool binaries to
# build the LLVM and LLVM-GCC sources. The following
# external tools are used for the build now: ld, as
# We may use two set of the tools -- from CodeSourcery and
# our own-built binutils. Set this variable up to
#  "$CODESOURCERY_ROOT/bin"
# to use the CodeSourcery tool or
#  "$INSTALL_PREFIX/bin"
# to use a custom binutils tool.
EXT_BINTOOL_ROOT=${CODESOURCERY_ROOT}/bin
</pre>
                    </div>
                    <div id="section_2">
                        <span id="Target_and_Intermediate_Folder_Settings"></span>
                        <h2 class="editable">
                            <span>Target and Intermediate Folder Settings</span></h2>
                        <pre>#------------------------------------------------------------------------------
# Note: Run this script from OBJ_ROOT. Source code directory should be ../src
# The script expects the llvm code checked out to ../src/$LLVM,
# llvm-gcc-4.2 code checked out to ../src/$LLVM_GCC,
# binutils and newlib source code trees combined with ../src/$LLVM_GCC.
#
# The result is a llvm-gcc cross-compiler for ARM and a set of tools and
# utilities in the $INSTALL_PREFIX directory.
#------------------------------------------------------------------------------
ROOT_DIR=<u>/home/vkutuzov/Development</u>
OBJ_ROOT=${ROOT_DIR}/llvm-project
</pre>
                        <p>
                            Set up the source folder names for the llvm and llvm-gcc source code. This 
                            shuold be a name of the folders with the source code.</p>
                        <pre>LLVM=<strong>llvm</strong>
LLVM_GCC=<strong>llvm-gcc-4.2</strong>
</pre>
                        <p>
                            Installation folder</p>
                        <pre>INSTALL_PREFIX=${OBJ_ROOT}/${BASE_ARCH}.install</pre>
                        <p>
                            "Clean up" current search pathes</p>
                        <pre>export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</pre>
                        <p>
                            Always set up path to our custom binaries</p>
                        <pre>export PATH=${INSTALL_PREFIX}/bin:$PATH
export PATH=${CODESOURCERY_ROOT}/bin:$PATH</pre>
                        <p>
                            Make sure the compiler flags are not existed</p>
                        <pre># Var preset
unset CFLAGS
unset CXXFLAGS
</pre>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="title hideforedit">
        <h1 id="title0">
            Step 2: Build LLVM (Stage 1)
        </h1>
    </div>
    <div class="text">
        <div id="page-top0">
            <div id="topic0">
                <div id="pageText0">
                    <pre>objdir=obj.${BASE_ARCH}.${LLVM}.stage1

rm -f ${objdir}
mkdir -pv ${objdir}

pushd ${objdir}

../${LLVM}.source/configure \
  --target=${target} \
  --prefix=${INSTALL_PREFIX}.stage1 \
  --disable-werror \
  --disable-nls \
  --disable-shared \
  --enable-optimized \
  --without-llvmgcc \
  --without-llvmgxx \
  --with-binutils-include=${OBJ_ROOT}/${BINUTILS}.source/include || exit 1

make ENABLE_OPTIMIZED=1 -j 2 2>&1 || exit 1
make install ENABLE_OPTIMIZED=1 || exit 1

popd
</pre>
                </div>
            </div>
        </div>
    </div>
    <div class="title hideforedit">
        <h1 id="title1">
            Step 3: Build LLVM-GCC (Stage 1)
        </h1>
        <div id="page-top1">
            <div id="topic1">
                <div id="pageText1">
                    <pre>objdir=obj.${BASE_ARCH}.${LLVM_GCC}.stage1

rm -f ${objdir}
mkdir -pv ${objdir}

pushd ${objdir}

../${LLVM_GCC}.source/configure \
  --target=${target} \
  --prefix=${INSTALL_PREFIX}.stage1 \
  --with-sysroot=${CODESOURCERY_SYSROOT} \
  --enable-languages=c,c++ \
  --enable-llvm=${OBJ_ROOT}/obj.${BASE_ARCH}.${LLVM}.stage1\
  --enable-optimized \
  --program-prefix=llvm- \
  --disable-shared \
  --disable-nls \
  --with-arch=armv6 \
  --enable-interwork \
  --with-as=${EXT_BINTOOL_ROOT}/${target}-as \
  --with-ld=${EXT_BINTOOL_ROOT}/${target}-ld \
  --with-gxx-include-dir=${CODESOURCERY_ROOT}/${target}/include/c++/4.3.3 || exit 1

make ENABLE_OPTIMIZED=1 LLVM_VERSION_INFO=llvm-gcc_cross-${BASE_ARCH}_stage1 -j 2 || exit 1
make install ENABLE_OPTIMIZED=1 || exit 1

popd
</pre>
                </div>
            </div>
        </div>
    </div>
    <div class="title hideforedit">
        <h1 id="title2">
            Step 4: Build LLVM (Stage 2)
        </h1>
        <div id="page-top2">
            <div id="topic2">
                <div id="pageText2">
                    <pre>objdir=obj.${BASE_ARCH}.${LLVM}.stage2

rm -f ${objdir}
mkdir -pv ${objdir}

pushd ${objdir}

../${LLVM}.source/configure \
  --target=${target} \
  --prefix=${INSTALL_PREFIX}.stage2 \
  --disable-werror \
  --disable-nls \
  --disable-shared \
  --enable-optimized \
  --with-llvmgcc=${INSTALL_PREFIX}.stage1/bin/llvm-gcc \
  --with-llvmgxx=${INSTALL_PREFIX}.stage1/bin/llvm-g++ \
  --with-binutils-include=${OBJ_ROOT}/${BINUTILS}.source/include || exit 1

make ENABLE_OPTIMIZED=1 -j 2 2>&1 || exit 1
make install ENABLE_OPTIMIZED=1 || exit 1

popd
</pre>
                </div>
            </div>
        </div>
    </div>
    <div class="title hideforedit">
        <h1 id="title3">
            Step 5: Build LLVM-GCC (Stage 2)
        </h1>
        <div id="page-top3">
            <div id="topic3">
                <div id="pageText3">
                    <pre>objdir=obj.${BASE_ARCH}.${LLVM_GCC}.stage2

rm -f ${objdir}
mkdir -pv ${objdir}

pushd ${objdir}

../${LLVM_GCC}.source/configure \
  --target=${target} \
  --prefix=${INSTALL_PREFIX}.stage1 \
  --with-sysroot=${CODESOURCERY_SYSROOT} \
  --enable-languages=c,c++ \
  --enable-llvm=${OBJ_ROOT}/obj.${BASE_ARCH}.${LLVM}.stage2 \
  --enable-optimized \
  --program-prefix=llvm.2- \
  --disable-shared \
  --disable-nls \
  --disable-multilib \
  --with-arch=armv6 \
  --enable-interwork \
  --with-as=${EXT_BINTOOL_ROOT}/${target}-as \
  --with-ld=${EXT_BINTOOL_ROOT}/${target}-ld \
  --with-llvmgcc=${INSTALL_PREFIX}.stage1/bin/llvm-gcc \
  --with-llvmgxx=${INSTALL_PREFIX}.stage1/bin/llvm-g++ \
  --with-gxx-include-dir=${CODESOURCERY_ROOT}/${target}/include/c++/4.3.3 || exit 1

make ENABLE_OPTIMIZED=1 LLVM_VERSION_INFO=llvm-gcc_cross-${BASE_ARCH}_stage2 -j 2 || exit 1
make install ENABLE_OPTIMIZED=1 || exit 1

popd
</pre>
                </div>
            </div>
        </div>
    </div>

</body>
</html>