forked from tpoechtrager/osxcross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_clang.sh
executable file
·171 lines (132 loc) · 3.39 KB
/
build_clang.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
#
# Build and install Clang/LLVM, using `gcc`.
#
# You only need to run this if your distribution does not provide
# clang - or if you want to build your own version from a recent
# source tree.
#
pushd "${0%/*}" &>/dev/null
DESC=clang
USESYSTEMCOMPILER=1
source tools/tools.sh
mkdir -p $BUILD_DIR
source $BASE_DIR/tools/trap_exit.sh
if [ -z "$CLANG_VERSION" ]; then
CLANG_VERSION=10.0.1
fi
if [ -z "$INSTALLPREFIX" ]; then
INSTALLPREFIX="/usr/local"
fi
require cmake
LLVM_PKG=""
CLANG_PKG=""
function set_package_link()
{
pushd $BUILD_DIR &>/dev/null
download https://releases.llvm.org/download.html &>/dev/null
if [[ $(file download.html) == *gzip* ]]; then
mv download.html download.html.gz
require gzip
gzip -d download.html.gz
fi
links=$(cat download.html | grep -Po '(?<=href=")[^"]*' | grep -v "\.sig")
rm -f download.html
LLVM_PKG=$(echo "$links" | grep "llvm-$CLANG_VERSION.src" | head -n 1 || true)
CLANG_PKG=$(echo "$links" | grep -E "(clang|cfe)-$CLANG_VERSION.src" | head -n 1 || true)
if [ -n "$LLVM_PKG" ] && [[ $LLVM_PKG != https* ]]; then
LLVM_PKG="https://releases.llvm.org/$LLVM_PKG"
CLANG_PKG="https://releases.llvm.org/$CLANG_PKG"
fi
popd &>/dev/null
}
set_package_link
if [ -z "$LLVM_PKG" ] || [ -z "$CLANG_PKG" ]; then
echo "Release $CLANG_VERSION not found!" 1>&2
exit 1
fi
function warn_if_installed()
{
set +e
command -v $1 &>/dev/null && \
{
echo ""
echo "It is highly recommended to uninstall previous $2 versions first:"
echo "-> $(command -v $1 2>/dev/null)"
echo ""
}
set -e
}
if [ $PLATFORM != "Darwin" -a $PLATFORM != "FreeBSD" ]; then
warn_if_installed clang clang
warn_if_installed llvm-config llvm
fi
echo "Building Clang/LLVM $CLANG_VERSION may take a long time."
echo "Installation Prefix: $INSTALLPREFIX"
if [ -z "$UNATTENDED" ]; then
echo ""
read -p "Press enter to start building."
echo ""
fi
pushd $TARBALL_DIR &>/dev/null
download $LLVM_PKG
download $CLANG_PKG
popd &>/dev/null
pushd $BUILD_DIR &>/dev/null
echo "cleaning up ..."
rm -rf llvm* 2>/dev/null
extract "$TARBALL_DIR/$(basename $LLVM_PKG)"
pushd llvm* &>/dev/null
pushd tools &>/dev/null
extract "$TARBALL_DIR/$(basename $CLANG_PKG)"
echo ""
[ -e clang* ] && mv clang* clang
[ -e cfe* ] && mv cfe* clang
popd &>/dev/null
function build()
{
stage=$1
mkdir -p $stage
pushd $stage &>/dev/null
cmake .. \
-DCMAKE_INSTALL_PREFIX=$INSTALLPREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=OFF \
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1
$MAKE $2 -j $JOBS VERBOSE=1
popd &>/dev/null
}
if [ -n "$DISABLE_BOOTSTRAP" ]; then
build build
else
build build_stage1 clang
export CC=$PWD/build_stage1/bin/clang
export CXX=$PWD/build_stage1/bin/clang++
if [ -z "$PORTABLE" ]; then
export CFLAGS="-march=native"
export CXXFLAGS="-march=native"
fi
build build_stage2
if [ -n "$ENABLE_FULL_BOOTSTRAP" ]; then
CC=$PWD/build_stage2/bin/clang \
CXX=$PWD/build_stage2/bin/clang++ \
build build_stage3
fi
fi
if [ -z "$ENABLE_CLANG_INSTALL" ]; then
echo ""
echo "Done!"
echo ""
echo -n "cd into '$PWD/$stage' and type 'make install' to install "
echo "clang/llvm to '$INSTALLPREFIX'"
echo ""
else
pushd $stage &>/dev/null
$MAKE install -j $JOBS VERBOSE=1
popd &>/dev/null
echo ""
echo "Done!"
echo ""
fi
popd &>/dev/null # llvm
popd &>/dev/null