Ticket #10742: build.sh

File build.sh, 14.0 KB (added by anonymous, 8 years ago)
Line 
1#===============================================================================
2# Filename: boost.sh
3# Author: Pete Goodliffe, Daniel Rosser
4# Copyright: (c) Copyright 2009 Pete Goodliffe, 2013 Daniel Rosser
5# Licence: Please feel free to use this, with attribution
6# Modified version ## for ofxiOSBoost
7#===============================================================================
8#
9# Builds a Boost framework for the iPhone.
10# Creates a set of universal libraries that can be used on an iPhone and in the
11# iPhone simulator. Then creates a pseudo-framework to make using boost in Xcode
12# less painful.
13#
14# To configure the script, define:
15# BOOST_LIBS: which libraries to build
16# IPHONE_SDKVERSION: iPhone SDK version (e.g. 8.0)
17#
18# Then go get the source tar.bz of the boost you want to build, shove it in the
19# same directory as this script, and run "./boost.sh". Grab a cuppa. And voila.
20#===============================================================================
21
22#!/bin/sh
23here="`dirname \"$0\"`"
24echo "cd-ing to $here"
25cd "$here" || exit 1
26
27CPPSTD=c++11 #c++89, c++99, c++14
28STDLIB=libc++ # libstdc++
29COMPILER=clang++
30
31BOOST_V1=1.57.0
32BOOST_V2=1_57_0
33
34CURRENTPATH=`pwd`
35LOGDIR="$CURRENTPATH/build/logs/"
36
37SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
38OSX_SDKVERSION=`xcrun -sdk macosx --show-sdk-version`
39DEVELOPER=`xcode-select -print-path`
40XCODE_ROOT=`xcode-select -print-path`
41
42if [ ! -d "$DEVELOPER" ]; then
43 echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)"
44 echo "run"
45 echo "sudo xcode-select -switch <xcode path>"
46 echo "for default installation:"
47 echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
48 exit 1
49fi
50
51case $DEVELOPER in
52 *\ * )
53 echo "Your Xcode path contains whitespaces, which is not supported."
54 exit 1
55 ;;
56esac
57
58case $CURRENTPATH in
59 *\ * )
60 echo "Your path contains whitespaces, which is not supported by 'make install'."
61 exit 1
62 ;;
63esac
64
65#: ${BOOST_LIBS:="random regex graph random chrono thread signals filesystem system date_time"}
66: ${BOOST_LIBS:="coroutine random regex graph random chrono thread signals filesystem system date_time"}
67: ${IPHONE_SDKVERSION:=`xcodebuild -showsdks | grep iphoneos | egrep "[[:digit:]]+\.[[:digit:]]+" -o | tail -1`}
68: ${EXTRA_CPPFLAGS:="-DBOOST_AC_USE_PTHREADS -DBOOST_SP_USE_PTHREADS -std=$CPPSTD -stdlib=$STDLIB"}
69
70# The EXTRA_CPPFLAGS definition works around a thread race issue in
71# shared_ptr. I encountered this historically and have not verified that
72# the fix is no longer required. Without using the posix thread primitives
73# an invalid compare-and-swap ARM instruction (non-thread-safe) was used for the
74# shared_ptr use count causing nasty and subtle bugs.
75#
76# Should perhaps also consider/use instead: -BOOST_SP_USE_PTHREADS
77
78: ${TARBALLDIR:=`pwd`/..}
79: ${SRCDIR:=`pwd`/../build/src}
80: ${IOSBUILDDIR:=`pwd`/../build/libs/boost/lib}
81: ${IOSINCLUDEDIR:=`pwd`/../build/libs/boost/include/boost}
82: ${PREFIXDIR:=`pwd`/../build/ios/prefix}
83: ${COMPILER:="clang++"}
84: ${OUTPUT_DIR:=`pwd`/../libs/boost/}
85: ${OUTPUT_DIR_LIB:=`pwd`/../libs/boost/ios/}
86: ${OUTPUT_DIR_SRC:=`pwd`/../libs/boost/include/boost}
87
88: ${BOOST_VERSION:=$BOOST_V1}
89: ${BOOST_VERSION2:=$BOOST_V2}
90
91BOOST_TARBALL=$TARBALLDIR/boost_$BOOST_VERSION2.tar.bz2
92BOOST_SRC=$SRCDIR/boost_${BOOST_VERSION2}
93BOOST_INCLUDE=$BOOST_SRC/boost
94
95
96
97#===============================================================================
98ARM_DEV_CMD="xcrun --sdk iphoneos"
99SIM_DEV_CMD="xcrun --sdk iphonesimulator"
100OSX_DEV_CMD="xcrun --sdk macosx"
101
102ARM_COMBINED_LIB=$IOSBUILDDIR/lib_boost_arm.a
103
104#===============================================================================
105
106
107#===============================================================================
108# Functions
109#===============================================================================
110
111abort()
112{
113 echo
114 echo "Aborted: $@"
115 exit 1
116}
117
118doneSection()
119{
120 echo
121 echo "================================================================="
122 echo "Done"
123 echo
124}
125
126#===============================================================================
127
128cleanEverythingReadyToStart()
129{
130 echo Cleaning everything before we start to build...
131
132 rm -rf iphone-build iphonesim-build osx-build
133 rm -rf $IOSBUILDDIR
134 rm -rf $PREFIXDIR
135 rm -rf $IOSINCLUDEDIR
136 rm -rf $TARBALLDIR/build
137 rm -rf $LOGDIR
138
139 doneSection
140}
141
142postcleanEverything()
143{
144 echo Cleaning everything after the build...
145
146 rm -rf iphone-build iphonesim-build osx-build
147 rm -rf $PREFIXDIR
148 rm -rf $IOSBUILDDIR/armv6/obj
149 rm -rf $IOSBUILDDIR/armv7/obj
150 rm -rf $IOSBUILDDIR/armv7s/obj
151 rm -rf $IOSBUILDDIR/arm64/obj
152 rm -rf $IOSBUILDDIR/i386/obj
153 rm -rf $IOSBUILDDIR/x86_64/obj
154 rm -rf $TARBALLDIR/build
155 rm -rf $LOGDIR
156 doneSection
157}
158
159prepare()
160{
161
162 mkdir -p $LOGDIR
163 mkdir -p $OUTPUT_DIR
164 mkdir -p $OUTPUT_DIR_SRC
165 mkdir -p $OUTPUT_DIR_LIB
166
167}
168
169#===============================================================================
170
171downloadBoost()
172{
173 if [ ! -s $TARBALLDIR/boost_${BOOST_VERSION2}.tar.bz2 ]; then
174 echo "Downloading boost ${BOOST_VERSION}"
175 curl -L -o $TARBALLDIR/boost_${BOOST_VERSION2}.tar.bz2 sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/boost_${BOOST_VERSION2}.tar.bz2/download
176 fi
177
178 doneSection
179}
180
181#===============================================================================
182
183unpackBoost()
184{
185 [ -f "$BOOST_TARBALL" ] || abort "Source tarball missing."
186
187 echo Unpacking boost into $SRCDIR...
188
189 [ -d $SRCDIR ] || mkdir -p $SRCDIR
190 [ -d $BOOST_SRC ] || ( cd $SRCDIR; tar xfj $BOOST_TARBALL )
191 [ -d $BOOST_SRC ] && echo " ...unpacked as $BOOST_SRC"
192
193 doneSection
194}
195
196#===============================================================================
197
198restoreBoost()
199{
200 cp $BOOST_SRC/tools/build/example/user-config.jam-bk $BOOST_SRC/tools/build/example/user-config.jam
201}
202
203#===============================================================================
204
205updateBoost()
206{
207 echo Updating boost into $BOOST_SRC...
208
209 cp $BOOST_SRC/tools/build/example/user-config.jam $BOOST_SRC/tools/build/example/user-config.jam-bk
210
211 cat >> $BOOST_SRC/tools/build/example/user-config.jam <<EOF
212using darwin : ${IPHONE_SDKVERSION}~iphone
213: $XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/$COMPILER -arch armv7 -arch armv7s -arch arm64 -fvisibility=hidden -fvisibility-inlines-hidden $EXTRA_CPPFLAGS
214: <striper> <root>$XCODE_ROOT/Platforms/iPhoneOS.platform/Developer
215: <architecture>arm <target-os>iphone
216;
217using darwin : ${IPHONE_SDKVERSION}~iphonesim
218: $XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/$COMPILER -arch i386 -arch x86_64 -fvisibility=hidden -fvisibility-inlines-hidden $EXTRA_CPPFLAGS
219: <striper> <root>$XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer
220: <architecture>x86 <target-os>iphone
221;
222EOF
223
224 doneSection
225}
226
227#===============================================================================
228
229inventMissingHeaders()
230{
231 # These files are missing in the ARM iPhoneOS SDK, but they are in the simulator.
232 # They are supported on the device, so we copy them from x86 SDK to a staging area
233 # to use them on ARM, too.
234 echo Invent missing headers
235
236 cp $XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_SDKVERSION}.sdk/usr/include/{crt_externs,bzlib}.h $BOOST_SRC
237}
238
239#===============================================================================
240
241bootstrapBoost()
242{
243 cd $BOOST_SRC
244
245 BOOST_LIBS_COMMA=$(echo $BOOST_LIBS | sed -e "s/ /,/g")
246 echo "Bootstrapping (with libs $BOOST_LIBS_COMMA)"
247 ./bootstrap.sh --with-libraries=$BOOST_LIBS_COMMA
248
249 doneSection
250}
251
252#===============================================================================
253
254buildBoostForIPhoneOS()
255{
256 cd $BOOST_SRC
257
258 # Install this one so we can copy the includes for the frameworks...
259
260
261 set +e
262 echo "------------------"
263 LOG="$LOGDIR/build-iphone-stage.log"
264 echo "Running bjam for iphone-build stage"
265 echo "To see status in realtime check:"
266 echo " ${LOG}"
267 echo "Please stand by..."
268 ./bjam -j16 --build-dir=iphone-build -sBOOST_BUILD_USER_CONFIG=$BOOST_SRC/tools/build/example/user-config.jam --stagedir=iphone-build/stage --prefix=$PREFIXDIR abi=aapcs binary-format=mach-o address-model=32 toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-${IPHONE_SDKVERSION} define=_LITTLE_ENDIAN link=static stage > "${LOG}" 2>&1
269 if [ $? != 0 ]; then
270 echo "Problem while Building iphone-build stage - Please check ${LOG}"
271 exit 1
272 else
273 echo "iphone-build stage successful"
274 fi
275
276 echo "------------------"
277 LOG="$LOGDIR/build-iphone-install.log"
278 echo "Running bjam for iphone-build install"
279 echo "To see status in realtime check:"
280 echo " ${LOG}"
281 echo "Please stand by..."
282 ./bjam -j16 --build-dir=iphone-build -sBOOST_BUILD_USER_CONFIG=$BOOST_SRC/tools/build/example/user-config.jam --stagedir=iphone-build/stage --prefix=$PREFIXDIR abi=aapcs binary-format=mach-o address-model=32 toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-${IPHONE_SDKVERSION} define=_LITTLE_ENDIAN link=static install > "${LOG}" 2>&1
283 if [ $? != 0 ]; then
284 echo "Problem while Building iphone-build install - Please check ${LOG}"
285 exit 1
286 else
287 echo "iphone-build install successful"
288 fi
289 doneSection
290
291 echo "------------------"
292 LOG="$LOGDIR/build-iphone-simulator-build.log"
293 echo "Running bjam for iphone-sim-build "
294 echo "To see status in realtime check:"
295 echo " ${LOG}"
296 echo "Please stand by..."
297 ./bjam -j16 --build-dir=iphonesim-build -sBOOST_BUILD_USER_CONFIG=$BOOST_SRC/tools/build/example/user-config.jam --stagedir=iphonesim-build/stage --toolset=darwin-${IPHONE_SDKVERSION}~iphonesim architecture=x86 target-os=iphone macosx-version=iphonesim-${IPHONE_SDKVERSION} link=static stage > "${LOG}" 2>&1
298 if [ $? != 0 ]; then
299 echo "Problem while Building iphone-simulator build - Please check ${LOG}"
300 exit 1
301 else
302 echo "iphone-simulator build successful"
303 fi
304
305 doneSection
306}
307
308#===============================================================================
309
310scrunchAllLibsTogetherInOneLibPerPlatform()
311{
312 cd $BOOST_SRC
313
314 mkdir -p $IOSBUILDDIR/armv7/obj
315 mkdir -p $IOSBUILDDIR/armv7s/obj
316 mkdir -p $IOSBUILDDIR/arm64/obj
317 mkdir -p $IOSBUILDDIR/i386/obj
318 mkdir -p $IOSBUILDDIR/x86_64/obj
319
320 ALL_LIBS=""
321
322 echo Splitting all existing fat binaries...
323
324 for NAME in $BOOST_LIBS; do
325 ALL_LIBS="$ALL_LIBS libboost_$NAME.a"
326
327 $ARM_DEV_CMD lipo "iphone-build/stage/lib/libboost_$NAME.a" -thin armv7 -o $IOSBUILDDIR/armv7/libboost_$NAME.a
328 $ARM_DEV_CMD lipo "iphone-build/stage/lib/libboost_$NAME.a" -thin armv7s -o $IOSBUILDDIR/armv7s/libboost_$NAME.a
329 $ARM_DEV_CMD lipo "iphone-build/stage/lib/libboost_$NAME.a" -thin arm64 -o $IOSBUILDDIR/arm64/libboost_$NAME.a
330
331 $ARM_DEV_CMD lipo "iphonesim-build/stage/lib/libboost_$NAME.a" -thin i386 -o $IOSBUILDDIR/i386/libboost_$NAME.a
332 $ARM_DEV_CMD lipo "iphonesim-build/stage/lib/libboost_$NAME.a" -thin x86_64 -o $IOSBUILDDIR/x86_64/libboost_$NAME.a
333
334 done
335
336 echo "Decomposing each architecture's .a files"
337
338 for NAME in $ALL_LIBS; do
339 echo Decomposing $NAME...
340 (cd $IOSBUILDDIR/armv7/obj; ar -x ../$NAME );
341 (cd $IOSBUILDDIR/armv7s/obj; ar -x ../$NAME );
342 (cd $IOSBUILDDIR/arm64/obj; ar -x ../$NAME );
343 (cd $IOSBUILDDIR/i386/obj; ar -x ../$NAME );
344 (cd $IOSBUILDDIR/x86_64/obj; ar -x ../$NAME );
345 done
346
347 echo "Linking each architecture into an uberlib ($ALL_LIBS => libboost.a )"
348
349 rm $IOSBUILDDIR/*/libboost.a
350
351 echo ...armv7
352 (cd $IOSBUILDDIR/armv7; $ARM_DEV_CMD ar crus libboost.a obj/*.o; )
353 echo ...armv7s
354 (cd $IOSBUILDDIR/armv7s; $ARM_DEV_CMD ar crus libboost.a obj/*.o; )
355 echo ...arm64
356 (cd $IOSBUILDDIR/arm64; $ARM_DEV_CMD ar crus libboost.a obj/*.o; )
357 echo ...i386
358 (cd $IOSBUILDDIR/i386; $SIM_DEV_CMD ar crus libboost.a obj/*.o; )
359 echo ...x86_64
360 (cd $IOSBUILDDIR/x86_64; $SIM_DEV_CMD ar crus libboost.a obj/*.o; )
361
362 echo "Making fat lib for iOS Boost $BOOST_VERSION"
363 lipo -c $IOSBUILDDIR/armv7/libboost.a \
364 $IOSBUILDDIR/armv7s/libboost.a \
365 $IOSBUILDDIR/arm64/libboost.a \
366 $IOSBUILDDIR/i386/libboost.a \
367 $IOSBUILDDIR/x86_64/libboost.a \
368 -output $OUTPUT_DIR_LIB/boost.a
369
370 echo "Completed Fat Lib"
371 echo "------------------"
372
373}
374
375#===============================================================================
376buildIncludes()
377{
378
379 mkdir -p $IOSINCLUDEDIR
380 echo "------------------"
381 echo "Copying Includes to Final Dir $OUTPUT_DIR_SRC"
382 LOG="$LOGDIR/buildIncludes.log"
383 set +e
384
385 cp -r $PREFIXDIR/include/boost/* $OUTPUT_DIR_SRC/ > "${LOG}" 2>&1
386 if [ $? != 0 ]; then
387 echo "Problem while copying includes - Please check ${LOG}"
388 exit 1
389 else
390 echo "Copy of Includes successful"
391 fi
392 echo "------------------"
393
394 doneSection
395}
396
397#===============================================================================
398# Execution starts here
399#===============================================================================
400
401mkdir -p $IOSBUILDDIR
402
403cleanEverythingReadyToStart #may want to comment if repeatedly running during dev
404restoreBoost
405
406echo "BOOST_VERSION: $BOOST_VERSION"
407echo "BOOST_LIBS: $BOOST_LIBS"
408echo "BOOST_SRC: $BOOST_SRC"
409echo "IOSBUILDDIR: $IOSBUILDDIR"
410echo "PREFIXDIR: $PREFIXDIR"
411echo "IOSFRAMEWORKDIR: $IOSFRAMEWORKDIR"
412echo "OSXFRAMEWORKDIR: $OSXFRAMEWORKDIR"
413echo "IPHONE_SDKVERSION: $IPHONE_SDKVERSION"
414echo "XCODE_ROOT: $XCODE_ROOT"
415echo "COMPILER: $COMPILER"
416echo
417
418downloadBoost
419unpackBoost
420#inventMissingHeaders
421prepare
422bootstrapBoost
423updateBoost
424buildBoostForIPhoneOS
425scrunchAllLibsTogetherInOneLibPerPlatform
426buildIncludes
427
428restoreBoost
429
430postcleanEverything
431
432echo "Completed successfully"
433
434#===============================================================================