构建compiler-rt
1. 构建脚本
1.1. 脚本参数
以下构建脚本在源代码根目录下执行且在构建llvm/clang/lld完成后执行。脚本中参数说明:
- BIN_DIR: 构建llvm/clang/lld生成的INSTALL_DIR目录下的bin目录。
- TOOLCHAIN_DIR:gcc交叉工具链(下载)归档在本地的目录,目录结构如下:
bin include lib lib64 libexec loongarch64-linux-gnu share VERSION
1.2. 脚本示例
#!/bin/bash
set -ex
BIN_DIR="$PWD/llvm_install/bin"
TOOLCHAIN_DIR="/home/llvm/loongarch64-linux-gnu-toolchain"
SYSROOT_DIR="$TOOLCHAIN_DIR/loongarch64-linux-gnu/sysroot"
LA_FLAGS="-B$TOOLCHAIN_DIR/loongarch64-linux-gnu -mcmodel=large"
rm -rf _build_cross
mkdir _build_cross
cd _build_cross
cmake \
-DCMAKE_CROSSCOMPILING=True \
-DLLVM_CONFIG_PATH="$BIN_DIR"/llvm-config \
-DCMAKE_AR="$TOOLCHAIN_DIR"/bin/loongarch64-linux-gnu-ar \
-DCMAKE_C_COMPILER="$TOOLCHAIN_DIR"/bin/loongarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER="$TOOLCHAIN_DIR"/bin/loongarch64-linux-gnu-g++ \
-DCMAKE_NM="$TOOLCHAIN_DIR"/bin/loongarch64-linux-gnu-nm \
-DCMAKE_RANLIB="$TOOLCHAIN_DIR"/bin/loongarch64-linux-gnu-ranlib \
-DCMAKE_SYSROOT="$SYSROOT_DIR" \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCMAKE_C_COMPILER_TARGET="loongarch64" \
-DCMAKE_CXX_COMPILER_TARGET="loongarch64" \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCMAKE_C_FLAGS="$LA_FLAGS" \
-DCMAKE_CXX_FLAGS="$LA_FLAGS" \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_INSTALL_PREFIX="`$BIN_DIR/clang -print-resource-dir`" \
\
../compiler-rt -G Ninja
ninja
ninja install
2. 构建输出
构建输出归档在由CMAKE_INSTALL_PREFIX决定的目录。以LLVM8为例,归档在 $INSTALL_DIR/lib/clang/8.0.1目录。该目录结构如下:
include
lib
share