forked from faithfracture/Apple-Boost-BuildScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boost.sh
executable file
·1271 lines (1072 loc) · 40.2 KB
/
boost.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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#===============================================================================
# Filename: boost.sh
# Author: Pete Goodliffe
# Copyright: (c) Copyright 2009 Pete Goodliffe
# Licence: Please feel free to use this, with attribution
# Modified version
#===============================================================================
#
# Builds a Boost framework for iOS, iOS Simulator, tvOS, tvOS Simulator, and macOS.
# Creates a set of universal libraries that can be used on an iOS and in the
# iOS simulator. Then creates a pseudo-framework to make using boost in Xcode
# less painful.
#
# To configure the script, define:
# BOOST_VERSION: Which version of Boost to build (e.g. 1.69.0)
# BOOST_LIBS: Which Boost libraries to build
# IOS_SDK_VERSION: iOS SDK version (e.g. 12.0)
# MIN_IOS_VERSION: Minimum iOS Target Version (e.g. 11.0)
# TVOS_SDK_VERSION: iOS SDK version (e.g. 12.0)
# MIN_TVOS_VERSION: Minimum iOS Target Version (e.g. 11.0)
# MACOS_SDK_VERSION: macOS SDK version (e.g. 10.14)
# MIN_MACOS_VERSION: Minimum macOS Target Version (e.g. 10.12)
#
# If a boost tarball (a file named “boost_$BOOST_VERSION2.tar.bz2”) does not
# exist in the current directory, this script will attempt to download the
# version specified. You may also manually place a matching
# tarball in the current directory and the script will use that.
#
#===============================================================================
BOOST_VERSION=1.72.0
BOOST_LIBS="atomic chrono date_time exception filesystem program_options random system thread test"
ALL_BOOST_LIBS_1_68="atomic chrono container context coroutine coroutine2
date_time exception fiber filesystem graph graph_parallel iostreams locale log
math metaparse mpi program_options python random regex serialization signals
system test thread timer type_erasure wave"
ALL_BOOST_LIBS_1_69="atomic chrono container context coroutine coroutine2
date_time exception fiber filesystem graph graph_parallel iostreams locale log
math metaparse mpi program_options python random regex serialization signals2
system test thread timer type_erasure wave"
BOOTSTRAP_LIBS=""
MIN_IOS_VERSION=11.0
MIN_TVOS_VERSION=11.0
TVOS_SDK_PATH=$(xcrun --sdk appletvos --show-sdk-path)
TVOSSIM_SDK_PATH=$(xcrun --sdk appletvsimulator --show-sdk-path)
MIN_MACOS_VERSION=10.12
MACOS_SDK_PATH=$(xcrun --sdk macosx --show-sdk-path)
MACOS_ARCHS=("x86_64")
IOS_ARCHS=("armv7" "arm64")
IOS_SIM_ARCHS=("i386" "x86_64")
# Applied to all platforms
CXX_FLAGS="-std=c++14 -stdlib=libc++"
XCODE_VERSION=$(xcrun xcodebuild -version | head -n1 | tr -Cd '[:digit:].')
XCODE_ROOT=$(xcode-select -print-path)
COMPILER="$XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
THREADS="-j$(sysctl -n hw.ncpu)"
CURRENT_DIR=$(pwd)
SRCDIR="$CURRENT_DIR/src"
IOS_ARM_DEV_CMD="xcrun --sdk iphoneos"
IOS_SIM_DEV_CMD="xcrun --sdk iphonesimulator"
TVOS_ARM_DEV_CMD="xcrun --sdk appletvos"
TVOS_SIM_DEV_CMD="xcrun --sdk appletvsimulator"
MACOS_DEV_CMD="xcrun --sdk macosx"
BUILD_VARIANT=release
#===============================================================================
# Functions
#===============================================================================
sdkVersion()
{
FULL_VERSION=$(xcrun --sdk "$1" --show-sdk-version)
read -ra VERSION <<< "${FULL_VERSION//./ }"
echo "${VERSION[0]}.${VERSION[1]}"
}
IOS_SDK_VERSION=$(sdkVersion iphoneos)
TVOS_SDK_VERSION=$(sdkVersion appletvos)
MACOS_SDK_VERSION=$(sdkVersion macosx)
usage()
{
cat << EOF
usage: $0 [{-ios,-tvos,-macos} ...] options
Build Boost for iOS, iOS Simulator, tvOS, tvOS Simulator, and macOS
The -ios, -tvos, and -macOS options may be specified together. Default
is to build all of them.
Examples:
./boost.sh -ios -tvos --boost-version 1.68.0
./boost.sh -macos --no-framework
./boost.sh --clean
OPTIONS:
-h | --help
Display these options and exit.
-ios
Build for the iOS platform.
-macos
Build for the macOS platform.
-tvos
Build for the tvOS platform.
--boost-version [num]
Specify which version of Boost to build.
Defaults to $BOOST_VERSION.
--boost-libs "{all|none|(lib, ...)}"
Specify which libraries to build. Space-separate list. Pass 'all' to
build all optional libraries. Pass 'none' to skip building optional
libraries.
Defaults to: $BOOST_LIBS
Boost libraries requiring separate building are:
- atomic
- chrono
- container (Unavailable on tvOS)
- context (macOS only)
- coroutine (macOS only)
- coroutine2 (macOS only)
- date_time
- exception
- fiber (No complaints when building for iOS / tvOS, but no library is output)
- filesystem
- graph
- graph_parallel (No complaints when building for iOS / tvOS, but no library is output)
- iostreams
- locale
- log
- math (Unavailable* on iOS, tvOS)
- metaparse (Unavailable on tvOS)
- mpi (macOS only. Requires mpic++ (openmpi))
- program_options
- python
- random
- regex
- serialization
- signals
- system
- test (Unavailable on tvOS)
- thread
- timer
- type_erasure
- wave
NOTE:
Unsupported and unavailable libraries are ignored when building for the
platforms they are unsupported on. It's OK to pass them as arguments,
just be aware that they will not be built for those platforms.
Several libraries are unavailable on tvOS only because they make calls
that are not available in tvOS.
There are a couple of libraries that *appear* to build successfully for
iOS and / or tvOS, but there is no library output, so I don't know that
they are actually built for those platforms. I don't use them so I can't
say for certain. If you find out one way or the other, please let me
know so I can update this.
* math fails for iOS and tvOS with a complaint about using a PCH with
multiple architectures defined. I don't know how to get around this if
you need a specific architecture (like arm64), since the only RISC
option for the <architeciture> jamfile feature tag is 'arm'. I'm sure
there's a way to get this working by tweaking user-config, but I haven't
the time to figure it out now.
--ios-sdk [num]
Specify the iOS SDK version to build with.
Defaults to $IOS_SDK_VERSION
--min-ios-version [num]
Specify the minimum iOS version to target. Since iOS 11+ are 64-bit only,
if the minimum iOS version is set to iOS 11.0 or later, iOS archs is
automatically set to 'arm64' and iOS Simulator archs is set to "x86_64",
unless '--ios-archs' is also specified.
Defaults to $MIN_IOS_VERSION
--ios-archs "(archs, ...)"
Specify the iOS architectures to build for. Also updates the iOS Simulator
architectures to match. Space-separate list.
--tvos-sdk [num]
Specify the tvOS SDK version to build with.
Defaults to $TVOS_SDK_VERSION
--min-tvos_version [num]
Specify the minimum tvOS version to target.
Defaults to $MIN_TVOS_VERSION
--macos-sdk [num]
Specify the macOS SDK version to build with.
Defaults to $MACOS_SDK_VERSION
--min-macos-version [num]
Specify the minimum macOS version to target.
Defaults to $MIN_MACOS_VERSION
--macos-archs "(archs, ...)"
Specify the macOS architectures to build for. Space-separate list.
Defaults to ${MACOS_ARCHS[*]}
--hidden-visibility
Compile using -fvisibility=hidden and -fvisibility-inlines-hidden
--no-framework
Do not create the framework.
--universal
Create universal FAT binary.
--framework-header-root
Place headers in a 'boost' root directory in the framework rather than
directly in the 'Headers' directory.
Added for compatibility with projects that expect this structure.
--debug
Build a debug variant.
--clean
Just clean up build artifacts, but don't actually build anything.
(all other parameters are ignored)
--purge
Removes everything (build directory, src, Boost tarball, etc.).
Similar to --clean, but more thorough.
--no-clean
Do not clean up existing build artifacts before building.
-j | --threads [num]
Specify the number of threads to use.
Defaults to $THREADS
EOF
}
abort()
{
echo
echo "Aborted:" "$@"
exit 1
}
die()
{
usage
exit 1
}
cd_or_abort()
{
cd "$1" || abort "Could not change directory into \"$1\""
}
missingParameter()
{
echo "$1 requires a parameter"
die
}
unknownParameter()
{
if [[ -n $2 && $2 != "" ]]; then
echo "Unknown argument \"$2\" for parameter $1."
else
echo "Unknown argument $1"
fi
die
}
parseArgs()
{
while [ "$1" != "" ]; do
case $1 in
-h | --help)
usage
exit
;;
-ios)
BUILD_IOS=1
;;
-tvos)
BUILD_TVOS=1
;;
-macos)
BUILD_MACOS=1
;;
--boost-version)
if [ -n "$2" ]; then
BOOST_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--boost-libs)
if [ -n "$2" ]; then
CUSTOM_LIBS=$2
shift
else
missingParameter "$1"
fi
;;
--ios-sdk)
if [ -n "$2" ]; then
IOS_SDK_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--min-ios-version)
if [ -n "$2" ]; then
MIN_IOS_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--ios-archs)
if [ -n "$2" ]; then
CUSTOM_IOS_ARCHS=$2
shift;
else
missingParameter "$1"
fi
;;
--tvos-sdk)
if [ -n "$2" ]; then
TVOS_SDK_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--min-tvos-version)
if [ -n "$2" ]; then
MIN_TVOS_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--macos-sdk)
if [ -n "$2" ]; then
MACOS_SDK_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--min-macos-version)
if [ -n "$2" ]; then
MIN_MACOS_VERSION=$2
shift
else
missingParameter "$1"
fi
;;
--macos-archs)
if [ -n "$2" ]; then
CUSTOM_MACOS_ARCHS=$2
shift;
else
missingParameter "$1"
fi
;;
--hidden-visibility)
CXX_FLAGS="$CXX_FLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
;;
--universal)
UNIVERSAL=1
;;
--debug)
BUILD_VARIANT=debug
;;
--clean)
CLEAN=1
;;
--purge)
PURGE=1
;;
--no-clean)
NO_CLEAN=1
;;
--no-framework)
NO_FRAMEWORK=1
;;
--framework-header-root)
HEADER_ROOT=1
;;
-j | --threads)
if [ -n "$2" ]; then
THREADS="-j$2"
shift
else
missingParameter "$1"
fi
;;
*)
unknownParameter "$1"
;;
esac
shift
done
if [[ -n $CUSTOM_LIBS ]]; then
if [[ "$CUSTOM_LIBS" == "none" ]]; then
CUSTOM_LIBS=""
elif [[ "$CUSTOM_LIBS" == "all" ]]; then
read -ra BOOST_PARTS <<< "${BOOST_VERSION//./ }"
if [[ ${BOOST_PARTS[1]} -lt 69 ]]; then
CUSTOM_LIBS=$ALL_BOOST_LIBS_1_68
else
CUSTOM_LIBS=$ALL_BOOST_LIBS_1_69
fi
fi
BOOST_LIBS=$CUSTOM_LIBS
fi
# Force 32/64-bit architecture when building universal macOS.
# Forcing i386 & x86_64 is fine for now, but if macOS ever supports
# other architectures in the future we'll need to be a bit smarter
# about this.
if [[ -n $BUILD_MACOS && -n $UNIVERSAL ]]; then
CUSTOM_MACOS_ARCHS=("i386" "x86_64")
fi
if [[ "${#CUSTOM_MACOS_ARCHS[@]}" -gt 0 ]]; then
read -ra MACOS_ARCHS <<< "${CUSTOM_MACOS_ARCHS[@]}"
fi
if [[ "${#CUSTOM_IOS_ARCHS[@]}" -gt 0 ]]; then
read -ra IOS_ARCHS <<< "${CUSTOM_IOS_ARCHS[@]}"
IOS_SIM_ARCHS=()
# As of right now this matches the currently available ARM architectures
# Add 32-bit simulator for 32-bit arm
if [[ "${IOS_ARCHS[*]}" =~ armv ]]; then
IOS_SIM_ARCHS+=("i386")
fi
# Add 64-bit simulator for 64-bit arm
if [[ "${IOS_ARCHS[*]}" =~ arm64 ]]; then
IOS_SIM_ARCHS+=("x86_64")
fi
else
read -ra MIN_IOS_PARTS <<< "${MIN_IOS_VERSION//./ }"
if [[ ${MIN_IOS_PARTS[0]} -ge 11 ]]; then
# iOS 11 dropped support for 32bit devices
IOS_ARCHS=("arm64")
IOS_SIM_ARCHS=("x86_64")
fi
fi
}
doneSection()
{
echo
echo "Done"
echo "================================================================="
echo
}
#===============================================================================
cleanup()
{
echo Cleaning everything
if [[ -n $BUILD_IOS ]]; then
rm -r "$BOOST_SRC/iphone-build"
rm -r "$BOOST_SRC/iphonesim-build"
rm -r "$IOS_OUTPUT_DIR"
fi
if [[ -n $BUILD_TVOS ]]; then
rm -r "$BOOST_SRC/appletv-build"
rm -r "$BOOST_SRC/appletvsim-build"
rm -r "$TVOS_OUTPUT_DIR"
fi
if [[ -n $BUILD_MACOS ]]; then
rm -r "$BOOST_SRC/macos-build"
rm -r "$MACOS_OUTPUT_DIR"
fi
doneSection
}
#===============================================================================
# version() from https://stackoverflow.com/a/37939589/3938401
version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
downloadBoost()
{
if [ "$(version "$BOOST_VERSION")" -ge "$(version "1.63.0")" ]; then
DOWNLOAD_SRC=https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION2}.tar.bz2
else
DOWNLOAD_SRC=http://sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/boost_${BOOST_VERSION2}.tar.bz2/download
fi
if [ ! -s "$BOOST_TARBALL" ]; then
echo "Downloading boost ${BOOST_VERSION} from ${DOWNLOAD_SRC}"
curl -L -o "$BOOST_TARBALL" "$DOWNLOAD_SRC"
doneSection
fi
}
#===============================================================================
unpackBoost()
{
[ -f "$BOOST_TARBALL" ] || abort "Source tarball missing."
echo Unpacking boost into "$SRCDIR"...
[ -d "$SRCDIR" ] || mkdir -p "$SRCDIR"
[ -d "$BOOST_SRC" ] || ( cd_or_abort "$SRCDIR"; tar xjf "$BOOST_TARBALL" )
[ -d "$BOOST_SRC" ] && echo " ...unpacked as $BOOST_SRC"
doneSection
}
#===============================================================================
patchBoost()
{
echo "Patching boost in $BOOST_SRC"
if [ "$(version "$BOOST_VERSION")" -le "$(version "1.72.0")" ] &&
[ "$(version "$XCODE_VERSION")" -ge "$(version "11.4")" ]
then
# https://github.com/boostorg/build/pull/560
(cd "$BOOST_SRC" && patch --forward -p1 -d "$BOOST_SRC/tools/build" < "$CURRENT_DIR/patches/xcode-11.4.patch")
fi
doneSection
}
#===============================================================================
inventMissingHeaders()
{
# These files are missing in the ARM iPhoneOS SDK, but they are in the simulator.
# They are supported on the device, so we copy them from x86 SDK to a staging area
# to use them on ARM, too.
echo Invent missing headers
cp "$XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IOS_SDK_VERSION}.sdk/usr/include/"{crt_externs,bzlib}.h "$BOOST_SRC"
}
#===============================================================================
updateBoost()
{
echo "Updating boost into $BOOST_SRC..."
USING_MPI=
if [[ $BOOST_LIBS == *"mpi"* ]]; then
USING_MPI="using mpi ;" # trailing space needed
fi
if [[ "$1" == "iOS" ]]; then
cat > "$BOOST_SRC/tools/build/src/user-config.jam" <<EOF
using darwin : ${IOS_SDK_VERSION}~iphone
: $COMPILER ${IOS_ARCH_FLAGS[*]} $EXTRA_IOS_FLAGS
: <striper> <root>$XCODE_ROOT/Platforms/iPhoneOS.platform/Developer
: <architecture>arm <target-os>iphone
;
using darwin : ${IOS_SDK_VERSION}~iphonesim
: $COMPILER ${IOS_SIM_ARCH_FLAGS[*]} $EXTRA_IOS_SIM_FLAGS
: <striper> <root>$XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer
: <architecture>x86 <target-os>iphone
;
$USING_MPI
EOF
fi
if [[ "$1" == "tvOS" ]]; then
cat > "$BOOST_SRC/tools/build/src/user-config.jam" <<EOF
using darwin : ${TVOS_SDK_VERSION}~appletv
: $COMPILER -arch arm64 $EXTRA_TVOS_FLAGS -isysroot $TVOS_SDK_PATH -I $TVOS_SDK_PATH
: <striper> <root>$XCODE_ROOT/Platforms/AppleTVOS.platform/Developer
: <architecture>arm <target-os>iphone
;
using darwin : ${TVOS_SDK_VERSION}~appletvsim
: $COMPILER -arch x86_64 $EXTRA_TVOS_SIM_FLAGS -isysroot $TVOSSIM_SDK_PATH -I $TVOSSIM_SDK_PATH
: <striper> <root>$XCODE_ROOT/Platforms/AppleTVSimulator.platform/Developer
: <architecture>x86 <target-os>iphone
;
$USING_MPI
EOF
fi
if [[ "$1" == "macOS" ]]; then
cat > "$BOOST_SRC/tools/build/src/user-config.jam" <<EOF
using darwin : ${MACOS_SDK_VERSION}
: $COMPILER ${MACOS_ARCH_FLAGS[*]} $EXTRA_MACOS_FLAGS -isysroot $MACOS_SDK_PATH
: <striper> <root>$XCODE_ROOT/Platforms/MacOSX.platform/Developer
: <architecture>x86 <target-os>darwin
;
$USING_MPI
EOF
fi
doneSection
}
#===============================================================================
bootstrapBoost()
{
cd_or_abort "$BOOST_SRC"
if [[ -z $BOOST_LIBS ]]; then
./bootstrap.sh --without-libraries="${ALL_BOOST_LIBS// /,}"
else
BOOTSTRAP_LIBS=$BOOST_LIBS
# Strip out unsupported / unavailable libraries
if [[ "$1" == "iOS" ]]; then
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//context/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//coroutine/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//coroutine2/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//math/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//mpi/}"
fi
if [[ "$1" == "tvOS" ]]; then
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//container/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//context/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//coroutine/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//coroutine2/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//math/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//metaparse/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//mpi/}"
BOOTSTRAP_LIBS="${BOOTSTRAP_LIBS//test/}"
fi
echo "Bootstrap libs ${BOOTSTRAP_LIBS}"
BOOST_LIBS_COMMA="${BOOTSTRAP_LIBS// /,}"
echo "Bootstrapping for $1 (with libs $BOOST_LIBS_COMMA)"
./bootstrap.sh --with-libraries="$BOOST_LIBS_COMMA"
fi
doneSection
}
#===============================================================================
buildBoost_iOS()
{
cd_or_abort "$BOOST_SRC"
mkdir -p "$IOS_OUTPUT_DIR"
echo Building Boost for iPhone
# Install this one so we can copy the headers for the frameworks...
./b2 "$THREADS" --build-dir=iphone-build --stagedir=iphone-build/stage \
--prefix="$IOS_OUTPUT_DIR/prefix" toolset=darwin \
cxxflags="${CXX_FLAGS} ${IOS_ARCH_FLAGS[*]}" architecture=arm target-os=iphone linkflags="-stdlib=libc++" \
macosx-version="iphone-$IOS_SDK_VERSION" define=_LITTLE_ENDIAN \
link=static variant=${BUILD_VARIANT} stage >> "${IOS_OUTPUT_DIR}/ios-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error staging iPhone. Check log."; exit 1; fi
./b2 "$THREADS" --build-dir=iphone-build --stagedir=iphone-build/stage \
--prefix="$IOS_OUTPUT_DIR/prefix" toolset=darwin \
cxxflags="${CXX_FLAGS} ${IOS_ARCH_FLAGS[*]}" architecture=arm linkflags="-stdlib=libc++" \
target-os=iphone macosx-version="iphone-$IOS_SDK_VERSION" \
define=_LITTLE_ENDIAN link=static variant=${BUILD_VARIANT} install >> "${IOS_OUTPUT_DIR}/ios-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error installing iPhone. Check log."; exit 1; fi
doneSection
echo Building Boost for iPhoneSimulator
./b2 "$THREADS" --build-dir=iphonesim-build --stagedir=iphonesim-build/stage \
toolset="darwin-{IOS_SDK_VERSION}~iphonesim" \
cxxflags="${CXX_FLAGS} ${IOS_SIM_ARCH_FLAGS[*]}" architecture=x86 linkflags="-stdlib=libc++" \
target-os=iphone macosx-version="iphonesim-$IOS_SDK_VERSION" \
link=static variant=${BUILD_VARIANT} stage >> "${IOS_OUTPUT_DIR}/ios-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error staging iPhoneSimulator. Check log."; exit 1; fi
doneSection
}
buildBoost_tvOS()
{
cd_or_abort "$BOOST_SRC"
mkdir -p "$TVOS_OUTPUT_DIR"
echo Building Boost for AppleTV
./b2 "$THREADS" --build-dir=appletv-build --stagedir=appletv-build/stage \
--prefix="$TVOS_OUTPUT_DIR/prefix" toolset="darwin-$TVOS_SDK_VERSION~appletv" \
cxxflags="${CXX_FLAGS}" architecture=arm target-os=iphone define=_LITTLE_ENDIAN linkflags="-stdlib=libc++" \
link=static variant=${BUILD_VARIANT} stage >> "${TVOS_OUTPUT_DIR}/tvos-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error staging AppleTV. Check log."; exit 1; fi
./b2 "$THREADS" --build-dir=appletv-build --stagedir=appletv-build/stage \
--prefix="$TVOS_OUTPUT_DIR/prefix" toolset="darwin-$TVOS_SDK_VERSION~appletv" \
cxxflags="${CXX_FLAGS}" architecture=arm target-os=iphone define=_LITTLE_ENDIAN linkflags="-stdlib=libc++" \
link=static variant=${BUILD_VARIANT} install >> "${TVOS_OUTPUT_DIR}/tvos-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error installing AppleTV. Check log."; exit 1; fi
doneSection
echo Building Boost for AppleTVSimulator
./b2 "$THREADS" --build-dir=appletv-build --stagedir=appletvsim-build/stage \
toolset="darwin-$TVOS_SDK_VERSION~appletvsim" architecture=x86 \
cxxflags="${CXX_FLAGS}" target-os=iphone link=static variant=${BUILD_VARIANT} linkflags="-stdlib=libc++" \
stage >> "${TVOS_OUTPUT_DIR}/tvos-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error staging AppleTVSimulator. Check log."; exit 1; fi
doneSection
}
buildBoost_macOS()
{
cd_or_abort "$BOOST_SRC"
mkdir -p "$MACOS_OUTPUT_DIR"
echo building Boost for macOS
./b2 "$THREADS" --build-dir=macos-build --stagedir=macos-build/stage --prefix="$MACOS_OUTPUT_DIR/prefix" \
toolset="darwin-$MACOS_SDK_VERSION" architecture=x86 \
cxxflags="${CXX_FLAGS} ${MACOS_ARCH_FLAGS[*]} ${EXTRA_MACOS_SDK_FLAGS}" \
linkflags="-stdlib=libc++ ${EXTRA_MACOS_SDK_FLAGS}" link=static variant=${BUILD_VARIANT} threading=multi \
macosx-version="${MACOS_SDK_VERSION}" stage >> "${MACOS_OUTPUT_DIR}/macos-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error staging macOS. Check log."; exit 1; fi
./b2 "$THREADS" --build-dir=macos-build --stagedir=macos-build/stage --prefix="$MACOS_OUTPUT_DIR/prefix" \
toolset="darwin-$MACOS_SDK_VERSION" architecture=x86 \
cxxflags="${CXX_FLAGS} ${MACOS_ARCH_FLAGS[*]} ${EXTRA_MACOS_SDK_FLAGS}" \
linkflags="-stdlib=libc++ ${EXTRA_MACOS_SDK_FLAGS}" link=static variant=${BUILD_VARIANT} threading=multi \
macosx-version="$MACOS_SDK_VERSION" install >> "${MACOS_OUTPUT_DIR}/macos-build.log" 2>&1
# shellcheck disable=SC2181
if [ $? != 0 ]; then echo "Error installing macOS. Check log."; exit 1; fi
doneSection
}
#===============================================================================
unpackArchive()
{
BUILDDIR="$1"
LIBNAME="$2"
echo "Unpacking $BUILDDIR/$LIBNAME"
if [[ -d "$BUILDDIR/$LIBNAME" ]]; then
cd_or_abort "$BUILDDIR/$LIBNAME"
rm ./*.o
rm ./*.SYMDEF*
else
mkdir -p "$BUILDDIR/$LIBNAME"
fi
(
cd_or_abort "$BUILDDIR/$NAME"; ar -x "../../libboost_$NAME.a";
for FILE in *.o; do
NEW_FILE="${NAME}_${FILE}"
mv "$FILE" "$NEW_FILE"
done
)
}
scrunchAllLibsTogetherInOneLibPerPlatform()
{
cd_or_abort "$BOOST_SRC"
if [[ -n $BUILD_IOS ]]; then
# iOS Device
for ARCH in "${IOS_ARCHS[@]}"; do
mkdir -p "$IOS_BUILD_DIR/$ARCH/obj"
done
# iOS Simulator
for ARCH in "${IOS_SIM_ARCHS[@]}"; do
mkdir -p "$IOS_BUILD_DIR/$ARCH/obj"
done
fi
if [[ -n $BUILD_TVOS ]]; then
# tvOS Device
mkdir -p "$TVOS_BUILD_DIR/arm64/obj"
# tvOS Simulator
mkdir -p "$TVOS_BUILD_DIR/x86_64/obj"
fi
if [[ -n $BUILD_MACOS ]]; then
# macOS
for ARCH in "${MACOS_ARCHS[@]}"; do
mkdir -p "$MACOS_BUILD_DIR/$ARCH/obj"
done
fi
ALL_LIBS=""
echo Splitting all existing fat binaries...
for NAME in $BOOTSTRAP_LIBS; do
if [ "$NAME" == "test" ]; then
NAME="unit_test_framework"
fi
ALL_LIBS="$ALL_LIBS libboost_$NAME.a"
if [[ -n $BUILD_IOS ]]; then
if [[ "${#IOS_ARCHS[@]}" -gt 1 ]]; then
for ARCH in "${IOS_ARCHS[@]}"; do
$IOS_ARM_DEV_CMD lipo "iphone-build/stage/lib/libboost_$NAME.a" \
-thin "$ARCH" -o "$IOS_BUILD_DIR/$ARCH/libboost_$NAME.a"
done
else
cp "iphone-build/stage/lib/libboost_$NAME.a" \
"$IOS_BUILD_DIR/${IOS_ARCHS[0]}/libboost_$NAME.a"
fi
if [[ "${#IOS_SIM_ARCHS[@]}" -gt 1 ]]; then
for ARCH in "${IOS_SIM_ARCHS[@]}"; do
$IOS_SIM_DEV_CMD lipo "iphonesim-build/stage/lib/libboost_$NAME.a" \
-thin "$ARCH" -o "$IOS_BUILD_DIR/$ARCH/libboost_$NAME.a"
done
else
cp "iphonesim-build/stage/lib/libboost_$NAME.a" \
"$IOS_BUILD_DIR/${IOS_SIM_ARCHS[0]}/libboost_$NAME.a"
fi
fi
if [[ -n $BUILD_TVOS ]]; then
cp "appletv-build/stage/lib/libboost_$NAME.a" \
"$TVOS_BUILD_DIR/arm64/libboost_$NAME.a"
cp "appletvsim-build/stage/lib/libboost_$NAME.a" \
"$TVOS_BUILD_DIR/x86_64/libboost_$NAME.a"
fi
if [[ -n $BUILD_MACOS ]]; then
if [[ "${#MACOS_ARCHS[@]}" -gt 1 ]]; then
for ARCH in "${MACOS_ARCHS[@]}"; do
$MACOS_DEV_CMD lipo "macos-build/stage/lib/libboost_$NAME.a" \
-thin "$ARCH" -o "$MACOS_BUILD_DIR/$ARCH/libboost_$NAME.a"
done
else
cp "macos-build/stage/lib/libboost_$NAME.a" \
"$MACOS_BUILD_DIR/$ARCH/libboost_$NAME.a"
fi
fi
done
echo "Decomposing each architecture's .a files"
for NAME in $BOOTSTRAP_LIBS; do
if [ "$NAME" == "test" ]; then
NAME="unit_test_framework"
fi
echo "Decomposing libboost_${NAME}.a"
if [[ -n $BUILD_IOS ]]; then
for ARCH in "${IOS_ARCHS[@]}"; do
unpackArchive "$IOS_BUILD_DIR/$ARCH/obj" $NAME
done
for ARCH in "${IOS_SIM_ARCHS[@]}"; do
unpackArchive "$IOS_BUILD_DIR/$ARCH/obj" $NAME
done
fi
if [[ -n $BUILD_TVOS ]]; then
unpackArchive "$TVOS_BUILD_DIR/arm64/obj" $NAME
unpackArchive "$TVOS_BUILD_DIR/x86_64/obj" $NAME
fi
if [[ -n $BUILD_MACOS ]]; then
for ARCH in "${MACOS_ARCHS[@]}"; do
unpackArchive "$MACOS_BUILD_DIR/$ARCH/obj" $NAME
done
fi
done
echo "Linking each architecture into an uberlib ($ALL_LIBS => libboost.a )"
if [[ -n $BUILD_IOS ]]; then
for ARCH in "${IOS_ARCHS[@]}"; do
rm "$IOS_BUILD_DIR/$ARCH/libboost.a"
done
fi
if [[ -n $BUILD_TVOS ]]; then
rm "$TVOS_BUILD_DIR"/*/libboost.a
fi
if [[ -n $BUILD_MACOS ]]; then
for ARCH in "${MACOS_ARCHS[@]}"; do
rm "$MACOS_BUILD_DIR/$ARCH/libboost.a"
done
fi
for NAME in $BOOTSTRAP_LIBS; do
if [ "$NAME" == "test" ]; then
NAME="unit_test_framework"
fi
echo "Archiving $NAME"
# The obj/$NAME/*.o below should all be quoted, but I couldn't figure out how to do that elegantly.
# Boost lib names probably won't contain non-word characters any time soon, though. ;) - Jan
if [[ -n $BUILD_IOS ]]; then
for ARCH in "${IOS_ARCHS[@]}"; do
echo "...ios-$ARCH"
(cd_or_abort "$IOS_BUILD_DIR/$ARCH"; $IOS_ARM_DEV_CMD ar crus libboost.a "obj/$NAME/"*.o; )
done
for ARCH in "${IOS_SIM_ARCHS[@]}"; do
echo "...ios-sim-$ARCH"
(cd_or_abort "$IOS_BUILD_DIR/$ARCH"; $IOS_SIM_ARM_DEV_CMD ar crus libboost.a "obj/$NAME/"*.o; )
done
fi
if [[ -n $BUILD_TVOS ]]; then
echo "...tvOS-arm64"
(cd_or_abort "$TVOS_BUILD_DIR/arm64"; $TVOS_ARM_DEV_CMD ar crus libboost.a "obj/$NAME/"*.o; )
echo "...tvOS-x86_64"
(cd_or_abort "$TVOS_BUILD_DIR/x86_64"; $TVOS_SIM_DEV_CMD ar crus libboost.a "obj/$NAME/"*.o; )
fi
if [[ -n $BUILD_MACOS ]]; then
for ARCH in "${MACOS_ARCHS[@]}"; do
echo "...macos-$ARCH"
(cd_or_abort "$MACOS_BUILD_DIR/$ARCH"; $MACOS_DEV_CMD ar crus libboost.a "obj/$NAME/"*.o; )
done
fi
done
}
buildUniversal()
{
echo "Creating universal library..."
if [[ -n $BUILD_IOS ]]; then
mkdir -p "$IOS_BUILD_DIR/universal"
cd_or_abort "$IOS_BUILD_DIR"
for NAME in $BOOTSTRAP_LIBS; do
if [ "$NAME" == "test" ]; then
NAME="unit_test_framework"
fi
ARCH_FILES=()
for ARCH in "${IOS_ARCHS[@]}"; do
ARCH_FILES+=("$ARCH/libboost_$NAME.a")
done
for ARCH in "${IOS_SIM_ARCHS[@]}"; do
ARCH_FILES+=("$ARCH/libboost_$NAME.a")
done
if [[ "${#ARCH_FILES[@]}" -gt 0 ]]; then
echo "... $NAME"
$IOS_ARM_DEV_CMD lipo -create "${ARCH_FILES[@]}" -o "universal/libboost_$NAME.a" || abort "Lipo $NAME failed"
fi
done
fi
if [[ -n $BUILD_TVOS ]]; then
mkdir -p "$TVOS_BUILD_DIR/universal"
cd_or_abort "$TVOS_BUILD_DIR"
for NAME in $BOOTSTRAP_LIBS; do
if [ "$NAME" == "test" ]; then
NAME="unit_test_framework"