-
Notifications
You must be signed in to change notification settings - Fork 10
/
buildllvm.sh
executable file
·219 lines (189 loc) · 5.86 KB
/
buildllvm.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
#
# On Linux this script builds LLVM/Clang libraries into subdirectories in
# the $HOME/invariant dir. LLVM sources must be found from the current user's
# home directory $HOME/invariant/llvm.
#
# On Windows and macOS this script downloads the LLVM/Clang libraries and
# extracts it into the $HOME/invariant dir.
#
#
# Copyright (C) 2014-2019 Jolla Ltd.
# Copyright (C) 2020 Open Mobile Platform LLC.
# Contact: http://jolla.com/
# All rights reserved.
#
# You may use this file under the terms of BSD license as follows:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Jolla Ltd nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
export LC_ALL=C
. $(dirname $0)/defaults.sh
. $(dirname $0)/utils.sh
configure_llvm() {
export CC=gcc-9 CXX=g++-9
# See Qt Creator's README
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D LLVM_ENABLE_RTTI=ON \
-D LLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
-D CMAKE_INSTALL_PREFIX=$DEF_LLVM_INSTALL_DIR \
$DEF_LLVM_SRC_DIR/llvm
}
build_llvm() {
rm -rf $DEF_LLVM_BUILD_DIR
mkdir -p $DEF_LLVM_BUILD_DIR
pushd $DEF_LLVM_BUILD_DIR
configure_llvm
make -j$(nproc)
rm -rf $DEF_LLVM_INSTALL_DIR
make install
popd
}
download_llvm_windows() {
local download_dest=$DEF_LLVM_DOWNLOAD_DIR/${DEF_WIN_LLVM_DOWNLOAD_URL##*/}
curl -o $download_dest $DEF_WIN_LLVM_DOWNLOAD_URL
rm -rf $DEF_LLVM_INSTALL_DIR
7z -y -o$(dirname $DEF_LLVM_INSTALL_DIR) x $download_dest
[[ -d $DEF_LLVM_INSTALL_DIR ]] || fail "Fixme: Name of the LLVM/Clang archive root directory has changed"
}
download_llvm_mac() {
local download_dest=$DEF_LLVM_DOWNLOAD_DIR/${DEF_MAC_LLVM_DOWNLOAD_URL##*/}
curl -o $download_dest $DEF_MAC_LLVM_DOWNLOAD_URL
rm -rf $DEF_LLVM_INSTALL_DIR
7z -y -o$(dirname $DEF_LLVM_INSTALL_DIR) x $download_dest
[[ -d $DEF_LLVM_INSTALL_DIR ]] || fail "Fixme: Name of the LLVM/Clang archive root directory has changed"
}
build_arch() {
if [[ $UNAME_SYSTEM == "Linux" ]]; then
echo "linux"
elif [[ $UNAME_SYSTEM == "Darwin" ]]; then
echo "mac"
else
echo "windows"
fi
}
fail() {
echo "FAIL: $@"
exit 1
}
usage() {
if [[ $(build_arch) == "linux" ]]; then
cat <<EOF
Build LLVM/Clang
Prerequisites:
- LLVM/Clang sources
[$DEF_LLVM_SRC_DIR]
- LLVM/Clang build directory (will be created)
[$DEF_LLVM_BUILD_DIR]
- LLVM/Clang installation directory (will be created)
[$DEF_LLVM_INSTALL_DIR]
EOF
else
cat <<EOF
Download LLVM/Clang
Prerequisites:
- Download directory for LLVM/Clang binaries (must exist)
[$DEF_LLVM_DOWNLOAD_DIR]
- LLVM/Clang installation directory (will be created)
[$DEF_LLVM_INSTALL_DIR]
EOF
fi
cat <<EOF
Usage:
$(basename $0) [OPTION]
Options:
-y | --non-interactive answer yes to all questions presented by the script
-h | --help this help
EOF
# exit if any argument is given
[[ -n "$1" ]] && exit 1
}
# handle commandline options
while [[ ${1:-} ]]; do
case "$1" in
-y | --non-interactive ) shift
OPT_YES=1
;;
-h | --help ) shift
usage quit
;;
* )
usage quit
;;
esac
done
if [[ $(build_arch) == "linux" ]]; then
echo "Using sources from [$DEF_LLVM_SRC_DIR]"
elif [[ $(build_arch) == "mac" ]]; then
echo "Downloading LLVM/Clang from [$DEF_MAC_LLVM_DOWNLOAD_URL]"
else
echo "Downloading LLVM/Clang from [$DEF_WIN_LLVM_DOWNLOAD_URL]"
fi
# confirm
if [[ -z $OPT_YES ]]; then
while true; do
read -p "Do you want to continue? (y/n) " answer
case $answer in
[Yy]*)
break ;;
[Nn]*)
echo "Ok, exiting"
exit 0
;;
*)
echo "Please answer yes or no."
;;
esac
done
fi
if [[ $(build_arch) != "linux" && ! -d $DEF_LLVM_DOWNLOAD_DIR ]]; then
fail "directory [$DEF_LLVM_DOWNLOAD_DIR] does not exist"
fi
if [[ $(build_arch) == "linux" && ! -d $DEF_LLVM_SRC_DIR ]]; then
fail "directory [$DEF_LLVM_SRC_DIR] does not exist"
fi
# stop in case of errors
set -e
# record start time
BUILD_START=$(date +%s)
if [[ $(build_arch) == "linux" ]]; then
build_llvm
else
download_llvm_"$(build_arch)"
fi
# record end time
BUILD_END=$(date +%s)
time=$(( BUILD_END - BUILD_START ))
hour=$(( $time / 3600 ))
mins=$(( $time / 60 - 60*$hour ))
secs=$(( $time - 3600*$hour - 60*$mins ))
echo Time used for LLVM/Clang build: $(printf "%02d:%02d:%02d" $hour $mins $secs)
# For Emacs:
# Local Variables:
# indent-tabs-mode:nil
# tab-width:8
# sh-basic-offset:4
# End:
# For VIM:
# vim:set softtabstop=4 shiftwidth=4 tabstop=8 expandtab: