-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
474 lines (312 loc) · 10 KB
/
build.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/bin/sh
set -e
#--------------------------------------------------------------------------------------------------
# Settings
#--------------------------------------------------------------------------------------------------
target="HelloSky"
external="$PWD/../3rdparty"
Sky="$PWD/../Sky"
#--------------------------------------------------------------------------------------------------
Qt4_version="4.8.7"
Qt5_version="5.15.2"
Qt6_version="6.6.0"
#--------------------------------------------------------------------------------------------------
make_arguments="-j 4"
#--------------------------------------------------------------------------------------------------
# Windows
ProgramFiles="/c/Program Files (x86)"
BuildTools="$ProgramFiles/Microsoft Visual Studio/2019/BuildTools"
#--------------------------------------------------------------------------------------------------
MinGW_version="11.2.0"
jom_version="1.1.3"
MSVC_version="14"
WindowsKit_version="10"
#--------------------------------------------------------------------------------------------------
# Android
JDK_version="11.0.2"
SDK_version="34"
SDK_version_minimum="21"
NDK_version="26"
#--------------------------------------------------------------------------------------------------
# environment
compiler_win="mingw"
qt="qt5"
mobile="simulator"
#--------------------------------------------------------------------------------------------------
# Functions
#--------------------------------------------------------------------------------------------------
makeAndroid()
{
if [ ! -d "${1}" ]; then
mkdir $1
fi
cd $1
if [ $qt = "qt5" ]; then
qtconf=""
else
qtconf="-qtconf $2"
fi
$qmake -r -spec $spec $qtconf "$config" \
"ANDROID_ABIS=$1" \
"ANDROID_MIN_SDK_VERSION=$SDK_version_minimum" \
"ANDROID_TARGET_SDK_VERSION=$SDK_version" ../..
make $make_arguments
make INSTALL_ROOT=android-build install
cd ..
}
deployAndroid()
{
cd $1
cat android-$target-deployment-settings.json
"$androiddeployqt" --release --aab \
--input android-$target-deployment-settings.json \
--output android-build \
--android-platform android-$SDK_version \
--jdk $JAVA_HOME
cd -
}
#--------------------------------------------------------------------------------------------------
getOs()
{
case `uname` in
MINGW*) os="windows";;
Darwin*) os="macOS";;
Linux*) os="linux";;
*) os="other";;
esac
type=`uname -m`
if [ $type = "x86_64" ]; then
if [ $os = "windows" ]; then
echo win64
else
echo $os
fi
elif [ $os = "windows" ]; then
echo win32
else
echo $os
fi
}
getPath()
{
echo $(ls "$1" | grep $2 | tail -1)
}
#--------------------------------------------------------------------------------------------------
# Syntax
#--------------------------------------------------------------------------------------------------
if [ $# != 1 -a $# != 2 ] \
|| \
[ $1 != "win32" -a $1 != "win64" -a $1 != "macOS" -a $1 != "iOS" -a $1 != "linux" -a \
$1 != "android" ] \
|| \
[ $# = 2 -a "$2" != "all" -a "$2" != "deploy" -a "$2" != "clean" ]; then
echo "Usage: build <win32 | win64 | macOS | iOS | linux | android> [all | deploy | clean]"
exit 1
fi
#--------------------------------------------------------------------------------------------------
# All
#--------------------------------------------------------------------------------------------------
if [ "$2" = "all" ]; then
sh 3rdparty.sh $1 all
sh configure.sh $1 sky
cd "$Sky"
sh build.sh $1 tools
cd -
sh build.sh $1 deploy
exit 0
fi
#--------------------------------------------------------------------------------------------------
# Configuration
#--------------------------------------------------------------------------------------------------
host=$(getOs)
external="$external/$1"
if [ $1 = "win32" -o $1 = "win64" ]; then
os="windows"
compiler="$compiler_win"
if [ $compiler = "mingw" ]; then
MinGW="$external/MinGW/$MinGW_version/bin"
else
jom="$external/jom/$jom_version"
MSVC_version=$(getPath "$BuildTools/VC/Tools/MSVC" $MSVC_version)
MSVC="$BuildTools/VC/Tools/MSVC/$MSVC_version"
WindowsKit="$ProgramFiles/Windows Kits/$WindowsKit_version"
WindowsKit_version=$(getPath "$WindowsKit/bin" $WindowsKit_version)
echo "MSVC version $MSVC_version"
echo ""
echo "WindowsKit version $WindowsKit_version"
echo ""
if [ $1 = "win32" ]; then
abi="x86"
else
abi="x64"
fi
fi
else
if [ $1 = "android" -a $host != "linux" ]; then
echo "You have to cross-compile $1 from Linux (preferably Ubuntu)."
exit 1
fi
os="default"
compiler="default"
fi
if [ $qt = "qt4" ]; then
Qt="$external/Qt/$Qt4_version"
elif [ $qt = "qt5" ]; then
Qt="$external/Qt/$Qt5_version"
else
Qt="$external/Qt/$Qt6_version"
fi
if [ $qt = "qt6" ]; then
if [ $1 = "iOS" ]; then
QtBin="$Qt/macos/bin"
elif [ $1 = "android" ]; then
QtBin="$Qt/gcc_64/bin"
else
QtBin="$Qt/bin"
fi
else
QtBin="$Qt/bin"
fi
qmake="$QtBin/qmake"
#--------------------------------------------------------------------------------------------------
# Clean
#--------------------------------------------------------------------------------------------------
if [ "$2" = "clean" ]; then
echo "CLEANING"
# NOTE: We have to remove the folder to delete .qmake.stash.
rm -rf build
mkdir build
touch build/.gitignore
exit 0
fi
#--------------------------------------------------------------------------------------------------
# Build HelloSky
#--------------------------------------------------------------------------------------------------
echo "BUILDING $target"
echo "-----------------"
export QT_SELECT="$qt"
if [ $qt = "qt4" ]; then
config="CONFIG += release"
else
config="CONFIG += release qtquickcompiler"
fi
if [ $compiler = "mingw" ]; then
spec=win32-g++
PATH="$Qt/bin:$MinGW:$PATH"
elif [ $compiler = "msvc" ]; then
if [ $qt = "qt4" ]; then
spec=win32-msvc2015
else
spec=win32-msvc
fi
PATH="$jom:$MSVC/bin/Host$abi/$abi:\
$WindowsKit/bin/$WindowsKit_version/$abi:\
$Qt/bin:$PATH"
export INCLUDE="$MSVC/include:\
$WindowsKit/Include/$WindowsKit_version/ucrt:\
$WindowsKit/Include/$WindowsKit_version/um:\
$WindowsKit/Include/$WindowsKit_version/shared"
export LIB="$MSVC/lib/$abi:\
$WindowsKit/Lib/$WindowsKit_version/ucrt/$abi:\
$WindowsKit/Lib/$WindowsKit_version/um/$abi"
elif [ $1 = "macOS" ]; then
spec=macx-clang
export PATH="$Qt/bin:$PATH"
elif [ $1 = "iOS" ]; then
spec=macx-ios-clang
if [ $mobile = "device" ]; then
config="$config iphoneos device"
fi
elif [ $1 = "linux" ]; then
if [ -d "/usr/lib/x86_64-linux-gnu" ]; then
spec=linux-g++-64
else
spec=linux-g++-32
fi
elif [ $1 = "android" ]; then
spec=android-clang
export JAVA_HOME="$external/JDK/$JDK_version"
export ANDROID_SDK_ROOT="$external/SDK/$SDK_version"
export ANDROID_NDK_ROOT="$external/NDK/$NDK_version"
export ANDROID_NDK_PLATFORM="android-$SDK_version"
# NOTE android: This variable enforces the linux clang compiler.
export ANDROID_NDK_HOST="linux-x86_64"
fi
$qmake --version
echo ""
cd content
if [ "$2" = "deploy" ]; then
sh generate.sh $1 deploy
else
sh generate.sh $1
fi
echo ""
cd ../build
if [ "$2" = "deploy" ]; then
config="$config deploy"
fi
if [ $1 = "iOS" ]; then
if [ $qt = "qt5" ]; then
qtconf=""
else
qtconf="-qtconf $Qt/ios/bin/target_qt.conf"
fi
$qmake -r -spec $spec "$config" $qtconf ..
if [ $qt = "qt5" ]; then
# NOTE iOS: Replacing WorkspaceSettings with a proper one. Otherwise the legacy build
# system stops the compilation.
cp "$Sky"/dist/iOS/WorkspaceSettings.xcsettings \
$target.xcodeproj/project.xcworkspace/xcshareddata
fi
elif [ $1 = "android" ]; then
makeAndroid armeabi-v7a "$Qt"/android_armv7/bin/target_qt.conf
makeAndroid arm64-v8a "$Qt"/android_arm64_v8a/bin/target_qt.conf
makeAndroid x86 "$Qt"/android_x86/bin/target_qt.conf
makeAndroid x86_64 "$Qt"/android_x86_64/bin/target_qt.conf
else
$qmake -r -spec $spec "$config" ..
fi
if [ $compiler = "mingw" ]; then
mingw32-make $make_arguments
elif [ $compiler = "msvc" ]; then
jom
elif [ $1 = "iOS" ]; then
set +e
# FIXME iOS: For some reason, we have to call this several times to build and deploy properly.
if [ $qt = "qt5" ]; then
make $make_arguments
make $make_arguments
else
make $make_arguments
fi
set -e
make $make_arguments
elif [ $1 = "android" ]; then
#----------------------------------------------------------------------------------------------
# FIXME android/Qt: We have to call androiddeployqt to generate a release apk.
if [ $qt = "qt5" ]; then
# NOTE android/Qt5: We use a custom androiddeployqt that supports the latest NDK.
androiddeployqt="$Sky/deploy/androiddeployqt"
else
androiddeployqt="$QtBin/androiddeployqt"
fi
deployAndroid armeabi-v7a
deployAndroid arm64-v8a
deployAndroid x86
deployAndroid x86_64
#----------------------------------------------------------------------------------------------
else
make $make_arguments
fi
cd ..
echo "-----------------"
#--------------------------------------------------------------------------------------------------
# Deploying HelloSky
#--------------------------------------------------------------------------------------------------
if [ "$2" = "deploy" ]; then
echo ""
echo "DEPLOYING $target"
echo "------------------"
sh deploy.sh $1
echo "------------------"
fi