-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup-toolchain.sh
executable file
·115 lines (102 loc) · 2.53 KB
/
setup-toolchain.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
#!/bin/sh
if [ $# -lt 2 ]; then
echo $0 cctools clang
exit 1
fi
if [ ! -d Contents/Developer/usr/bin ]; then
echo Execute this in the xcode dir root
exit 1
fi
CCTOOLS=$1
CLANG=$2
if [ ! -e $CCTOOLS/bin/lipo ]; then
echo lipo not found in $CCTOOLS
exit 1
fi
if [ ! -e $CLANG/bin/clang ]; then
echo clang not found in $CLANG
exit 1
fi
set -e
cd Contents/Developer/usr/bin
ln -sf /bin/true copypng
ln -sf /bin/true ibtool
cd ../../Toolchains/XcodeDefault.xctoolchain/usr/bin
TOOLS_SYMLINK="ar as cmpdylib ctf_insert dyldinfo install_name_tool ld libtool"
TOOLS_SYMLINK="$TOOLS_SYMLINK lipo nmedit pagestuff ranlib segedit size string"
TOOLS_SYMLINK="$TOOLS_SYMLINK strip unwinddump vtool"
for tool in $TOOLS_SYMLINK; do
ln -sf $CCTOOLS/bin/$tool .
done
cat<<EOF > clang
#!/bin/bash
ARGS=()
TARGET_SET=""
SYSROOT_SET=""
TOOL=\$(basename \$0 | sed 's/.*-\([^-]*\)/\1/')
ARCH=\$(basename \$0 | sed 's/-.*//')
case \$ARCH in
i386|x86_64|arm*)
ARGS+=(-target \$ARCH-apple-darwin16)
TARGET_SET=1
;;
*)
;;
esac
while [ \$# -gt 0 ]; do
a=\$1
if [ "\$a" = "-arch" ]; then
shift
ARGS+=(-target \$1-apple-darwin16 -arch \$1)
TARGET_SET=1
shift
else
if [ "\$a" = "-isysroot" ]; then
SYSROOT_SET=1
elif [ "\$a" = "-target" ]; then
TARGET_SET=1
fi
ARGS+=("\$a")
shift
fi
done
if [ -z "\$TARGET_SET" ]; then
ARGS+=(-target x86_64-apple-darwin16)
fi
if [ -z "\$SYSROOT_SET" ]; then
# Is there a better way to find the default sdk?
SDKS=\$DEVELOPER_DIR/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
SDK=\$SDKS/\$(ls \$SDKS | grep MacOSX1 | head -1)
ARGS+=(-isysroot \$SDK)
fi
export PATH=$CCTOOLS/bin:\$PATH
if [ "\$TOOL" = "clang++" ] || [ "\$TOOL" = "c++" ] || [ "\$TOOL" = "g++" ]; then
ARGS+=(--driver-mode=g++)
fi
ARGS+=(-no-canonical-prefixes)
EXE=\$(dirname \$(readlink -f \$0))/clang-exe
\$EXE "\${ARGS[@]}"
EOF
chmod a+x clang
ln -sf clang clang++
ln -sf clang cc
ln -sf clang c89
ln -sf clang c99
ln -sf clang c++
ln -sf clang gcc
ln -sf clang g++
ln -s $CLANG/bin/dsymutil .
ln -s $CLANG/bin/llvm-nm nm
ln -s $CLANG/bin/clang clang-exe
cd ../lib/clang
# Rename the original bundled clang resource directory to "orig", to avoid
# potential version number clashes.
mv * orig
# Fetch the version number of the resource directory of the clang we're
# using.
VER=$(cd $CLANG/lib/clang && ls)
# Link in the clang resource directory from the external installation into
# this directory.
ln -s $CLANG/lib/clang/$VER .
# Provide the original libraries in the external clang's resource directory.
ln -s $(pwd)/orig/lib/darwin $VER/lib