cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

iosbuild.sh (7935B)


      1#!/bin/sh
      2#
      3# Build a fat binary for iOS
      4# Based on fatbuild.sh and code from the Ignifuga Game Engine
      5
      6# Number of CPUs (for make -j)
      7NCPU=`sysctl -n hw.ncpu`
      8if test x$NJOB = x; then
      9    NJOB=$NCPU
     10fi
     11
     12# SDK path
     13XCODE_PATH=`xcode-select --print-path`
     14if [ -z "$XCODE_PATH" ]; then
     15    echo "Could not find XCode location (use xcode-select -switch to set the correct path)"
     16    exit 1
     17fi
     18
     19prepare_environment() {
     20    ARCH=$1
     21    
     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"
     26          exit 1
     27      fi  
     28    fi
     29    
     30    case $ARCH in
     31        armv6)
     32            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
     33            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
     34            ;;
     35        armv7)
     36            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
     37            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
     38            ;;
     39        i386)
     40            DEV_PATH="$XCODE_PATH/Platforms/iPhoneSimulator.platform/Developer"
     41            SDK_PATH="$DEV_PATH/SDKs/iPhoneSimulator$SDK_VERSION.sdk"
     42            ;;
     43        *)
     44            echo "Unknown Architecture $ARCH"
     45            exit 1
     46            ;;
     47    esac
     48
     49    if [ ! -d "$SDK_PATH" ]; then
     50        echo "Could not find iOS SDK at $SDK_PATH"
     51        exit 1
     52    fi
     53
     54    if test x$MIN_OS_VERSION = x; then
     55        export MIN_OS_VERSION="3.0"
     56    fi
     57    
     58    # Environment flags
     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"
     65    export CPP="$CXXCPP"
     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"
     74    
     75    # We dynamically load X11, so using the system X11 headers is fine.
     76    CONFIG_FLAGS="--disable-shared --enable-static"
     77    
     78    case $ARCH in
     79        armv6)
     80            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv6-apple-darwin"
     81            export CFLAGS="$CFLAGS -arch armv6"
     82            export LDFLAGS="$LDFLAGS -arch armv6"
     83            ;;
     84        armv7)
     85            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv7-apple-darwin"
     86            export CFLAGS="$CFLAGS -arch armv7"
     87            export LDFLAGS="$LDFLAGS -arch armv7"
     88            ;;
     89        i386)
     90            export CONFIG_FLAGS="$CONFIG_FLAGS --host=i386-apple-darwin"
     91            export CFLAGS="$CFLAGS -arch i386"
     92            export LDFLAGS="$LDFLAGS -arch i386"
     93            ;;
     94        *)
     95            echo "Unknown Architecture $ARCH"
     96            exit 1
     97            ;;
     98    esac
     99}
    100
    101prepare_environment "armv6"
    102echo "Building with iOS SDK v$SDK_VERSION for iOS >= $MIN_OS_VERSION"
    103
    104#
    105# Find the configure script
    106#
    107srcdir=`dirname $0`/..
    108srcdir=`cd $srcdir && pwd`
    109auxdir=$srcdir/build-scripts
    110cd $srcdir
    111
    112#
    113# Figure out which phase to build:
    114# all,
    115# configure, configure-armv6, configure-armv7, configure-i386
    116# make, make-armv6, make-armv7, make-i386, merge
    117# clean
    118if test x"$1" = x; then
    119    phase=all
    120else
    121    phase="$1"
    122fi
    123case $phase in
    124    all)
    125        configure_armv6="yes"
    126        configure_armv7="yes"
    127        configure_i386="yes"
    128        make_armv6="yes"
    129        make_armv7="yes"
    130        make_i386="yes"
    131        merge="yes"
    132        ;;
    133    configure)
    134        configure_armv6="yes"
    135        configure_armv7="yes"
    136        configure_i386="yes"
    137        ;;
    138    configure-armv6)
    139        configure_armv6="yes"
    140        ;;
    141    configure-armv7)
    142        configure_armv7="yes"
    143        ;;
    144    configure-i386)
    145        configure_i386="yes"
    146        ;;
    147    make)
    148        make_armv6="yes"
    149        make_armv7="yes"
    150        make_i386="yes"
    151        merge="yes"
    152        ;;
    153    make-armv6)
    154        make_armv6="yes"
    155        ;;
    156    make-armv7)
    157        make_armv7="yes"
    158        ;;
    159    make-i386)
    160        make_i386="yes"
    161        ;;
    162    merge)
    163        merge="yes"
    164        ;;
    165    clean)
    166        clean_armv6="yes"
    167        clean_armv7="yes"
    168        clean_i386="yes"
    169        ;;
    170    clean-armv6)
    171        clean_armv6="yes"
    172        ;;
    173    clean-armv7)
    174        clean_armv7="yes"
    175        ;;
    176    clean-i386)
    177        clean_i386="yes"
    178        ;;
    179    *)
    180        echo "Usage: $0 [all|configure[-armv6|-armv7|-i386]|make[-armv6|-armv7|-i386]|merge|clean[-armv6|-armv7|-i386]]"
    181        exit 1
    182        ;;
    183esac
    184
    185#
    186# Create the build directories
    187#
    188for dir in build build/armv6 build/armv7 build/i386; do
    189    if test -d $dir; then
    190        :
    191    else
    192        mkdir $dir || exit 1
    193    fi
    194done
    195
    196#
    197# Build the armv6 binary
    198#
    199prepare_environment "armv6"
    200if test x$configure_armv6 = xyes; then
    201    (cd build/armv6 && \
    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
    208fi
    209if test x$make_armv6 = xyes; then
    210    (cd build/armv6 && make -j$NJOB) || exit 3
    211fi
    212#
    213# Build the armv7 binary
    214#
    215prepare_environment "armv7"
    216if test x$configure_armv7 = xyes; then
    217    (cd build/armv7 && \
    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
    224fi
    225if test x$make_armv7 = xyes; then
    226    (cd build/armv7 && make -j$NJOB) || exit 3
    227fi
    228#
    229# Build the i386 binary
    230#
    231prepare_environment "i386"
    232if test x$configure_i386 = xyes; then
    233    (cd build/i386 && \
    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
    240fi
    241if test x$make_i386 = xyes; then
    242    (cd build/i386 && make -j$NJOB) || exit 3
    243fi
    244
    245#
    246# Combine into fat binary
    247#
    248if test x$merge = xyes; then
    249    output=ios/lib
    250    sh $auxdir/mkinstalldirs build/$output
    251    cd build
    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
    258    cd ..
    259fi
    260
    261#
    262# Clean up
    263#
    264do_clean()
    265{
    266    echo $*
    267    $* || exit 6
    268}
    269if test x$clean_armv6 = xyes; then
    270    do_clean rm -r build/armv6
    271fi
    272if test x$clean_armv7 = xyes; then
    273    do_clean rm -r build/armv7
    274fi
    275if test x$clean_i386 = xyes; then
    276    do_clean rm -r build/i386
    277fi