在使用Make工具編譯LLVM是很是耗時的。每每須要三四個小時。可是使用goolge開源的ninja編譯LLVM只須要10到20分鐘。html
本文以llvm3.3爲例,演示在linux上編譯和安裝過程。java
1 獲取並編譯安裝 ninjalinux
$ git clone git://github.com/martine/ninja.git
$ cd ninja
$ ./bootstrap.py
$ sudo cp ninja /usr/local/bin/
Q: warning: A compatible version of re2c (>= 0.11.3) was not found;git
changes to src/*.in.cc will not affect your build.github
A: re2c 是一個用於編寫快速靈活的詞法分析器的工具.json
$sudo apt-get install re2cbootstrap
2 安裝 cmake(至少須要 2.8.9):
用sudo apt-get install cmake獲得的是 2.8.7–2013.3.7
可從http://www.cmake.org/cmake/resources/software.html獲 取 最 新 的
cmake, 再編譯.
編譯 cmake 須要 QT4 和 java:
Q:Could NOT find Qt4 (missing: ...
A:sudo apt-get install qt-sdk
Q:fatal error: ext2fs/ext2 fs.h: No such file or directory
A: sudo apt-get install e2fslibs-dev
Q:fatal error: curses.h: No such file or directory
A: sudo apt-get install libncurses5-devbash
llvm全部的項目的代碼的svn庫都在:
http://llvm.org/svn/llvm-project/
能夠使用svn拷貝
1 下載llvm3.3
$ svn co http://llvm.org/svn/llvm-project/llvm/branches/release_33/ llvm3.3
2 下載clang3.3到llvk3.3/tools
$ cd llvm3.3/tools/
$ svn co http://llvm.org/svn/llvm-project/cfe/branches/release_33/ clangsvn
3 下載Compiler RT到llvm3.3/projects
$ cd ../projects
$ svn co http://llvm.org/svn/llvm-project/compiler-rt/branches/release_33/ compiler-rt工具
1 創建build目錄
$ cd llvm3.3/
$ mkdir build
2 產生ninja編譯文件
#能夠使用-DCMAKE_INSTALL_PREFIX指定安裝目錄
$ cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=/opt/llvm3.3 ..
$ ln -s ../build/compile_commands.json ..
3 編譯
$ ninja
4 安裝
$ sudo ninja install
5 把安裝目錄加入的環境變量PATH中
能夠在home目錄的.bashrc中加入
export PATH=/opt/llvm3.3/bin/:$PATH