Adds a simple command line utility (iosbuild.sh) to create iOS binaries for armv6, armv7 and i386
authorGabriel Jacobo <gabomdq@gmail.com>
Tue, 19 Jun 2012 18:25:04 -0300
changeset 63338d541aa4e1da
parent 6332 019660f4cc2b
child 6334 85b8778a05c2
Adds a simple command line utility (iosbuild.sh) to create iOS binaries for armv6, armv7 and i386
README.iOS
build-scripts/iosbuild.sh
     1.1 --- a/README.iOS	Tue Jun 19 13:50:14 2012 -0400
     1.2 +++ b/README.iOS	Tue Jun 19 18:25:04 2012 -0300
     1.3 @@ -17,6 +17,26 @@
     1.4  	Package a project template together with the SDL for iPhone static libraries and copies of the SDL headers.  The template includes proper references to the SDL library and headers, skeleton code for a basic SDL program, and placeholder graphics for the application icon and startup screen.
     1.5  
     1.6  ==============================================================================
     1.7 +Build SDL for iOS from the command line
     1.8 +==============================================================================
     1.9 +
    1.10 +1. cd (PATH WHERE THE SDL CODE IS)/build-scripts
    1.11 +2. ./iosbuild.sh
    1.12 +
    1.13 +If everything goes fine, you should see a build/ios directory, inside there's
    1.14 +two directories "lib" and "include". 
    1.15 +"include" contains a copy of the SDL headers that you'll need for your project,
    1.16 +make sure to configure XCode to look for headers there.
    1.17 +"lib" contains find two files, libSDL2.a and libSDL2main.a, you have to add both 
    1.18 +to your XCode project. These libraries contain three architectures in them,
    1.19 +armv6 for legacy devices, armv7, and i386 (for the simulator).
    1.20 +By default, iosbuild.sh will autodetect the SDK version you have installed using 
    1.21 +xcodebuild -showsdks, and build for iOS >= 3.0, you can override this behaviour 
    1.22 +by setting the MIN_OS_VERSION variable, ie:
    1.23 +
    1.24 +MIN_OS_VERSION=4.2 ./iosbuild.sh
    1.25 +
    1.26 +==============================================================================
    1.27  Using the Simple DirectMedia Layer for iOS
    1.28  ==============================================================================
    1.29  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/build-scripts/iosbuild.sh	Tue Jun 19 18:25:04 2012 -0300
     2.3 @@ -0,0 +1,277 @@
     2.4 +#!/bin/sh
     2.5 +#
     2.6 +# Build a fat binary for iOS
     2.7 +# Based on fatbuild.sh and code from the Ignifuga Game Engine
     2.8 +
     2.9 +# Number of CPUs (for make -j)
    2.10 +NCPU=`sysctl -n hw.ncpu`
    2.11 +if test x$NJOB = x; then
    2.12 +    NJOB=$NCPU
    2.13 +fi
    2.14 +
    2.15 +# SDK path
    2.16 +XCODE_PATH=`xcode-select --print-path`
    2.17 +if [ -z "$XCODE_PATH" ]; then
    2.18 +    echo "Could not find XCode location"
    2.19 +    exit 1
    2.20 +fi
    2.21 +
    2.22 +prepare_environment() {
    2.23 +    ARCH=$1
    2.24 +    
    2.25 +    if test x$SDK_VERSION = x; then
    2.26 +      export SDK_VERSION=`xcodebuild -showsdks | grep iphoneos | sed "s|.*iphoneos||"`
    2.27 +      if [ -z "$XCODE_PATH" ]; then
    2.28 +          echo "Could not find a valid iOS SDK"
    2.29 +          exit 1
    2.30 +      fi  
    2.31 +    fi
    2.32 +    
    2.33 +    case $ARCH in
    2.34 +        armv6)
    2.35 +            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
    2.36 +            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
    2.37 +            ;;
    2.38 +        armv7)
    2.39 +            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
    2.40 +            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
    2.41 +            ;;
    2.42 +        i386)
    2.43 +            DEV_PATH="$XCODE_PATH/Platforms/iPhoneSimulator.platform/Developer"
    2.44 +            SDK_PATH="$DEV_PATH/SDKs/iPhoneSimulator$SDK_VERSION.sdk"
    2.45 +            ;;
    2.46 +        *)
    2.47 +            echo "Unknown Architecture $ARCH"
    2.48 +            exit 1
    2.49 +            ;;
    2.50 +    esac
    2.51 +
    2.52 +    if [ ! -d "$SDK_PATH" ]; then
    2.53 +        echo "Could not find iOS SDK at $SDK_PATH"
    2.54 +        exit 1
    2.55 +    fi
    2.56 +
    2.57 +    if test x$MIN_OS_VERSION = x; then
    2.58 +        export MIN_OS_VERSION="3.0"
    2.59 +    fi
    2.60 +    
    2.61 +    # Environment flags
    2.62 +    CFLAGS="-g -O2 -pipe -no-cpp-precomp -isysroot $SDK_PATH \
    2.63 +            -miphoneos-version-min=$MIN_OS_VERSION -I$SDK_PATH/usr/include/"
    2.64 +    LDFLAGS="-L$SDK_PATH/usr/lib/ -isysroot $SDK_PATH \
    2.65 +             -miphoneos-version-min=$MIN_OS_VERSION -static-libgcc"
    2.66 +    export CXXFLAGS="$CFLAGS"
    2.67 +    export CXXCPP="$DEV_PATH/usr/bin/llvm-cpp-4.2"
    2.68 +    export CPP="$CXXCPP"
    2.69 +    export CXX="$DEV_PATH/usr/bin/llvm-g++-4.2"
    2.70 +    export CC="$DEV_PATH/usr/bin/llvm-gcc-4.2"
    2.71 +    export LD="$DEV_PATH/usr/bin/ld"
    2.72 +    export AR="$DEV_PATH/usr/bin/ar"
    2.73 +    export AS="$DEV_PATH/usr/bin/ls"
    2.74 +    export NM="$DEV_PATH/usr/bin/nm"
    2.75 +    export RANLIB="$DEV_PATH/usr/bin/ranlib"
    2.76 +    export STRIP="$DEV_PATH/usr/bin/strip"
    2.77 +    
    2.78 +    # We dynamically load X11, so using the system X11 headers is fine.
    2.79 +    CONFIG_FLAGS="--disable-shared --enable-static"
    2.80 +    
    2.81 +    case $ARCH in
    2.82 +        armv6)
    2.83 +            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv6-apple-darwin"
    2.84 +            export CFLAGS="$CFLAGS -arch armv6"
    2.85 +            export LDFLAGS="$LDFLAGS -arch armv6"
    2.86 +            ;;
    2.87 +        armv7)
    2.88 +            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv7-apple-darwin"
    2.89 +            export CFLAGS="$CFLAGS -arch armv7"
    2.90 +            export LDFLAGS="$LDFLAGS -arch armv7"
    2.91 +            ;;
    2.92 +        i386)
    2.93 +            export CONFIG_FLAGS="$CONFIG_FLAGS --host=i386-apple-darwin"
    2.94 +            export CFLAGS="$CFLAGS -arch i386"
    2.95 +            export LDFLAGS="$LDFLAGS -arch i386"
    2.96 +            ;;
    2.97 +        *)
    2.98 +            echo "Unknown Architecture $ARCH"
    2.99 +            exit 1
   2.100 +            ;;
   2.101 +    esac
   2.102 +}
   2.103 +
   2.104 +prepare_environment "armv6"
   2.105 +echo "Building with iOS SDK v$SDK_VERSION for iOS >= $MIN_OS_VERSION"
   2.106 +
   2.107 +#
   2.108 +# Find the configure script
   2.109 +#
   2.110 +srcdir=`dirname $0`/..
   2.111 +srcdir=`cd $srcdir && pwd`
   2.112 +auxdir=$srcdir/build-scripts
   2.113 +cd $srcdir
   2.114 +
   2.115 +#
   2.116 +# Figure out which phase to build:
   2.117 +# all,
   2.118 +# configure, configure-armv6, configure-armv7, configure-i386
   2.119 +# make, make-armv6, make-armv7, make-i386, merge
   2.120 +# clean
   2.121 +if test x"$1" = x; then
   2.122 +    phase=all
   2.123 +else
   2.124 +    phase="$1"
   2.125 +fi
   2.126 +case $phase in
   2.127 +    all)
   2.128 +        configure_armv6="yes"
   2.129 +        configure_armv7="yes"
   2.130 +        configure_i386="yes"
   2.131 +        make_armv6="yes"
   2.132 +        make_armv7="yes"
   2.133 +        make_i386="yes"
   2.134 +        merge="yes"
   2.135 +        ;;
   2.136 +    configure)
   2.137 +        configure_armv6="yes"
   2.138 +        configure_armv7="yes"
   2.139 +        configure_i386="yes"
   2.140 +        ;;
   2.141 +    configure-armv6)
   2.142 +        configure_armv6="yes"
   2.143 +        ;;
   2.144 +    configure-armv7)
   2.145 +        configure_armv7="yes"
   2.146 +        ;;
   2.147 +    configure-i386)
   2.148 +        configure_i386="yes"
   2.149 +        ;;
   2.150 +    make)
   2.151 +        make_armv6="yes"
   2.152 +        make_armv7="yes"
   2.153 +        make_i386="yes"
   2.154 +        merge="yes"
   2.155 +        ;;
   2.156 +    make-armv6)
   2.157 +        make_armv6="yes"
   2.158 +        ;;
   2.159 +    make-armv7)
   2.160 +        make_armv7="yes"
   2.161 +        ;;
   2.162 +    make-i386)
   2.163 +        make_i386="yes"
   2.164 +        ;;
   2.165 +    merge)
   2.166 +        merge="yes"
   2.167 +        ;;
   2.168 +    clean)
   2.169 +        clean_armv6="yes"
   2.170 +        clean_armv7="yes"
   2.171 +        clean_i386="yes"
   2.172 +        ;;
   2.173 +    clean-armv6)
   2.174 +        clean_armv6="yes"
   2.175 +        ;;
   2.176 +    clean-armv7)
   2.177 +        clean_armv7="yes"
   2.178 +        ;;
   2.179 +    clean-i386)
   2.180 +        clean_i386="yes"
   2.181 +        ;;
   2.182 +    *)
   2.183 +        echo "Usage: $0 [all|configure[-armv6|-armv7|-i386]|make[-armv6|-armv7|-i386]|merge|clean[-armv6|-armv7|-i386]]"
   2.184 +        exit 1
   2.185 +        ;;
   2.186 +esac
   2.187 +
   2.188 +#
   2.189 +# Create the build directories
   2.190 +#
   2.191 +for dir in build build/armv6 build/armv7 build/i386; do
   2.192 +    if test -d $dir; then
   2.193 +        :
   2.194 +    else
   2.195 +        mkdir $dir || exit 1
   2.196 +    fi
   2.197 +done
   2.198 +
   2.199 +#
   2.200 +# Build the armv6 binary
   2.201 +#
   2.202 +prepare_environment "armv6"
   2.203 +if test x$configure_armv6 = xyes; then
   2.204 +    (cd build/armv6 && \
   2.205 +     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
   2.206 +     # configure is not yet fully ready for iOS, some manual patching is required
   2.207 +     cp include/* build/armv6/include
   2.208 +     cp include/SDL_config_iphoneos.h build/armv6/include/SDL_config.h || exit 2
   2.209 +     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv6/Makefile || exit 2
   2.210 +     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv6/Makefile || exit 2
   2.211 +fi
   2.212 +if test x$make_armv6 = xyes; then
   2.213 +    (cd build/armv6 && make -j$NJOB) || exit 3
   2.214 +fi
   2.215 +#
   2.216 +# Build the armv7 binary
   2.217 +#
   2.218 +prepare_environment "armv7"
   2.219 +if test x$configure_armv7 = xyes; then
   2.220 +    (cd build/armv7 && \
   2.221 +     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
   2.222 +     # configure is not yet fully ready for iOS, some manual patching is required
   2.223 +     cp include/* build/armv7/include
   2.224 +     cp include/SDL_config_iphoneos.h build/armv7/include/SDL_config.h || exit 2
   2.225 +     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv7/Makefile || exit 2
   2.226 +     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv7/Makefile || exit 2
   2.227 +fi
   2.228 +if test x$make_armv7 = xyes; then
   2.229 +    (cd build/armv7 && make -j$NJOB) || exit 3
   2.230 +fi
   2.231 +#
   2.232 +# Build the i386 binary
   2.233 +#
   2.234 +prepare_environment "i386"
   2.235 +if test x$configure_i386 = xyes; then
   2.236 +    (cd build/i386 && \
   2.237 +     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
   2.238 +     # configure is not yet fully ready for iOS, some manual patching is required
   2.239 +     cp include/* build/i386/include
   2.240 +     cp include/SDL_config_iphoneos.h build/i386/include/SDL_config.h || exit 2
   2.241 +     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/i386/Makefile || exit 2
   2.242 +     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/i386/Makefile || exit 2
   2.243 +fi
   2.244 +if test x$make_i386 = xyes; then
   2.245 +    (cd build/i386 && make -j$NJOB) || exit 3
   2.246 +fi
   2.247 +
   2.248 +#
   2.249 +# Combine into fat binary
   2.250 +#
   2.251 +if test x$merge = xyes; then
   2.252 +    output=ios/lib
   2.253 +    sh $auxdir/mkinstalldirs build/$output
   2.254 +    cd build
   2.255 +    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
   2.256 +    (lipo -create -o $output/libSDL2.a */build/.libs/libSDL2.a &&
   2.257 +     lipo -create -o $output/libSDL2main.a */build/libSDL2main.a &&
   2.258 +     cp -r armv6/include ios
   2.259 +     echo "Build complete!" &&
   2.260 +     echo "Files can be found under the build/ios directory.") || exit 4
   2.261 +    cd ..
   2.262 +fi
   2.263 +
   2.264 +#
   2.265 +# Clean up
   2.266 +#
   2.267 +do_clean()
   2.268 +{
   2.269 +    echo $*
   2.270 +    $* || exit 6
   2.271 +}
   2.272 +if test x$clean_armv6 = xyes; then
   2.273 +    do_clean rm -r build/armv6
   2.274 +fi
   2.275 +if test x$clean_armv7 = xyes; then
   2.276 +    do_clean rm -r build/armv7
   2.277 +fi
   2.278 +if test x$clean_i386 = xyes; then
   2.279 +    do_clean rm -r build/i386
   2.280 +fi