参考了一些别人的方法,折腾了很久,以失败告终。最后按照书上写的,终于成功了。以下是一键安装的脚本。
cd
mkdir llvm
#.Checkout LLVM(添加一个你想放置LLVM的路径)
cd llvm
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
#Checkout Clang
cd tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
#Checkout Extra Clang Tools [不是必须的,可选]
cd clang/tools
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
#Checkout LLD linker [不是必须的,可选]
cd ../..
svn co http://llvm.org/svn/llvm-project/lld/trunk lld
#Checkout Polly Loop Optomizer [不是必须的,可选]
svn co http://llvm.org/svn/llvm-project/polly/trunk polly
#Checkout Compiler-RT(Required to build the sanitizers) [不是必须的,可选]
cd ../projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
#Checkout Libomp(required for OpenMP support) [不是必须的,可选]
svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp
#Checkout libcxx and libcxxabi [不是必须的,可选]
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
#Get the Test Suite Source Code [不是必须的,可选]
svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite
cd ..
mkdir build
mkdir suite
cd build/
cmake ../llvm/ -G Ninja -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="../suite/" -DBUILD_SHARED_LIBS=ON
ninja && ninja install
编译选项参考 https://llvm.org/docs/CMake.html
最后,由于上面是将编译好的东西放在了suite中,别忘在/etc/profile.d/apps-bin-path.sh中添加环境变量
llmv_bin_path="/foyer/suite/bin"
llvm_lib_path="/foyer/suite/lib"
if [ -n "${PATH##*${llmv_bin_path}}" -a -n "${PATH##*${llmv_bin_path}:*}" ]; then
export PATH=$PATH:${llmv_bin_path}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${llvm_lib_path}
fi