Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages, and can often be used as a drop-in replacement for the GNU C & C++ compilers. Clang uses LLVM as its back end. It is possible to checkout the latest version of Clang from the LLVM SVN repository:

mkdir $HOME/src

cd $HOME/src
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm 

cd $HOME/src/llvm/tools 
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang 

cd $HOME/src/llvm/tools/clang/tools 
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra 

cd $HOME/src/llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt

Arch Linux is a Linux-based operating system for i686 and x86-64 computers. It uses a rolling release model. To build Clang under Arch you’ll first need to install a few prerequisites, including cmake, make, gcc, subversion and python2.

To build Clang with GCC:

#!/bin/sh

BUILD=$HOME/src/llvm/build
rm -rf $BUILD
mkdir $BUILD
cd $BUILD

cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/clang -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/bin/gcc \
-DCMAKE_CXX_COMPILER=/bin/g++ \
-DPYTHON_EXECUTABLE:PATH=/usr/bin/python2 ..

make

Then run “make install” as root to install Clang to /opt/clang/.

You can also install an older version of Clang from the Arch repositories to build the SVN version of Clang. This should speed up the build process compared to using GNU C++. It takes roughly an hour to build on an Intel Core 2 Duo.

#!/bin/sh

BUILD=$HOME/src/llvm/build
rm -rf $BUILD
mkdir $BUILD
cd $BUILD

cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/clang -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/bin/clang \
-DCMAKE_CXX_COMPILER=/bin/clang++ \
-DPYTHON_EXECUTABLE:PATH=/usr/bin/python2 ..

make

Again, run “make install” as root to install Clang to /opt/clang/.

Lastly, you can build Clang from SVN with the version of Clang you just installed to /opt/clang/.

#!/bin/sh

BUILD=$HOME/src/llvm/build
rm -rf $BUILD
mkdir $BUILD
cd $BUILD

cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/clang -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/opt/clang/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/clang/bin/clang++ \
-DPYTHON_EXECUTABLE:PATH=/usr/bin/python2 ..

make

Finally, run “make install” as root to install Clang over itself to /opt/clang/.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: