-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcompile_clang.sh
executable file
·185 lines (160 loc) · 5.96 KB
/
compile_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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------
LLVM_VERSION="5.0.0"
DEFAULT_COLOR='\033[0m'
ERROR_COLOR='\033[0;31m'
GREEN_COLOR='\033[0;32m'
CC_URL="git://sourceware.org/git/binutils-gdb.git\nhttp://llvm.org/releases/${LLVM_VERSION}/\n"
if [[ $1 == '-y' || $1 == '-Y' ]]; then
ALWAYS_YES=1
fi
WARN_LICENSE () {
echo -e "${ERROR_COLOR}"
echo -e "----------------------------------------------------------------"
echo -e "${DEFAULT_COLOR}"
echo -e "This script will download LLVM/CLANG and LLVM Gold Bintools from\n${CC_URL}\n"
echo "These software are licensed to you by its publisher(s), not Microsoft."
echo "Microsoft is not responsible for the software."
echo "Your installation and use of the software is subject to the publisher's terms available here:"
echo -e "http://llvm.org/docs/DeveloperPolicy.html#license\nhttp://llvm.org/docs/GoldPlugin.html#licensing"
echo -e "${ERROR_COLOR}"
echo -e "----------------------------------------------------------------\n"
echo -e "${GREEN_COLOR}If you don't agree, press Ctrl+C to terminate${DEFAULT_COLOR}"
WAIT_QUESTION="Hit ENTER to continue (or wait 20 seconds)"
if [[ $ALWAYS_YES == 1 ]]; then
echo "$WAIT_QUESTION : Y"
else
read -t 20 -p "$WAIT_QUESTION"
fi
echo -e "\nWell, this will take some time... [and free memory 2GB+]\n"
}
WARN_PACKAGE () {
echo -e "\n${GREEN_COLOR}"
echo -e "----------------------------------------------------------------${DEFAULT_COLOR}"
echo "This script requires (texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel)"
echo "Automated installation of these requirements is supported with apt-get and yum only."
echo ""
echo "If you don't have these packages are installed, press Ctrl+C to terminate"
echo -e "${GREEN_COLOR}----------------------------------------------------------------"
echo -e "${DEFAULT_COLOR}"
WAIT_QUESTION="Hit ENTER to continue (or wait 20 seconds)"
if [[ $ALWAYS_YES == 1 ]]; then
echo "$WAIT_QUESTION : Y"
else
read -t 20 -p "$WAIT_QUESTION"
fi
}
DOWNLOAD_HELPER() {
WGET_CTR=1
while [ 1 ]; do
wget --no-dns-cache --tries=3 --retry-connrefused --waitretry=3 $1 >/dev/null 2>&1
if [[ $? == 0 ]]; then
break;
else
if [[ $WGET_CTR == 3 ]]; then
echo "Failed to download $1"
exit 1
fi
WGET_CTR=$(($WGET_CTR + 1))
echo "${WGET_CTR}. try...."
fi
done;
}
ROOT=${PWD}/cc-toolchain/
GOLD_PLUGIN=""
if [ ! -d ./cc-toolchain/src/llvm/projects/compiler-rt ]; then
rm -rf cc-toolchain
mkdir cc-toolchain
cd cc-toolchain
mkdir src
mkdir bin
cd src
if [[ "$OSTYPE" =~ "darwin" ]]; then # osx
echo "This script is not prepared for OSX"
exit 0
else
WARN_LICENSE
apt-get -v >/dev/null 2>&1
if [ $? == 0 ]; then # debian
apt-get install -y apt-file texinfo texi2html csh gawk automake libtool \
libtool-bin bison flex libncurses5-dev
if [ $? != 0 ]; then
WARN_PACKAGE
fi
else
yum -v >/dev/null 2>&1
if [ $? == 0 ]; then # redhat
yum install -y texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel
else
WARN_PACKAGE
fi
fi
fi
mkdir lto_utils
cd lto_utils
echo "Downloading LLVM Gold Plugin"
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils >/dev/null 2>&1
mkdir binutils_compile; cd binutils_compile
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ROOT}/build/lib/"
../binutils/configure --enable-gold --enable-plugins --disable-werror --prefix="${ROOT}/build"
make -j4
make install
if [ $? != 0 ]; then
exit 1
fi
echo -e "\n\n\n\n"
cd "${ROOT}/src/"
echo "Downloading LLVM ${LLVM_VERSION}"
DOWNLOAD_HELPER "http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
tar xf "llvm-${LLVM_VERSION}.src.tar.xz"
if [ $? == 0 ]; then
rm "llvm-${LLVM_VERSION}.src.tar.xz"
mv "llvm-${LLVM_VERSION}.src" llvm
else
exit 1
fi
cd llvm/tools/
echo "Downloading Clang ${LLVM_VERSION}"
DOWNLOAD_HELPER "http://llvm.org/releases/${LLVM_VERSION}/cfe-${LLVM_VERSION}.src.tar.xz"
tar xf "cfe-${LLVM_VERSION}.src.tar.xz"
if [ $? == 0 ]; then
mv "cfe-${LLVM_VERSION}.src" clang
rm "cfe-${LLVM_VERSION}.src.tar.xz"
else
exit 1
fi
mkdir -p ../projects/
cd ../projects/
echo "Downloading Compiler-RT ${LLVM_VERSION}"
DOWNLOAD_HELPER "http://llvm.org/releases/${LLVM_VERSION}/compiler-rt-${LLVM_VERSION}.src.tar.xz"
tar xf "compiler-rt-${LLVM_VERSION}.src.tar.xz"
if [ $? == 0 ]; then
mv "compiler-rt-${LLVM_VERSION}.src" compiler-rt
rm "compiler-rt-${LLVM_VERSION}.src.tar.xz"
else
exit 1
fi
fi
GOLD_PLUGIN=-DLLVM_BINUTILS_INCDIR="${ROOT}/src/lto_utils/binutils/include"
mkdir -p "${ROOT}/build"
cd "${ROOT}/src/llvm"
mkdir -p build_
cd build_
cmake ../ -DCMAKE_INSTALL_PREFIX="${ROOT}/build" -DCMAKE_BUILD_TYPE=Release ${GOLD_PLUGIN}
if [ $? != 0 ]; then
cd ..
rm -rf build_
mkdir build_
exit 1
fi
make -j4 install
if [ $? == 0 ]; then
echo -e "Done!\n./build.sh args are given below;\n\n"
# Create a local bfd-plugins and copy LLVMgold.so into there.
mkdir -p "${ROOT}/build/lib/bfd-plugins/"
cp "${ROOT}/build/lib/LLVMgold.so" "${ROOT}/build/lib/bfd-plugins/"
echo "--cxx=${ROOT}/build/bin/clang++ --cc=${ROOT}/build/bin/clang"
fi