-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.sh
executable file
·87 lines (71 loc) · 2.16 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Display all commands before executing them.
set -o errexit
set -o errtrace
LLVM_VERSION=$1
LLVM_REPO_URL=${2:-https://github.com/llvm/llvm-project.git}
LLVM_CROSS="$3"
if [[ -z "$LLVM_REPO_URL" || -z "$LLVM_VERSION" ]]
then
echo "Usage: $0 <llvm-version> <llvm-repository-url> [aarch64/riscv64]"
echo
echo "# Arguments"
echo " llvm-version The name of a LLVM release branch without the 'release/' prefix"
echo " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)"
echo " aarch64 / riscv64 To cross-compile an aarch64/riscv64 version of LLVM"
exit 1
fi
# Clone the LLVM project.
if [ ! -d llvm-project ]
then
git clone -b "release/$LLVM_VERSION" --single-branch --depth=1 "$LLVM_REPO_URL" llvm-project
fi
cd llvm-project
git fetch origin
git checkout "release/$LLVM_VERSION"
git reset --hard origin/"release/$LLVM_VERSION"
# Create a directory to build the project.
mkdir -p build
cd build
# Create a directory to receive the complete installation.
mkdir -p install
# Adjust compilation based on the OS.
CMAKE_ARGUMENTS=""
case "${OSTYPE}" in
darwin*) ;;
linux*) ;;
*) ;;
esac
# Adjust cross compilation
CROSS_COMPILE=""
case "${LLVM_CROSS}" in
aarch64*) CROSS_COMPILE="-DLLVM_HOST_TRIPLE=aarch64-linux-gnu" ;;
riscv64*) CROSS_COMPILE="-DLLVM_HOST_TRIPLE=riscv64-linux-gnu" ;;
*) ;;
esac
# Run `cmake` to configure the project.
cmake \
-G Ninja \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX="/" \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TOOLS=ON \
-DLLVM_INCLUDE_UTILS=OFF \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64;RISCV;WebAssembly;LoongArch" \
"${CROSS_COMPILE}" \
"${CMAKE_ARGUMENTS}" \
../llvm
# Showtime!
cmake --build . --config MinSizeRel
DESTDIR=destdir cmake --install . --strip --config MinSizeRel
# move usr/bin/* to bin/ or llvm-config will be broken
if [ ! -d destdir/bin ];then
mkdir destdir/bin
fi
mv destdir/usr/bin/* destdir/bin/