Initial Installation and setup

Basically, I followed the official instructions for Getting Started.

get source

I checked out the source from svn. I link clang into the right place, but check both out into the same top level directory for easier directory.

svn co llvm
svn co clang

Getting ready to build

In order to have reasonable compilation speeds, I followed instructions at how to speedup compile time and more speedup tips and here. I use ninja instead of make, the gold linker, split-dwarf, shared libraries, and only compile for the x86. The following script will enforce all of this building the compiler from scratch. (If you don't have the gold binutils or ninja, then follow these instructions to get them installed.

I build the compiler in the $LLVMBASE/build.


# build from scratch.  Make sure we have dependencies and source files, etc.

if [ ! -e llvm ]; then
    echo "I can't even find the llvm directory.  Huh?"
    exit -1
# make sure ninja is on the path
type ninja > /tmp/$$
if [ $? != 0 ]; then
    echo "You must put ninja on your path.  e.g., "
    echo "export PATH=\$HOME/opt/ninja/bin:\$HOME/opt/\$PATH"
    exit -1
# make sure we have gold version of ld on the path
ld --version | grep -q gold
if [ $? == 0 ]; then
    # yes, so get path
    ldfile=`type -p ld`
    ldpath=dirname $ldfile
    echo "You need the gold version of binutils, in particular ld"
    echo -1
# make sure clang and llvm are linked properly
if [ ! -e llvm/tools/clang ]; then
    cd llvm/tools
    ln -s ../../clang .
    cd ../..
# make sure we have a build directory
if [ ! -e build ]; then
    mkdir -p build
cd build
# make sure we have run cmake properly
if [ ! -e CMakeCache.txt ]; then
    cmake -G Ninja ../llvm -DLLVM_USE_SPLIT_DWARF=TRUE -DLLVM_ENABLE_ASSERTIONS=TRUE -DCMAKE_BUILD_TYPE=Debug -DCMAKE_SHARED_LINKER_FLAGS="-B$ldpath -Wl,--gdb-index" -DCMAKE_EXE_LINKER_FLAGS="-B$ldpath -Wl,--gdb-index" -DBUILD_SHARED_LIBS=true -DLLVM_TARGETS_TO_BUILD=X86 2>&1 | tee cmake.out.log
# ok, now compile it
nice ninja

(It always takes longer than I would like, so I nice ninja so I can do other things on my system during the initial compile.)