Apple provides you with the clang compiler, so why should you want to compile it yourself? Because there are some utilities out there (e.g. clang-format), that Apple does - for whatever reason - not bring to your Mac. Strange considering the fact that they are heavily involved into clang development. For Mr. and Mrs. Average those tools aren't needed on a Mac, that's for sure but for developers? Come on Apple, wake up!
Never mind, it's easy.
Open you terminal and get download the code
$ # just for convenience $ export build=~/devtools # or wherever you'd like to build $ mkdir -p $build $ cd $build $ # first llvm, the basic infrastructure $ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm $ # followed by clang, the compiler $ cd llvm/tools $ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang $ cd ../.. $ # finally the tools, the reason for this all here $ cd llvm/tools/clang/tools $ svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra $ cd ../../../..
$ mkdir -p $build/clang $ cd $build/clang $ # As I already have a clang package from Apple that I don't want to mix up, $ # I do not provide --prefix here $ ../llvm/configure --enable-libcpp --enable-cxx11 --enable-debug-symbols=no --enable-optimized $ $ ls Makefile bindings docs lib runtime unittests Makefile.common config.log examples llvm.spec test utils Makefile.config config.status include projects tools $ # compiling will take some time…almost an hour on my computer $ make
The tools were automatically build, too.
Just go on, have a look in
$build/clang/Release+Asserts. If you want to have a glimpse on what those tools can do for you, watch Chandler Carruth's talk from Going Native 2013.