I've talked about the LLVM Compiler Infrastructure
in the past, but what I haven't talked about yet is just how easy
you can build it on your own Mac running Leopard! This is a great way to get into hacking on compiler lexical analyzers and parsers, code generators, optimizers, and so on.
What's more, you can build both LLVM
and the new C front-end
very easily and in five to ten minutes
First, create a work area to check them out into, wherever you normally create your projects.
[~]% cd /Projects
[/Projects]% mkdir LLVM
[/Projects]% cd LLVM
Then check out LLVM itself and
from the LLVM Subversion repository
[/Projects/LLVM]% svn checkout http://llvm.org/svn/llvm-project/llvm/trunk llvm
[/Projects/LLVM]% cd llvm/tools
[/Projects/LLVM/llvm/tools]% svn checkout http://llvm.org/svn/llvm-project/cfe/trunk clang
[/Projects/LLVM/llvm/tools]% cd ../..
Then edit the
to tell it about
. Just add
onto the end, like this:
PARALLEL_DIRS := llvm-config \
opt llvm-as llvm-dis \
llc llvm-ranlib llvm-ar llvm-nm \
llvm-ld llvm-prof llvm-link \
lli gccas gccld llvm-extract llvm-db \
bugpoint llvm-bcanalyzer llvm-stub llvmc2 \
Now create a directory to build into, next to your
directory, and change into it.
[/Projects/LLVM]% mkdir build
[/Projects/LLVM]% cd build
This is where you'll actually run
. This will ensure your source tree isn't polluted with build products, and that everything stays self-contained while you hack.
[/Projects/LLVM/build]% ../llvm/configure --enable-targets=host-only
# lots of logging
You'll note that above I passed an argument to
. This ensures that LLVM is only built to target the architecture I'm running on, to speed up the build process; this is generally fine for simple front-end development.
Now, to build LLVM as well as
all I have to do is invoke
. LLVM is set up to correctly do parallel builds, so I'll pass the number of CPUs I have in my machine via
make -j 4
[/Projects/LLVM/build]% make -j 4
# lots of logging
That's it! LLVM is now (hopefully) successfully built. All of the pieces are in the
and so on; see the LLVM web site for details about what the various components are.