hardcodes.de


Building clang-format and friends on OSX Mountain Lion

Oct 19, 02:04 PM

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!


Image from http://www.tonyrogers.com/weapons/images/high_speed_photos/

Never mind, it’s easy.

Tools

Have a look at the prerequisites and install the tools that are not on your Mac, e.g. auto tools.

Getting the sourcecode

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 ../../../..

Build

llvm and clang

$ 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

clang-tools

The tools were automatically build, too.


Image from http://isocpp.org

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.

Sven Putze

,





Search

RSS / Atom



© by Sven Putze

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
All trademarks and trade names are the property of their respective holders. Using glyphicons.