-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolchain.sh
executable file
·353 lines (290 loc) · 7.64 KB
/
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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
# Find absolute path (that works on both macOS and Linux)
TOOLCHAIN_ROOT=$(dirname ${BASH_SOURCE[0]})
if [ -z "$TOOLCHAIN_ROOT" ]; then
TOOLCHAIN_ROOT=$PWD
echo "Cannot find PWD forcing: $TOOLCHAIN_ROOT"
fi
cd $TOOLCHAIN_ROOT
TOOLCHAIN_ROOT=$(pwd -P)
cd -
function xcode_setup() {
sdk="$1"
xcode=$(xcode-select -p)
echo "Xcode is currently pointing to: '$xcode'"
echo ""
echo "Building TeamTalk toolchain has currently only been tested on Xcode 12.2."
echo "It is therefore recommended to download Xcode 12.2 from Apple and change"
echo "default Xcode to point to downloaded Xcode."
echo ""
echo "To change default Xcode run 'sudo xcode-select -s TOOLCHAIN_ROOT/Xcode.app/Contents/Developer'"
echo "where TOOLCHAIN_ROOT is the location of Xcode.app."
echo "To switch back run 'sudo xcode-select -s /Applications/Xcode.app/Contents/Developer'"
}
function mac64() {
echo "### Setting TeamTalk Toolchain up for Mac OS x86_64 ###"
if [ -z "$TTLIBS_ROOT" ]; then
TTLIBS_ROOT=$TOOLCHAIN_ROOT
fi
SDK=$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
MACOSX_DEPLOYMENT_TARGET=10.10
export SDK MACOSX_DEPLOYMENT_TARGET
echo "Exporting SDK environment variable. This is required by build ACE."
echo "TeamTalk toolchain will use $SDK"
echo "MACOSX_DEPLOYMENT_TARGET is $MACOSX_DEPLOYMENT_TARGET"
}
function ios_common() {
xcode_setup
export IPHONE_VERSION="" #compilation requires this
if [ -z "$1" ]; then
echo "1 = i386, 2 = x86_64, 3 = armv7, 4 = arm64"
read arch
case "$arch" in
"1")
arch=i386
;;
"2")
arch=x86_64
;;
"3")
arch=armv7
;;
"4")
arch=arm64
;;
*)
echo "Unknown arch"
return 1
;;
esac
else
arch=$1
fi
case "$arch" in
"i386")
ios_i386
ios_export
;;
"x86_64")
ios_x86_64
ios_export
;;
"armv7")
ios_armv7
ios_export
;;
"arm64")
ios_arm64
ios_export
;;
*)
echo "Unknown arch"
return 1
;;
esac
}
function ios_armv7() {
echo "### Setting TeamTalk up for iOS armv7 ###"
export IPHONE_TARGET=HARDWARE
export ARCH=armv7
SDK=$(xcode-select -p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
export SDK
}
function ios_arm64() {
echo "### Setting TeamTalk up for iOS arm64 ###"
export IPHONE_TARGET=HARDWARE
export ARCH=arm64
SDK=$(xcode-select -p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
export SDK
}
function ios_i386() {
echo "### Setting TeamTalk up for iOS Simulator i386 ###"
export IPHONE_TARGET=SIMULATOR
export ARCH=i386
SDK=$(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
export SDK
}
function ios_x86_64() {
echo "### Setting TeamTalk up for iOS Simulator x86_64 ###"
export IPHONE_TARGET=SIMULATOR
export ARCH=x86_64
SDK=$(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
export SDK
}
function ios_export() {
if [ -z "$TTLIBS_ROOT" ]; then
TTLIBS_ROOT=$TOOLCHAIN_ROOT/$ARCH
fi
export CC="clang"
if [ "$IPHONE_TARGET" = "SIMULATOR" ]; then
export CFLAGS=" -arch $ARCH -isysroot $SDK -mios-simulator-version-min=7.0"
else
export CFLAGS=" -arch $ARCH -isysroot $SDK -miphoneos-version-min=7.0 -fembed-bitcode"
fi
export CXX="$CC"
export CXXFLAGS=$CFLAGS
export LD="$CC"
export LDFLAGS=$CFLAGS
echo "Exporting SDK environment variable. This is required by build ACE."
echo "TeamTalk toolchain will use $SDK"
}
function linux() {
echo "### Setting TeamTalk Toolchain up for Linux ###"
if [ -z "$TTLIBS_ROOT" ]; then
TTLIBS_ROOT=$TOOLCHAIN_ROOT
fi
}
function android() {
if [ -z "$1" ]; then
echo "1 = armeabi-v7a, 2 = arm64-v8a, 3 = x86, 4 = x86_64"
read arch
case "$arch" in
"1")
arch=armeabi-v7a
;;
"2")
arch=arm64-v8a
;;
"3")
arch=x86
;;
"4")
arch=x86_64
;;
*)
echo "Unknown selection"
return 1
;;
esac
else
arch=$1
fi
if [ -z "$ANDROID_NDK_HOME" ]; then
NDK=$TOOLCHAIN_ROOT/android-ndk-r21
else
NDK=$ANDROID_NDK_HOME
fi
if ! test -d "$NDK"; then
echo "Android NDK not found. Must be placed in $NDK"
return 1
else
echo "Using Android NDK located in $NDK"
fi
ANDROID_APP_PLATFORM=android-21
ANDROID_APP_STL=c++_static
if [ "Darwin" = `uname -s` ]; then
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64
else
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
fi
case "$arch" in
"armeabi-v7a")
echo "### Setting TeamTalk up for Android armv7a ###"
ANDROID_APP_ABI=armeabi-v7a
ANDROID_ARCH=arm
;;
"arm64-v8a")
echo "### Setting TeamTalk up for Android arm64 ###"
ANDROID_APP_ABI=arm64-v8a
ANDROID_ARCH=arm64
;;
"x86")
echo "### Setting TeamTalk up for Android x86 ###"
ANDROID_APP_ABI=x86
ANDROID_ARCH=x86
;;
"x86_64")
echo "### Setting TeamTalk up for Android x86_64 ###"
ANDROID_APP_ABI=x86_64
ANDROID_ARCH=x86_64
;;
*)
echo "Unknown arch"
return 1
;;
esac
ANDROID_ABI=$ANDROID_APP_ABI
ARCH=$ANDROID_APP_ABI
SYSROOT=$TOOLCHAIN/sysroot
PATH=$TOOLCHAIN/bin:$PATH
if [ -z "$TTLIBS_ROOT" ]; then
TTLIBS_ROOT=$TOOLCHAIN_ROOT/$ARCH
fi
export ANDROID_ABI ANDROID_ARCH ARCH NDK SYSROOT TOOLCHAIN PATH ANDROID_APP_ABI ANDROID_APP_PLATFORM ANDROID_APP_STL
echo "Android NDK: $NDK"
echo "Android $ANDROID_APP_ABI toolchain: $TOOLCHAIN"
}
function win() {
if [ -z "$TTLIBS_ROOT" ]; then
TTLIBS_ROOT=$TOOLCHAIN_ROOT/build
fi
}
function win32() {
win
}
function win64() {
win
}
echo "1 = Win32, 2 = Win64, 3 = macOS, 4 = Android, 5 = iOS, 6 = Linux"
if [ -z "$1" ]; then
read platform
case "$platform" in
"1")
platform=win32
;;
"2")
platform=win64
;;
"3")
platform=mac
;;
"4")
platform=android
;;
"5")
platform=ios
;;
"6")
platform=linux
;;
*)
echo "Unknown arch"
return 1
;;
esac
else
platform=$1
fi
case "$platform" in
win32)
win32
;;
win64)
win64
;;
mac)
mac64
;;
android)
android $2
;;
ios)
ios_common $2
;;
linux)
linux
;;
*)
echo "Unknown platform"
return 1
;;
esac
if [ "$?" -eq 0 ]; then
echo "TOOLCHAIN_ROOT is now \"$TOOLCHAIN_ROOT\""
echo "TTLIBS_ROOT is now \"$TTLIBS_ROOT\""
export TTLIBS_ROOT TOOLCHAIN_ROOT
return 0
else
echo "Failed to set up toolchain"
return 1
fi