-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapple-config.sh
executable file
·486 lines (423 loc) · 13.2 KB
/
apple-config.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
475
476
477
478
479
480
481
482
483
484
485
486
#!/bin/sh
# Automatic build environments script for Apple platforms
#
# Created by Yang Yubo on 2020.11.25.
# Copyright 2020 Yang Yubo. All rights reserved.
#
# Based on work of [openssl-apple](https://github.com/keeshux/openssl-apple)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Default (=full) set of targets
DEFAULTTARGETS=`cat <<TARGETS
ios-sim-cross-x86_64 ios-sim-cross-arm64 ios64-cross-arm64 ios64-cross-arm64e
macos64-x86_64 macos64-arm64
mac-catalyst-x86_64 mac-catalyst-arm64
watchos-cross-arm64_32 watchos-sim-cross-x86_64 watchos-sim-cross-arm64
tvos-sim-cross-x86_64 tvos-sim-cross-arm64 tvos-cross-arm64
xros-sim-cross-arm64 xros-cross-arm64
TARGETS`
# Minimum iOS/tvOS SDK version to build for
IOS_MIN_SDK_VERSION="12.0"
MACOS_MIN_SDK_VERSION="11.0"
CATALYST_MIN_SDK_VERSION="11.0"
WATCHOS_MIN_SDK_VERSION="4.0"
TVOS_MIN_SDK_VERSION="12.0"
XROS_MIN_SDK_VERSION="1.0"
isFunction() { declare -Ff "$1" >/dev/null; }
echo_help()
{
echo "Usage: ${0##*/} [options...]"
echo "Generic options"
echo " --cleanup Clean up build directories before starting build"
echo " -h, --help Print help (this message)"
echo " --ios-sdk=SDKVERSION Override iOS SDK version"
echo " --macos-sdk=SDKVERSION Override macOS SDK version"
echo " --catalyst-sdk=SDKVERSION Override macOS SDK version for Catalyst"
echo " --watchos-sdk=SDKVERSION Override watchOS SDK version"
echo " --tvos-sdk=SDKVERSION Override tvOS SDK version"
echo " --xros-sdk=SDKVERSION Override xrOS SDK version"
echo " --min-ios-sdk=SDKVERSION Set minimum iOS SDK version"
echo " --min-macos-sdk=SDKVERSION Set minimum macOS SDK version"
echo " --min-watchos-sdk=SDKVERSION Set minimum watchOS SDK version"
echo " --min-tvos-sdk=SDKVERSION Set minimum tvOS SDK version"
echo " -v, --verbose Enable verbose logging"
echo " --verbose-on-error Dump last 500 lines from log file if an error occurs (for Travis builds)"
echo " --targets=\"TARGET TARGET ...\" Space-separated list of build targets"
echo
echo "For custom configure options, set variable CONFIG_OPTIONS"
if isFunction extra_help; then
echo
echo "Extra options"
extra_help
fi
}
spinner()
{
local pid=$!
local delay=0.75
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c]" "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b"
done
wait $pid
return $?
}
# Check for error status
check_status()
{
local STATUS=$1
local COMMAND=$2
if [ "${STATUS}" != 0 ]; then
if [[ "${LOG_VERBOSE}" != "verbose"* ]]; then
echo "Problem during ${COMMAND} - Please check ${LOG}"
fi
# Dump last 500 lines from log file for verbose-on-error
if [ "${LOG_VERBOSE}" == "verbose-on-error" ]; then
echo "Problem during ${COMMAND} - Dumping last 500 lines from log file"
echo
tail -n 500 "${LOG}"
fi
exit 1
fi
}
define_condition()
{
local CONF_CURRENT=$1
DEFINE_CONDITION=
# Determine define condition
case "${CONF_CURRENT}" in
*_iPhoneOS_arm64.h)
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64"
;;
*_iPhoneOS_arm64e.h)
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64E"
;;
*_iPhoneSimulator_x86_64.h)
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_SIMULATOR && TARGET_CPU_X86_64"
;;
*_iPhoneSimulator_arm64.h)
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_SIMULATOR && TARGET_CPU_ARM64"
;;
*_MacOSX_x86_64.h)
DEFINE_CONDITION="TARGET_OS_OSX && TARGET_CPU_X86_64"
;;
*_MacOSX_arm64.h)
DEFINE_CONDITION="TARGET_OS_OSX && TARGET_CPU_ARM64"
;;
*_Catalyst_x86_64.h)
DEFINE_CONDITION="(TARGET_OS_MACCATALYST || (TARGET_OS_IOS && TARGET_OS_SIMULATOR)) && TARGET_CPU_X86_64"
;;
*_Catalyst_arm64.h)
DEFINE_CONDITION="(TARGET_OS_MACCATALYST || (TARGET_OS_IOS && TARGET_OS_SIMULATOR)) && TARGET_CPU_ARM64"
;;
*_WatchOS_armv7k.h)
DEFINE_CONDITION="TARGET_OS_WATCH && TARGET_OS_EMBEDDED && TARGET_CPU_ARM"
;;
*_WatchOS_arm64_32.h)
DEFINE_CONDITION="TARGET_OS_WATCH && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64"
;;
*_WatchSimulator_x86_64.h)
DEFINE_CONDITION="TARGET_OS_WATCH && TARGET_OS_SIMULATOR && TARGET_CPU_X86_64"
;;
*_WatchSimulator_arm64.h)
DEFINE_CONDITION="TARGET_OS_WATCH && TARGET_OS_SIMULATOR && TARGET_CPU_ARM64"
;;
*_WatchSimulator_i386.h)
DEFINE_CONDITION="TARGET_OS_WATCH && TARGET_OS_SIMULATOR && TARGET_CPU_X86"
;;
*_AppleTVOS_arm64.h)
DEFINE_CONDITION="TARGET_OS_TV && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64"
;;
*_AppleTVSimulator_arm64.h)
DEFINE_CONDITION="TARGET_OS_TV && TARGET_OS_SIMULATOR && TARGET_CPU_ARM64"
;;
*_AppleTVSimulator_x86_64.h)
DEFINE_CONDITION="TARGET_OS_TV && TARGET_OS_SIMULATOR && TARGET_CPU_X86_64"
;;
*_XRSimulator_arm64.h)
DEFINE_CONDITION="TARGET_OS_VISION && TARGET_OS_SIMULATOR && TARGET_CPU_ARM64"
;;
*_XROS_arm64.h)
DEFINE_CONDITION="TARGET_OS_VISION && TARGET_CPU_ARM64"
;;
*)
# Don't run into unexpected cases by setting the default condition to false
DEFINE_CONDITION="0"
;;
esac
}
# Reference: https://github.com/passepartoutvpn/openssl-apple/blob/master/config/20-all-platforms.conf
function generate_apple_envs() {
TARGET=$1
# Extract ARCH from TARGET (part after last dash)
ARCH=$(echo "${TARGET}" | sed -E 's|^.*\-([^\-]+)$|\1|g')
SDK_CFLAGS=
CONFIG_HOST=
# Determine relevant SDK version and platform
if [[ "${TARGET}" == macos* ]]; then
## Apple macOS
if [ ! -n "${MACOS_SDKVERSION}" ]; then
MACOS_SDKVERSION=$(xcrun -sdk macosx --show-sdk-version)
fi
# Truncate to minor version
MINOR_VERSION=(${MACOS_SDKVERSION//./ })
MACOS_SDKVERSION="${MINOR_VERSION[0]}.${MINOR_VERSION[1]}"
SDKVERSION="${MACOS_SDKVERSION}"
PLATFORM="MacOSX"
if [[ "${TARGET}" == "macos64-arm64" ]]; then
CONFIG_HOST="arm-apple-darwin"
else
CONFIG_HOST="x86_64-apple-darwin"
fi
MIN_SDK_VERSION=${MACOS_MIN_SDK_VERSION}
# CFLAGS
SDK_CFLAGS="-mmacosx-version-min=${MACOS_MIN_SDK_VERSION}"
elif [[ "${TARGET}" == mac-catalyst-* ]]; then
# Catalyst
if [ ! -n "${CATALYST_SDKVERSION}" ]; then
CATALYST_SDKVERSION=$(xcrun -sdk macosx --show-sdk-version)
fi
# Truncate to minor version
MINOR_VERSION=(${CATALYST_SDKVERSION//./ })
CATALYST_SDKVERSION="${MINOR_VERSION[0]}.${MINOR_VERSION[1]}"
SDKVERSION="${CATALYST_SDKVERSION}"
PLATFORM="MacOSX"
MIN_SDK_VERSION=${CATALYST_MIN_SDK_VERSION}
# CFLAGS
if [[ "${TARGET}" == "mac-catalyst-x86_64" ]]; then
# Catalyst (x86_64)
SDK_CFLAGS="-target x86_64-apple-ios14.0-macabi -mios-version-min=14.0"
CONFIG_HOST="x86_64-apple-darwin"
else
# Catalyst (arm64)
SDK_CFLAGS="-target arm64-apple-ios14.0-macabi -mios-version-min=14.0"
CONFIG_HOST="arm-apple-darwin"
fi
elif [[ "${TARGET}" == watchos* ]]; then
# watchOS cross
if [ ! -n "${WATCHOS_SDKVERSION}" ]; then
WATCHOS_SDKVERSION=$(xcrun -sdk watchos --show-sdk-version)
fi
SDKVERSION="${WATCHOS_SDKVERSION}"
CONFIG_HOST="arm-apple-darwin"
MIN_SDK_VERSION=${WATCHOS_MIN_SDK_VERSION}
# CFLAGS
SDK_CFLAGS="-mwatchos-version-min=${WATCHOS_MIN_SDK_VERSION}"
if [[ "${TARGET}" == "watchos-sim-cross"* ]]; then
PLATFORM="WatchSimulator"
if [[ "${TARGET}" == "watchos-sim-cross-arm64" ]]; then
SDK_CFLAGS="-target arm64-apple-watchos7.2-simulator -mwatchos-version-min=7.2"
fi
elif [[ "${TARGET}" == "watchos"* ]]; then
PLATFORM="WatchOS"
fi
elif [[ "${TARGET}" == tvos* ]]; then
# tvOS cross
if [ ! -n "${TVOS_SDKVERSION}" ]; then
TVOS_SDKVERSION=$(xcrun -sdk appletvos --show-sdk-version)
fi
SDKVERSION="${TVOS_SDKVERSION}"
CONFIG_HOST="arm-apple-darwin"
MIN_SDK_VERSION=${TVOS_MIN_SDK_VERSION}
# CFLAGS
SDK_CFLAGS="-mtvos-version-min=${TVOS_MIN_SDK_VERSION}"
if [[ "${TARGET}" == "tvos-sim-cross-"* ]]; then
PLATFORM="AppleTVSimulator"
if [[ "${TARGET}" == "tvos-sim-cross-arm64" ]]; then
SDK_CFLAGS+=" -target arm64-apple-tvos12.0-simulator"
fi
elif [[ "${TARGET}" == "tvos-cross-"* ]]; then
PLATFORM="AppleTVOS"
fi
elif [[ "${TARGET}" == xros* ]]; then
# XROS cross
if [ ! -n "${XROS_SDKVERSION}" ]; then
XROS_SDKVERSION=$(xcrun -sdk xros --show-sdk-version)
fi
SDKVERSION="${XROS_SDKVERSION}"
CONFIG_HOST="arm-apple-darwin"
if [[ "${TARGET}" == "xros-sim-cross-"* ]]; then
PLATFORM="XRSimulator"
elif [[ "${TARGET}" == "xros-cross-"* ]]; then
PLATFORM="XROS"
fi
# MIN_SDK_VERSION=${XROS_MIN_SDK_VERSION}
# CFLAGS
# SDK_CFLAGS="-mxros-version-min=${XROS_MIN_SDK_VERSION}"
else
## Apple iOS
if [ ! -n "${IOS_SDKVERSION}" ]; then
IOS_SDKVERSION=$(xcrun -sdk iphoneos --show-sdk-version)
fi
SDKVERSION="${IOS_SDKVERSION}"
CONFIG_HOST="arm-apple-darwin"
if [[ "${TARGET}" == "ios-sim-cross-"* ]]; then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
fi
MIN_SDK_VERSION=${IOS_MIN_SDK_VERSION}
# CFLAGS
SDK_CFLAGS="-mios-version-min=${IOS_MIN_SDK_VERSION}"
# Simulator (arm64)
if [[ "${TARGET}" == "ios-sim-cross-arm64" ]]; then
SDK_CFLAGS+=" -target arm64-apple-ios14.0-simulator -mios-version-min=14.0"
fi
fi
# Cross compile references, see Configurations/10-main.conf
local CROSS_COMPILE="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
local CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
local CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
# Prepare TARGETDIR and SOURCEDIR
PLATFORM="${PLATFORM}"
if [[ "${TARGET}" == "mac-catalyst-"* ]]; then
PLATFORM="Catalyst"
fi
SDK_CFLAGS="-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -fno-common -arch ${ARCH} ${SDK_CFLAGS}"
}
# Validate Xcode Developer path
DEVELOPER=$(xcode-select -print-path)
if [ ! -d "${DEVELOPER}" ]; then
echo "Xcode path is not set correctly ${DEVELOPER} does not exist"
echo "run"
echo "sudo xcode-select -switch <Xcode path>"
echo "for default installation:"
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
exit 1
fi
case "${DEVELOPER}" in
*\ * )
echo "Your Xcode path contains whitespaces, which is not supported."
exit 1
;;
esac
# Init optional command line vars
ARCHS=""
CLEANUP=""
IOS_SDKVERSION=""
MACOS_SDKVERSION=""
CATALYST_SDKVERSION=""
WATCHOS_SDKVERSION=""
TVOS_SDKVERSION=""
XROS_SDKVERSION=""
LOG_VERBOSE=""
TARGETS=""
# Process command line arguments
for i in "$@"
do
case $i in
--cleanup)
cleanup_build
exit
;;
-h|--help)
echo_help
exit
;;
--ios-sdk=*)
IOS_SDKVERSION="${i#*=}"
shift
;;
--macos-sdk=*)
MACOS_SDKVERSION="${i#*=}"
shift
;;
--catalyst-sdk=*)
CATALYST_SDKVERSION="${i#*=}"
shift
;;
--watchos-sdk=*)
WATCHOS_SDKVERSION="${i#*=}"
shift
;;
--tvos-sdk=*)
TVOS_SDKVERSION="${i#*=}"
shift
;;
--min-ios-sdk=*)
IOS_MIN_SDK_VERSION="${i#*=}"
shift
;;
--min-macos-sdk=*)
MACOS_MIN_SDK_VERSION="${i#*=}"
shift
;;
--min-watchos-sdk=*)
WATCHOS_MIN_SDK_VERSION="${i#*=}"
shift
;;
--min-tvos-sdk=*)
TVOS_MIN_SDK_VERSION="${i#*=}"
shift
;;
--min-xros-sdk=*)
XROS_MIN_SDK_VERSION="${i#*=}"
shift
;;
--targets=*)
TARGETS="${i#*=}"
shift
;;
-v|--verbose)
LOG_VERBOSE="verbose"
;;
--verbose-on-error)
LOG_VERBOSE="verbose-on-error"
;;
*)
extra_argument ${i}
;;
esac
done
did_process_arguments
bootstrap() {
for TARGET in ${TARGETS}
do
echo ${TARGET}:
echo -------------------------
generate_apple_envs "${TARGET}"
echo SDK_CFLAGS: ${SDK_CFLAGS}
echo -------------------------
prepare_target_source_dirs
# Run Configure
run_configure
# Run make
run_make
# Run make install
run_make_install
# Remove source dir, add references to library files to relevant arrays
# Keep reference to first build target for include file
finish_build_loop
done
}
# Set default for TARGETS if not specified
if [ ! -n "${TARGETS}" ]; then
TARGETS="${DEFAULTTARGETS}"
fi
if [ "$0" = "$BASH_SOURCE" ]; then
## Run standalone
echo ------------------------- CFLAGS -------------------------
for TARGET in ${TARGETS}
do
echo ${TARGET}:
echo -------------------------
generate_apple_envs "${TARGET}"
echo ${SDK_CFLAGS}
echo
done
fi