3 # Build a fat binary for iOS
4 # Based on fatbuild.sh and code from the Ignifuga Game Engine
6 # Number of CPUs (for make -j)
7 NCPU=`sysctl -n hw.ncpu`
8 if test x$NJOB = x; then
13 XCODE_PATH=`xcode-select --print-path`
14 if [ -z "$XCODE_PATH" ]; then
15 echo "Could not find XCode location (use xcode-select -switch to set the correct path)"
19 prepare_environment() {
22 if test x$SDK_VERSION = x; then
23 export SDK_VERSION=`xcodebuild -showsdks | grep iphoneos | sed "s|.*iphoneos||"`
24 if [ -z "$XCODE_PATH" ]; then
25 echo "Could not find a valid iOS SDK"
32 DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
33 SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
36 DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
37 SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
40 DEV_PATH="$XCODE_PATH/Platforms/iPhoneSimulator.platform/Developer"
41 SDK_PATH="$DEV_PATH/SDKs/iPhoneSimulator$SDK_VERSION.sdk"
44 echo "Unknown Architecture $ARCH"
49 if [ ! -d "$SDK_PATH" ]; then
50 echo "Could not find iOS SDK at $SDK_PATH"
54 if test x$MIN_OS_VERSION = x; then
55 export MIN_OS_VERSION="3.0"
59 CFLAGS="-g -O2 -pipe -no-cpp-precomp -isysroot $SDK_PATH \
60 -miphoneos-version-min=$MIN_OS_VERSION -I$SDK_PATH/usr/include/"
61 LDFLAGS="-L$SDK_PATH/usr/lib/ -isysroot $SDK_PATH \
62 -miphoneos-version-min=$MIN_OS_VERSION -static-libgcc"
63 export CXXFLAGS="$CFLAGS"
64 export CXXCPP="$DEV_PATH/usr/bin/llvm-cpp-4.2"
66 export CXX="$DEV_PATH/usr/bin/llvm-g++-4.2"
67 export CC="$DEV_PATH/usr/bin/llvm-gcc-4.2"
68 export LD="$DEV_PATH/usr/bin/ld"
69 export AR="$DEV_PATH/usr/bin/ar"
70 export AS="$DEV_PATH/usr/bin/ls"
71 export NM="$DEV_PATH/usr/bin/nm"
72 export RANLIB="$DEV_PATH/usr/bin/ranlib"
73 export STRIP="$DEV_PATH/usr/bin/strip"
75 # We dynamically load X11, so using the system X11 headers is fine.
76 CONFIG_FLAGS="--disable-shared --enable-static"
80 export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv6-apple-darwin"
81 export CFLAGS="$CFLAGS -arch armv6"
82 export LDFLAGS="$LDFLAGS -arch armv6"
85 export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv7-apple-darwin"
86 export CFLAGS="$CFLAGS -arch armv7"
87 export LDFLAGS="$LDFLAGS -arch armv7"
90 export CONFIG_FLAGS="$CONFIG_FLAGS --host=i386-apple-darwin"
91 export CFLAGS="$CFLAGS -arch i386"
92 export LDFLAGS="$LDFLAGS -arch i386"
95 echo "Unknown Architecture $ARCH"
101 prepare_environment "armv6"
102 echo "Building with iOS SDK v$SDK_VERSION for iOS >= $MIN_OS_VERSION"
105 # Find the configure script
107 srcdir=`dirname $0`/..
108 srcdir=`cd $srcdir && pwd`
109 auxdir=$srcdir/build-scripts
113 # Figure out which phase to build:
115 # configure, configure-armv6, configure-armv7, configure-i386
116 # make, make-armv6, make-armv7, make-i386, merge
118 if test x"$1" = x; then
125 configure_armv6="yes"
126 configure_armv7="yes"
134 configure_armv6="yes"
135 configure_armv7="yes"
139 configure_armv6="yes"
142 configure_armv7="yes"
180 echo "Usage: $0 [all|configure[-armv6|-armv7|-i386]|make[-armv6|-armv7|-i386]|merge|clean[-armv6|-armv7|-i386]]"
186 # Create the build directories
188 for dir in build build/armv6 build/armv7 build/i386; do
189 if test -d $dir; then
197 # Build the armv6 binary
199 prepare_environment "armv6"
200 if test x$configure_armv6 = xyes; then
202 sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
203 # configure is not yet fully ready for iOS, some manual patching is required
204 cp include/* build/armv6/include
205 cp include/SDL_config_iphoneos.h build/armv6/include/SDL_config.h || exit 2
206 sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv6/Makefile || exit 2
207 sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv6/Makefile || exit 2
209 if test x$make_armv6 = xyes; then
210 (cd build/armv6 && make -j$NJOB) || exit 3
213 # Build the armv7 binary
215 prepare_environment "armv7"
216 if test x$configure_armv7 = xyes; then
218 sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
219 # configure is not yet fully ready for iOS, some manual patching is required
220 cp include/* build/armv7/include
221 cp include/SDL_config_iphoneos.h build/armv7/include/SDL_config.h || exit 2
222 sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv7/Makefile || exit 2
223 sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv7/Makefile || exit 2
225 if test x$make_armv7 = xyes; then
226 (cd build/armv7 && make -j$NJOB) || exit 3
229 # Build the i386 binary
231 prepare_environment "i386"
232 if test x$configure_i386 = xyes; then
234 sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
235 # configure is not yet fully ready for iOS, some manual patching is required
236 cp include/* build/i386/include
237 cp include/SDL_config_iphoneos.h build/i386/include/SDL_config.h || exit 2
238 sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/i386/Makefile || exit 2
239 sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/i386/Makefile || exit 2
241 if test x$make_i386 = xyes; then
242 (cd build/i386 && make -j$NJOB) || exit 3
246 # Combine into fat binary
248 if test x$merge = xyes; then
250 sh $auxdir/mkinstalldirs build/$output
252 target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
253 (lipo -create -o $output/libSDL2.a armv6/build/.libs/libSDL2.a armv7/build/.libs/libSDL2.a i386/build/.libs/libSDL2.a &&
254 lipo -create -o $output/libSDL2main.a armv6/build/libSDL2main.a armv7/build/libSDL2main.a i386/build/libSDL2main.a &&
255 cp -r armv6/include ios
256 echo "Build complete!" &&
257 echo "Files can be found under the build/ios directory.") || exit 4
269 if test x$clean_armv6 = xyes; then
270 do_clean rm -r build/armv6
272 if test x$clean_armv7 = xyes; then
273 do_clean rm -r build/armv7
275 if test x$clean_i386 = xyes; then
276 do_clean rm -r build/i386