0%

Compile LLVM & Clang

隨著LLVM 3.3版本出來,記錄一下如河編譯,編譯環境是Mint 15。
使用CMake來幫助編譯。

CMake是用來產生個平台(Windows/MacOSX/Linux/FreeBSD等)建置專案的解決方案,在Visual Studio產生Solutions,在Linux產生正統的Makefile。 更多的CMake用法可以在網路找到。

前期作業

先把所有Code下載下來

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
$ cd llvm/tools
$ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
$ svn co https://llvm.org/svn/llvm-project/lld/trunk/ lld
$ svn co https://llvm.org/svn/llvm-project/lldb/trunk/ lldb
$ cd clang/tools
$ svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
$ cd ../../../projects/
$ svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
$ svn co https://llvm.org/svn/llvm-project/openmp/trunk/ openmp
$ svn co https://llvm.org/svn/llvm-project/libcxx/trunk/ libcxx
$ svn co https://llvm.org/svn/llvm-project/libcxxabi/trunk/ libcxxabi
$ svn co https://llvm.org/svn/llvm-project/libunwind/trunk/ libunwind
$ cd ..

Build Swig

編譯

建立一個build目錄放置CMake的設定黨,由於CMake支援Out-of-source Build技術,原先的目錄可以不遭受污染,就算失敗就只要砍掉build的目錄即可。我們使用Out-of-source Build的方式來建置Makefile。

1
2
3
4
$ mkdir build && cd build
$ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr/local ..
$ make -j 4
$ make install

這裡的cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local 等價於傳統的 ./configure --prefix=/usr/local/方式,預設的LLVM跟Clang是使用Debug Mode,這裡使用Release Mode。