3 # Build a fat binary for iOS
5 # Number of CPUs (for make -j)
6 NCPU=`sysctl -n hw.ncpu`
7 if test x$NJOB = x; then
11 SRC_DIR=$(cd `dirname $0`/..; pwd)
12 if [ "$PWD" = "$SRC_DIR" ]; then
13 PREFIX=$SRC_DIR/ios-build
14 if [ ! -d "$PREFIX" ]; then
22 BUILD_X86_64_IOSSIM=YES
33 XCODEDIR=`xcode-select --print-path`
34 IOS_SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
37 IPHONEOS_PLATFORM=`xcrun --sdk iphoneos --show-sdk-platform-path`
38 IPHONEOS_SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
40 IPHONESIMULATOR_PLATFORM=`xcrun --sdk iphonesimulator --show-sdk-platform-path`
41 IPHONESIMULATOR_SYSROOT=`xcrun --sdk iphonesimulator --show-sdk-path`
43 # Uncomment if you want to see more information about each invocation
44 # of clang as the builds proceed.
45 # CLANG_VERBOSE="--verbose"
50 SILENCED_WARNINGS="-Wno-unused-local-typedef -Wno-unused-function"
52 CFLAGS="${CLANG_VERBOSE} ${SILENCED_WARNINGS} -DNDEBUG -g -O0 -pipe -fPIC -fobjc-arc"
54 echo "PREFIX ..................... ${PREFIX}"
55 echo "BUILD_MACOSX_X86_64 ........ ${BUILD_MACOSX_X86_64}"
56 echo "BUILD_I386_IOSSIM .......... ${BUILD_I386_IOSSIM}"
57 echo "BUILD_X86_64_IOSSIM ........ ${BUILD_X86_64_IOSSIM}"
58 echo "BUILD_IOS_ARMV7 ............ ${BUILD_IOS_ARMV7}"
59 echo "BUILD_IOS_ARMV7S ........... ${BUILD_IOS_ARMV7S}"
60 echo "BUILD_IOS_ARM64 ............ ${BUILD_IOS_ARM64}"
61 echo "DARWIN ..................... ${DARWIN}"
62 echo "XCODEDIR ................... ${XCODEDIR}"
63 echo "IOS_SDK_VERSION ............ ${IOS_SDK_VERSION}"
64 echo "MIN_SDK_VERSION ............ ${MIN_SDK_VERSION}"
65 echo "IPHONEOS_PLATFORM .......... ${IPHONEOS_PLATFORM}"
66 echo "IPHONEOS_SYSROOT ........... ${IPHONEOS_SYSROOT}"
67 echo "IPHONESIMULATOR_PLATFORM ... ${IPHONESIMULATOR_PLATFORM}"
68 echo "IPHONESIMULATOR_SYSROOT .... ${IPHONESIMULATOR_SYSROOT}"
69 echo "CC ......................... ${CC}"
70 echo "CFLAGS ..................... ${CFLAGS}"
71 echo "CXX ........................ ${CXX}"
72 echo "CXXFLAGS ................... ${CXXFLAGS}"
73 echo "LDFLAGS .................... ${LDFLAGS}"
75 ###################################################################
76 # This section contains the build commands for each of the
77 # architectures that will be included in the universal binaries.
78 ###################################################################
80 echo "$(tput setaf 2)"
81 echo "###########################"
82 echo "# i386 for iPhone Simulator"
83 echo "###########################"
86 if [ "${BUILD_I386_IOSSIM}" == "YES" ]
91 ../configure --build=x86_64-apple-${DARWIN} --host=i386-ios-${DARWIN} --disable-shared --prefix=${PREFIX}/platform/i386-sim "CC=${CC}" "CFLAGS=${CFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch i386 -mios-simulator-version-min=${MIN_SDK_VERSION} ${LDFLAGS} -L${IPHONESIMULATOR_SYSROOT}/usr/lib/ -L${IPHONESIMULATOR_SYSROOT}/usr/lib/system" || exit 2
92 cp $SRC_DIR/include/SDL_config_iphoneos.h include/SDL_config.h
98 echo "$(tput setaf 2)"
99 echo "#############################"
100 echo "# x86_64 for iPhone Simulator"
101 echo "#############################"
104 if [ "${BUILD_X86_64_IOSSIM}" == "YES" ]
109 ../configure --build=x86_64-apple-${DARWIN} --host=x86_64-ios-${DARWIN} --disable-shared --prefix=${PREFIX}/platform/x86_64-sim "CC=${CC}" "CFLAGS=${CFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch x86_64 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch x86_64 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch x86_64 -mios-simulator-version-min=${MIN_SDK_VERSION} ${LDFLAGS} -L${IPHONESIMULATOR_SYSROOT}/usr/lib/ -L${IPHONESIMULATOR_SYSROOT}/usr/lib/system" || exit 2
110 cp $SRC_DIR/include/SDL_config_iphoneos.h include/SDL_config.h
111 make -j$NJOB || exit 3
116 echo "$(tput setaf 2)"
117 echo "##################"
118 echo "# armv7 for iPhone"
119 echo "##################"
122 if [ "${BUILD_IOS_ARMV7}" == "YES" ]
127 ../configure --build=x86_64-apple-${DARWIN} --host=armv7-ios-${DARWIN} --disable-shared --prefix=${PREFIX}/platform/armv7-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" || exit 2
128 cp $SRC_DIR/include/SDL_config_iphoneos.h include/SDL_config.h
129 make -j$NJOB || exit 3
134 echo "$(tput setaf 2)"
135 echo "###################"
136 echo "# armv7s for iPhone"
137 echo "###################"
140 if [ "${BUILD_IOS_ARMV7S}" == "YES" ]
145 ../configure --build=x86_64-apple-${DARWIN} --host=armv7s-ios-${DARWIN} --disable-shared --prefix=${PREFIX}/platform/armv7s-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7s -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" || exit 2
146 cp $SRC_DIR/include/SDL_config_iphoneos.h include/SDL_config.h
147 make -j$NJOB || exit 3
152 echo "$(tput setaf 2)"
153 echo "##################"
154 echo "# arm64 for iPhone"
155 echo "##################"
158 if [ "${BUILD_IOS_ARM64}" == "YES" ]
163 ../configure --build=x86_64-apple-${DARWIN} --host=arm-ios-${DARWIN} --disable-shared --prefix=${PREFIX}/platform/arm64-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch arm64 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" || exit 2
164 cp $SRC_DIR/include/SDL_config_iphoneos.h include/SDL_config.h
165 make -j$NJOB || exit 3
170 echo "$(tput setaf 2)"
171 echo "###################################################################"
172 echo "# Create Universal Libraries and Finalize the packaging"
173 echo "###################################################################"
177 cd ${PREFIX}/platform
179 lipo x86_64-sim/lib/libSDL2.a i386-sim/lib/libSDL2.a arm64-ios/lib/libSDL2.a armv7s-ios/lib/libSDL2.a armv7-ios/lib/libSDL2.a -create -output universal/libSDL2.a
185 cp -r platform/universal/* lib
187 lipo -info lib/libSDL2.a