-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-llvm.sh
163 lines (120 loc) · 4.95 KB
/
build-llvm.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
#!/bin/sh
#
# This script is designed to be sourced in build.sh
#
# llvm-configure-basic.sh uses CONFIGURE variable that depends on LOG_RULE_TEMPLATE (see testbuild.profile)
export LOG_NAME=llvm-build
export LLVM_SOURCE_DIR=$BUILD_DIR/llvm-$LLVM_VERSION
if [ -n "$LLVM_INSTALL_DIR" ]; then
LLVM_MAKE_INSTALL=$MAKE_INSTALL
LLVM_PREFIX_DIR="--prefix-dir=$LLVM_INSTALL_DIR"
else
LLVM_MAKE_INSTALL=
# If we pass --prefix-dir=$LLVM_SOURCE_DIR/$LLVM_BUILD_OUTPUT, then
# Makes.rules in LLVM breaks because it sees a conflict between the
# built products location and the install destination. So we must be
# sure the LLVM configure uses the default prefix (/usr/local) if we
# plan no installation.
LLVM_PREFIX_DIR=
# If there is no install dir, LLVM_INSTALL_DIR is set to the build output
# directories... bin and lib inside LLVM_SOURCE_DIR
LLVM_INSTALL_DIR=$LLVM_SOURCE_DIR/$LLVM_BUILD_OUTPUT
fi
# LLVM git mirror
LLVM_URL_GIT=http://llvm.org/git/llvm.git
# Clang git mirror
CLANG_URL_GIT=http://llvm.org/git/clang.git
if [ "$LLVM_VERSION" = "packaged" ]; then
echo "Using packaged version of LLVM/clang"
# FIXME: Support LLVM 3.4 packages and higher.
HAVE_CLANG_3_3=$(dpkg -s clang-3.3 | grep "install ok installed")
if [ -z "$HAVE_CLANG_3_3" ]; then
echo "Warning: LLVM/clang 3.3 package is not installed (more recent packages are not supported yet)"
export STATUS=1
else
# Workaround for:
# https://bugs.launchpad.net/ubuntu/+source/llvm-3.1/+bug/991493
if [ ! -f /usr/bin/llvm-config ]; then
echo "Symlinking /usr/bin/llvm-config to /usr/bin/llvm-config-3.3"
sudo ln -s /usr/bin/llvm-config-3.3 /usr/bin/llvm-config
fi
export STATUS=0
fi
elif [ "$LLVM_VERSION" = "trunk" ]; then
if [ "$LLVM_ACCESS" = "svn" ]; then
echo "Fetching LLVM and Clang $LLVM_VERSION using SVN"
${LLVM_SVN_ACCESS}llvm.org/svn/llvm-project/llvm/${LLVM_VERSION} $LLVM_SOURCE_DIR
${LLVM_SVN_ACCESS}llvm.org/svn/llvm-project/cfe/${LLVM_VERSION} $LLVM_SOURCE_DIR/tools/clang
elif [ "$LLVM_ACCESS" = "git" ]; then
if [ ! -d $LLVM_SOURCE_DIR ]; then
echo "Fetching LLVM trunk using a GIT mirror at $LLVM_URL_GIT"
git clone $LLVM_URL_GIT $LLVM_SOURCE_DIR
else
echo "Updating LLVM trunk using a GIT mirror at $LLVM_URL_GIT"
git pull $LLVM_SOURCE_DIR
fi
fi
elif [ -n "$LLVM_VERSION" -a ! -d $LLVM_SOURCE_DIR ]; then
echo "Fetching LLVM $LLVM_VERSION from LLVM release server"
wget -nc http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.gz
tar -xzf llvm-${LLVM_VERSION}.src.tar.gz
# Starting from 3.4, there is no '.src' suffix in the unarchived directory names
if [ -d llvm-${LLVM_VERSION}.src ]; then
mv llvm-${LLVM_VERSION}.src llvm-${LLVM_VERSION}
UNARCHIVE_DIR_SUFFIX=".src"
fi
echo "Fetching Clang $LLVM_VERSION from LLVM release server"
# For the release 3.4, the archive was named 'clang', starting with 3.4.1, they
# reverted to 'cfe'
CLANG_BASE_NAME=cfe-${LLVM_VERSION}
CLANG_ALT_BASE_NAME=clang-${LLVM_VERSION}
if ! wget -q --spider http://llvm.org/releases/${LLVM_VERSION}/${CLANG_BASE_NAME}.src.tar.gz; then
CLANG_BASE_NAME=$CLANG_ALT_BASE_NAME
fi
wget -nc http://llvm.org/releases/${LLVM_VERSION}/${CLANG_BASE_NAME}.src.tar.gz
tar -xzf $CLANG_BASE_NAME.src.tar.gz
mv ${CLANG_BASE_NAME}${UNARCHIVE_DIR_SUFFIX} llvm-${LLVM_VERSION}/tools/clang
elif [ -z "$LLVM_VERSION" ]; then
HAVE_CLANG_3_3_OR_HIGHER=$(clang -v 2>&1 | grep "clang version 3.[3-9]")
if [ -z "$HAVE_CLANG_3_3_OR_HIGHER" ]; then
echo "Warning: LLVM/clang 3.3 or higher is not installed (older versions are not supported)"
export STATUS=1
else
export STATUS=0
fi
fi
echo
if [ -n "$LLVM_VERSION" -a "$LLVM_VERSION" != "packaged" -a -n "$LLVM_VERSION" ]; then
echo "Building and Installing LLVM and Clang"
echo
# If LLVM has been successfully configured once, the codebase is not recompiled
# from scratch on every build unless --force-llvm-configure option is passed to build.sh
LLVM_CONFIG_SUCCESS_FILE="$LLVM_SOURCE_DIR/config.success"
if [ -f $LLVM_CONFIG_SUCCESS_FILE -a "$FORCE_LLVM_CONFIGURE" != "yes" ]; then
LLVM_CONFIGURE_ONCE=
else
LLVM_CONFIGURE_ONCE="eval $SCRIPT_DIR/$LLVM_CONFIGURE && touch $LLVM_CONFIG_SUCCESS_FILE"
fi
cd $LLVM_SOURCE_DIR
($DUMP_ENV) && ($LLVM_CONFIGURE_ONCE) && ($MAKE_BUILD) && ($LLVM_MAKE_INSTALL)
export STATUS=$?
cd ..
fi
if [ $STATUS -eq 0 ]; then
rm -f $LLVM_ENV_FILE
# Put LLVM in the path (it must come first to take over any prior LLVM install)
if [ "$LLVM_VERSION" = "packaged" ]; then
( echo "export PATH=/usr/bin:\$PATH"
echo "export LD_LIBRARY_PATH=/usr/lib:\$LD_LIBRARY_PATH"
echo "export CC=clang"
echo "export CXX=clang++" ) > $LLVM_ENV_FILE
elif [ -n "$LLVM_VERSION" ]; then
( echo "export PATH=$LLVM_INSTALL_DIR/bin:\$PATH"
echo "export LD_LIBRARY_PATH=$LLVM_INSTALL_DIR/lib:\$LD_LIBRARY_PATH"
echo "export CC=clang"
echo "export CXX=clang++" ) > $LLVM_ENV_FILE
else
( echo "export CC=clang"
echo "export CXX=clang++" ) > $LLVM_ENV_FILE
fi
fi