forked from lordhoto/ios-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-clang.sh
executable file
·94 lines (75 loc) · 2.4 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
#!/bin/bash
#
# Copyright (c) 2016 Johannes Schickel <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE
LLVM_VERSION=3.7.1
SOURCE_DIR=`pwd`
BUILD_DIR=build/
if [ -z "PARALLELISM" ]; then
PARALLELISM=2
fi
LLVM_PACKAGES="llvm cfe"
if [ -z "$IOS_TOOLCHAIN_BASE" ]; then
echo "ERROR: \$IOS_TOOLCHAIN_BASE needs to be set to the path where clang should be installed."
exit 1
fi
IOS_TOOLCHAIN_BASE=`realpath $IOS_TOOLCHAIN_BASE`
if [ -z "$NATIVE_ARCH" ]; then
# TODO: Pick native archtiecture in an automated fashion.
NATIVE_ARCH=X86
fi
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
echo "Downloading llvm+clang $LLVM_VERSION sources..."
for i in $LLVM_PACKAGES; do
URL="http://llvm.org/releases/$LLVM_VERSION/$i-$LLVM_VERSION.src.tar.xz"
wget -c -nv --show-progress --progress=bar:force $URL || exit 1
done
echo "Preparing soucres..."
for i in $LLVM_PACKAGES; do
rm -rf $i-$LLVM_VERSION.src
xz -dc $i-$LLVM_VERSION.src.tar.xz | tar xf - || exit 1
done
mv cfe-$LLVM_VERSION.src llvm-$LLVM_VERSION.src/tools/clang
cd llvm-$LLVM_VERSION.src
for i in `ls "$SOURCE_DIR/patches/clang/"`; do
echo "Applying patch $i..."
patch -p1 < "$SOURCE_DIR/patches/clang/$i" || exit 1
done
cd ..
echo "Building clang..."
mkdir -p clang-build
cd clang-build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$IOS_TOOLCHAIN_BASE" \
-DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="$NATIVE_ARCH;ARM" \
../llvm-$LLVM_VERSION.src || exit 1
make -j$PARALLELISM || exit 1
make install || exit 1
cd ..
# We add a fake dsymutil for now. This allows to build libraries which always
# pass -g when building.
cat > "$IOS_TOOLCHAIN_BASE/bin/dsymutil" << EOF
#!/bin/sh
EOF
chmod +x "$IOS_TOOLCHAIN_BASE/bin/dsymutil"
cd "$SOURCE_DIR"
echo "Removing build directory..."
rm -r "$BUILD_DIR"