Skip to content

Commit 9f25db0

Browse files
committed
add build static lib script
1 parent 87f0227 commit 9f25db0

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

build_static_libs.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Build only static libraries of LLVM and Clang and install CMake packages
5+
6+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
SRC_DIR="${ROOT_DIR}/llvm"
8+
BUILD_DIR="${ROOT_DIR}/build-static"
9+
INSTALL_DIR="${ROOT_DIR}/install"
10+
11+
if [[ ! -d "${SRC_DIR}" ]]; then
12+
echo "Error: expected to find LLVM source at ${SRC_DIR}. Run this from the llvm-project root." >&2
13+
exit 1
14+
fi
15+
16+
# Configurables via env vars
17+
BUILD_TYPE="${BUILD_TYPE:-Release}"
18+
TARGETS_TO_BUILD="${LLVM_TARGETS_TO_BUILD:-host}"
19+
20+
if [[ "${CLEAN:-0}" == "1" ]]; then
21+
echo "[clean] Removing ${BUILD_DIR} and ${INSTALL_DIR}"
22+
rm -rf "${BUILD_DIR}" "${INSTALL_DIR}"
23+
fi
24+
25+
mkdir -p "${BUILD_DIR}" "${INSTALL_DIR}"
26+
27+
GENERATOR="Ninja"
28+
if ! command -v ninja >/dev/null 2>&1; then
29+
GENERATOR="Unix Makefiles"
30+
fi
31+
32+
echo "[configure] Generator: ${GENERATOR}"
33+
echo "[configure] Build type: ${BUILD_TYPE}"
34+
echo "[configure] Targets: ${TARGETS_TO_BUILD}"
35+
echo "[configure] Build dir: ${BUILD_DIR}"
36+
echo "[configure] Install dir: ${INSTALL_DIR}"
37+
38+
cmake -S "${SRC_DIR}" -B "${BUILD_DIR}" -G "${GENERATOR}" \
39+
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
40+
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
41+
-DLLVM_ENABLE_PROJECTS="clang" \
42+
-DLLVM_TARGETS_TO_BUILD="${TARGETS_TO_BUILD}" \
43+
-DBUILD_SHARED_LIBS=OFF \
44+
-DLLVM_ENABLE_PIC=ON \
45+
-DLLVM_ENABLE_RTTI=ON \
46+
-DLLVM_ENABLE_EH=ON \
47+
-DLLVM_LINK_LLVM_DYLIB=OFF \
48+
-DLLVM_BUILD_LLVM_C_DYLIB=OFF \
49+
-DLLVM_INCLUDE_TESTS=OFF \
50+
-DLLVM_INCLUDE_EXAMPLES=OFF \
51+
-DLLVM_INCLUDE_BENCHMARKS=OFF \
52+
-DLLVM_INCLUDE_DOCS=OFF \
53+
-DLLVM_ENABLE_BINDINGS=OFF \
54+
-DLLVM_BUILD_TOOLS=OFF \
55+
-DCLANG_INCLUDE_TESTS=OFF \
56+
-DCLANG_INCLUDE_DOCS=OFF \
57+
-DCLANG_BUILD_TOOLS=OFF \
58+
-DLIBCLANG_BUILD_STATIC=ON \
59+
${CMAKE_EXTRA_ARGS:-}
60+
61+
echo "[build] Building and installing to ${INSTALL_DIR}"
62+
cmake --build "${BUILD_DIR}" --target install -j "$(nproc)"
63+
64+
echo "[done] Static LLVM/Clang libraries and CMake packages installed under: ${INSTALL_DIR}"
65+
66+

0 commit comments

Comments
 (0)