环境装备
以实际环境为准
gcc g++ 4.8 以上
Ubuntu、Debian
apt-get install build-essential swig python2.7-dev libedit-dev -y
apt-get install doxygen epydoc
CentOS、Fedora、Redhat
yum groupinstall -y "Development Tools"
yum install -y git python wget
注:缺啥,安装啥,不能安装就编译,不同环境缺的依赖不一样!
下载所需的tar
re2c-1.1.1.tar.gz cmake-3.14.5.tar.gz martine.tar llvm-9.0.1.tar等
注:可以通过apt和yum安装,因为版本低,所以编译高版本的,可以apt或yum装的自行忽略!
安装re2c
tar -xvzf re2c-1.1.1.tar.gz
cd re2c-1.1.1/
./autogen.sh
./configure
make
make install
安装cmake
tar -xvzf cmake-3.14.5.tar.gz
cd cmake-3.14.5
mkdir -p build
cd build
../configure
make
make install
安装ninja
tar -xvzf martine.tar
cd martine/ninja
./configure.py --bootstrap
cp ninja /usr/local/bin
或
git clone https://github.com/ninja-build/ninja.git -b v1.8.2
cd ninja
./configure.py --bootstrap
下线clang9
按所需要的组件下载,仅安装llvm和clang,仅需下载llvm.src和clang.src压缩包即可!
https://github.com/llvm/llvm-project/releases/tag/llvmorg-9.0.1
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/llvm-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/clang-tools-extra-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/lld-9.0.1.src.tar.xz
#https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/lldb-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/polly-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/compiler-rt-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/libcxx-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/libcxxabi-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/libunwind-9.0.1.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/openmp-9.0.1.src.tar.xz
解压clang9
按需求解压,比如不编译lldb组件。解压位置任意,比如:/opt/my/llvm
以下目的是为了,一起编译,所以是此目录结构。当然可以单独编译,不讲究目录结构,未测试单独编译,不再此讨论。
tar -xvf llvm-9.0.1.src.tar.xz
cd llvm-9.0.1.src
mkdir -p tools/clang
mkdir -p tools/clang/tools/extra
mkdir -p tools/lld
#mkdir -p tools/lldb
mkdir -p tools/polly
mkdir -p projects/compiler-rt
mkdir -p projects/libcxx
mkdir -p projects/libcxxabi
mkdir -p projects/libunwind
mkdir -p projects/openmp
tar -xvf ../clang-tools-extra-9.0.1.src.tar.xz -C tools/clang/tools/extra/ --strip-components=1
tar -xvf ../lld-9.0.1.src.tar.xz -C tools/lld --strip-components=1
#tar -xvf ../lldb-9.0.1.src.tar.xz -C tools/lldb/ --strip-components=1
tar -xvf ../polly-9.0.1.src.tar.xz -C tools/polly/ --strip-components=1
tar -xvf ../compiler-rt-9.0.1.src.tar.xz -C projects/compiler-rt/ --strip-components=1
tar -xvf ../libcxx-9.0.1.src.tar.xz -C projects/libcxx --strip-components=1
tar -xvf ../libcxxabi-9.0.1.src.tar.xz -C projects/libcxxabi/ --strip-components=1
tar -xvf ../libunwind-9.0.1.src.tar.xz -C projects/libunwind/ --strip-components=1
tar -xvf ../openmp-9.0.1.src.tar.xz -C projects/openmp/ --strip-components=1
编译clang9
mkdir -p build
cd build
cmake -G "Unix Makefiles" \
-LLVM_OPTIMIZED_TABLEGEN=true \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD="host" \
..
nohup make -j6 > build.log 2>&1 &
# -j6 6核CPU,以实际为准,前台执行 make -j6
安装clang9
make install
验证clang9
clang -v
注:自定义操作系统,需要添加软连接
尤其Linux国产化操作系统,有问题私信我