build-scripts/iosbuild.sh
changeset 6333 8d541aa4e1da
child 6334 85b8778a05c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build-scripts/iosbuild.sh	Tue Jun 19 18:25:04 2012 -0300
     1.3 @@ -0,0 +1,277 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Build a fat binary for iOS
     1.7 +# Based on fatbuild.sh and code from the Ignifuga Game Engine
     1.8 +
     1.9 +# Number of CPUs (for make -j)
    1.10 +NCPU=`sysctl -n hw.ncpu`
    1.11 +if test x$NJOB = x; then
    1.12 +    NJOB=$NCPU
    1.13 +fi
    1.14 +
    1.15 +# SDK path
    1.16 +XCODE_PATH=`xcode-select --print-path`
    1.17 +if [ -z "$XCODE_PATH" ]; then
    1.18 +    echo "Could not find XCode location"
    1.19 +    exit 1
    1.20 +fi
    1.21 +
    1.22 +prepare_environment() {
    1.23 +    ARCH=$1
    1.24 +    
    1.25 +    if test x$SDK_VERSION = x; then
    1.26 +      export SDK_VERSION=`xcodebuild -showsdks | grep iphoneos | sed "s|.*iphoneos||"`
    1.27 +      if [ -z "$XCODE_PATH" ]; then
    1.28 +          echo "Could not find a valid iOS SDK"
    1.29 +          exit 1
    1.30 +      fi  
    1.31 +    fi
    1.32 +    
    1.33 +    case $ARCH in
    1.34 +        armv6)
    1.35 +            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
    1.36 +            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
    1.37 +            ;;
    1.38 +        armv7)
    1.39 +            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
    1.40 +            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
    1.41 +            ;;
    1.42 +        i386)
    1.43 +            DEV_PATH="$XCODE_PATH/Platforms/iPhoneSimulator.platform/Developer"
    1.44 +            SDK_PATH="$DEV_PATH/SDKs/iPhoneSimulator$SDK_VERSION.sdk"
    1.45 +            ;;
    1.46 +        *)
    1.47 +            echo "Unknown Architecture $ARCH"
    1.48 +            exit 1
    1.49 +            ;;
    1.50 +    esac
    1.51 +
    1.52 +    if [ ! -d "$SDK_PATH" ]; then
    1.53 +        echo "Could not find iOS SDK at $SDK_PATH"
    1.54 +        exit 1
    1.55 +    fi
    1.56 +
    1.57 +    if test x$MIN_OS_VERSION = x; then
    1.58 +        export MIN_OS_VERSION="3.0"
    1.59 +    fi
    1.60 +    
    1.61 +    # Environment flags
    1.62 +    CFLAGS="-g -O2 -pipe -no-cpp-precomp -isysroot $SDK_PATH \
    1.63 +            -miphoneos-version-min=$MIN_OS_VERSION -I$SDK_PATH/usr/include/"
    1.64 +    LDFLAGS="-L$SDK_PATH/usr/lib/ -isysroot $SDK_PATH \
    1.65 +             -miphoneos-version-min=$MIN_OS_VERSION -static-libgcc"
    1.66 +    export CXXFLAGS="$CFLAGS"
    1.67 +    export CXXCPP="$DEV_PATH/usr/bin/llvm-cpp-4.2"
    1.68 +    export CPP="$CXXCPP"
    1.69 +    export CXX="$DEV_PATH/usr/bin/llvm-g++-4.2"
    1.70 +    export CC="$DEV_PATH/usr/bin/llvm-gcc-4.2"
    1.71 +    export LD="$DEV_PATH/usr/bin/ld"
    1.72 +    export AR="$DEV_PATH/usr/bin/ar"
    1.73 +    export AS="$DEV_PATH/usr/bin/ls"
    1.74 +    export NM="$DEV_PATH/usr/bin/nm"
    1.75 +    export RANLIB="$DEV_PATH/usr/bin/ranlib"
    1.76 +    export STRIP="$DEV_PATH/usr/bin/strip"
    1.77 +    
    1.78 +    # We dynamically load X11, so using the system X11 headers is fine.
    1.79 +    CONFIG_FLAGS="--disable-shared --enable-static"
    1.80 +    
    1.81 +    case $ARCH in
    1.82 +        armv6)
    1.83 +            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv6-apple-darwin"
    1.84 +            export CFLAGS="$CFLAGS -arch armv6"
    1.85 +            export LDFLAGS="$LDFLAGS -arch armv6"
    1.86 +            ;;
    1.87 +        armv7)
    1.88 +            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv7-apple-darwin"
    1.89 +            export CFLAGS="$CFLAGS -arch armv7"
    1.90 +            export LDFLAGS="$LDFLAGS -arch armv7"
    1.91 +            ;;
    1.92 +        i386)
    1.93 +            export CONFIG_FLAGS="$CONFIG_FLAGS --host=i386-apple-darwin"
    1.94 +            export CFLAGS="$CFLAGS -arch i386"
    1.95 +            export LDFLAGS="$LDFLAGS -arch i386"
    1.96 +            ;;
    1.97 +        *)
    1.98 +            echo "Unknown Architecture $ARCH"
    1.99 +            exit 1
   1.100 +            ;;
   1.101 +    esac
   1.102 +}
   1.103 +
   1.104 +prepare_environment "armv6"
   1.105 +echo "Building with iOS SDK v$SDK_VERSION for iOS >= $MIN_OS_VERSION"
   1.106 +
   1.107 +#
   1.108 +# Find the configure script
   1.109 +#
   1.110 +srcdir=`dirname $0`/..
   1.111 +srcdir=`cd $srcdir && pwd`
   1.112 +auxdir=$srcdir/build-scripts
   1.113 +cd $srcdir
   1.114 +
   1.115 +#
   1.116 +# Figure out which phase to build:
   1.117 +# all,
   1.118 +# configure, configure-armv6, configure-armv7, configure-i386
   1.119 +# make, make-armv6, make-armv7, make-i386, merge
   1.120 +# clean
   1.121 +if test x"$1" = x; then
   1.122 +    phase=all
   1.123 +else
   1.124 +    phase="$1"
   1.125 +fi
   1.126 +case $phase in
   1.127 +    all)
   1.128 +        configure_armv6="yes"
   1.129 +        configure_armv7="yes"
   1.130 +        configure_i386="yes"
   1.131 +        make_armv6="yes"
   1.132 +        make_armv7="yes"
   1.133 +        make_i386="yes"
   1.134 +        merge="yes"
   1.135 +        ;;
   1.136 +    configure)
   1.137 +        configure_armv6="yes"
   1.138 +        configure_armv7="yes"
   1.139 +        configure_i386="yes"
   1.140 +        ;;
   1.141 +    configure-armv6)
   1.142 +        configure_armv6="yes"
   1.143 +        ;;
   1.144 +    configure-armv7)
   1.145 +        configure_armv7="yes"
   1.146 +        ;;
   1.147 +    configure-i386)
   1.148 +        configure_i386="yes"
   1.149 +        ;;
   1.150 +    make)
   1.151 +        make_armv6="yes"
   1.152 +        make_armv7="yes"
   1.153 +        make_i386="yes"
   1.154 +        merge="yes"
   1.155 +        ;;
   1.156 +    make-armv6)
   1.157 +        make_armv6="yes"
   1.158 +        ;;
   1.159 +    make-armv7)
   1.160 +        make_armv7="yes"
   1.161 +        ;;
   1.162 +    make-i386)
   1.163 +        make_i386="yes"
   1.164 +        ;;
   1.165 +    merge)
   1.166 +        merge="yes"
   1.167 +        ;;
   1.168 +    clean)
   1.169 +        clean_armv6="yes"
   1.170 +        clean_armv7="yes"
   1.171 +        clean_i386="yes"
   1.172 +        ;;
   1.173 +    clean-armv6)
   1.174 +        clean_armv6="yes"
   1.175 +        ;;
   1.176 +    clean-armv7)
   1.177 +        clean_armv7="yes"
   1.178 +        ;;
   1.179 +    clean-i386)
   1.180 +        clean_i386="yes"
   1.181 +        ;;
   1.182 +    *)
   1.183 +        echo "Usage: $0 [all|configure[-armv6|-armv7|-i386]|make[-armv6|-armv7|-i386]|merge|clean[-armv6|-armv7|-i386]]"
   1.184 +        exit 1
   1.185 +        ;;
   1.186 +esac
   1.187 +
   1.188 +#
   1.189 +# Create the build directories
   1.190 +#
   1.191 +for dir in build build/armv6 build/armv7 build/i386; do
   1.192 +    if test -d $dir; then
   1.193 +        :
   1.194 +    else
   1.195 +        mkdir $dir || exit 1
   1.196 +    fi
   1.197 +done
   1.198 +
   1.199 +#
   1.200 +# Build the armv6 binary
   1.201 +#
   1.202 +prepare_environment "armv6"
   1.203 +if test x$configure_armv6 = xyes; then
   1.204 +    (cd build/armv6 && \
   1.205 +     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
   1.206 +     # configure is not yet fully ready for iOS, some manual patching is required
   1.207 +     cp include/* build/armv6/include
   1.208 +     cp include/SDL_config_iphoneos.h build/armv6/include/SDL_config.h || exit 2
   1.209 +     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv6/Makefile || exit 2
   1.210 +     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv6/Makefile || exit 2
   1.211 +fi
   1.212 +if test x$make_armv6 = xyes; then
   1.213 +    (cd build/armv6 && make -j$NJOB) || exit 3
   1.214 +fi
   1.215 +#
   1.216 +# Build the armv7 binary
   1.217 +#
   1.218 +prepare_environment "armv7"
   1.219 +if test x$configure_armv7 = xyes; then
   1.220 +    (cd build/armv7 && \
   1.221 +     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
   1.222 +     # configure is not yet fully ready for iOS, some manual patching is required
   1.223 +     cp include/* build/armv7/include
   1.224 +     cp include/SDL_config_iphoneos.h build/armv7/include/SDL_config.h || exit 2
   1.225 +     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv7/Makefile || exit 2
   1.226 +     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv7/Makefile || exit 2
   1.227 +fi
   1.228 +if test x$make_armv7 = xyes; then
   1.229 +    (cd build/armv7 && make -j$NJOB) || exit 3
   1.230 +fi
   1.231 +#
   1.232 +# Build the i386 binary
   1.233 +#
   1.234 +prepare_environment "i386"
   1.235 +if test x$configure_i386 = xyes; then
   1.236 +    (cd build/i386 && \
   1.237 +     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
   1.238 +     # configure is not yet fully ready for iOS, some manual patching is required
   1.239 +     cp include/* build/i386/include
   1.240 +     cp include/SDL_config_iphoneos.h build/i386/include/SDL_config.h || exit 2
   1.241 +     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/i386/Makefile || exit 2
   1.242 +     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/i386/Makefile || exit 2
   1.243 +fi
   1.244 +if test x$make_i386 = xyes; then
   1.245 +    (cd build/i386 && make -j$NJOB) || exit 3
   1.246 +fi
   1.247 +
   1.248 +#
   1.249 +# Combine into fat binary
   1.250 +#
   1.251 +if test x$merge = xyes; then
   1.252 +    output=ios/lib
   1.253 +    sh $auxdir/mkinstalldirs build/$output
   1.254 +    cd build
   1.255 +    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
   1.256 +    (lipo -create -o $output/libSDL2.a */build/.libs/libSDL2.a &&
   1.257 +     lipo -create -o $output/libSDL2main.a */build/libSDL2main.a &&
   1.258 +     cp -r armv6/include ios
   1.259 +     echo "Build complete!" &&
   1.260 +     echo "Files can be found under the build/ios directory.") || exit 4
   1.261 +    cd ..
   1.262 +fi
   1.263 +
   1.264 +#
   1.265 +# Clean up
   1.266 +#
   1.267 +do_clean()
   1.268 +{
   1.269 +    echo $*
   1.270 +    $* || exit 6
   1.271 +}
   1.272 +if test x$clean_armv6 = xyes; then
   1.273 +    do_clean rm -r build/armv6
   1.274 +fi
   1.275 +if test x$clean_armv7 = xyes; then
   1.276 +    do_clean rm -r build/armv7
   1.277 +fi
   1.278 +if test x$clean_i386 = xyes; then
   1.279 +    do_clean rm -r build/i386
   1.280 +fi