build-scripts/iosbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 17 Aug 2014 14:57:52 -0700
changeset 9086 c5e33f9a0d03
parent 6334 85b8778a05c2
child 10904 4dbd025c4eb9
permissions -rwxr-xr-x
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different

Tim McDaniel

On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.

I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.

If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
gabomdq@6333
     1
#!/bin/sh
gabomdq@6333
     2
#
gabomdq@6333
     3
# Build a fat binary for iOS
gabomdq@6333
     4
# Based on fatbuild.sh and code from the Ignifuga Game Engine
gabomdq@6333
     5
gabomdq@6333
     6
# Number of CPUs (for make -j)
gabomdq@6333
     7
NCPU=`sysctl -n hw.ncpu`
gabomdq@6333
     8
if test x$NJOB = x; then
gabomdq@6333
     9
    NJOB=$NCPU
gabomdq@6333
    10
fi
gabomdq@6333
    11
gabomdq@6333
    12
# SDK path
gabomdq@6333
    13
XCODE_PATH=`xcode-select --print-path`
gabomdq@6333
    14
if [ -z "$XCODE_PATH" ]; then
gabomdq@6334
    15
    echo "Could not find XCode location (use xcode-select -switch to set the correct path)"
gabomdq@6333
    16
    exit 1
gabomdq@6333
    17
fi
gabomdq@6333
    18
gabomdq@6333
    19
prepare_environment() {
gabomdq@6333
    20
    ARCH=$1
gabomdq@6333
    21
    
gabomdq@6333
    22
    if test x$SDK_VERSION = x; then
gabomdq@6333
    23
      export SDK_VERSION=`xcodebuild -showsdks | grep iphoneos | sed "s|.*iphoneos||"`
gabomdq@6333
    24
      if [ -z "$XCODE_PATH" ]; then
gabomdq@6333
    25
          echo "Could not find a valid iOS SDK"
gabomdq@6333
    26
          exit 1
gabomdq@6333
    27
      fi  
gabomdq@6333
    28
    fi
gabomdq@6333
    29
    
gabomdq@6333
    30
    case $ARCH in
gabomdq@6333
    31
        armv6)
gabomdq@6333
    32
            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
gabomdq@6333
    33
            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
gabomdq@6333
    34
            ;;
gabomdq@6333
    35
        armv7)
gabomdq@6333
    36
            DEV_PATH="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer"
gabomdq@6333
    37
            SDK_PATH="$DEV_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk"
gabomdq@6333
    38
            ;;
gabomdq@6333
    39
        i386)
gabomdq@6333
    40
            DEV_PATH="$XCODE_PATH/Platforms/iPhoneSimulator.platform/Developer"
gabomdq@6333
    41
            SDK_PATH="$DEV_PATH/SDKs/iPhoneSimulator$SDK_VERSION.sdk"
gabomdq@6333
    42
            ;;
gabomdq@6333
    43
        *)
gabomdq@6333
    44
            echo "Unknown Architecture $ARCH"
gabomdq@6333
    45
            exit 1
gabomdq@6333
    46
            ;;
gabomdq@6333
    47
    esac
gabomdq@6333
    48
gabomdq@6333
    49
    if [ ! -d "$SDK_PATH" ]; then
gabomdq@6333
    50
        echo "Could not find iOS SDK at $SDK_PATH"
gabomdq@6333
    51
        exit 1
gabomdq@6333
    52
    fi
gabomdq@6333
    53
gabomdq@6333
    54
    if test x$MIN_OS_VERSION = x; then
gabomdq@6333
    55
        export MIN_OS_VERSION="3.0"
gabomdq@6333
    56
    fi
gabomdq@6333
    57
    
gabomdq@6333
    58
    # Environment flags
gabomdq@6333
    59
    CFLAGS="-g -O2 -pipe -no-cpp-precomp -isysroot $SDK_PATH \
gabomdq@6333
    60
            -miphoneos-version-min=$MIN_OS_VERSION -I$SDK_PATH/usr/include/"
gabomdq@6333
    61
    LDFLAGS="-L$SDK_PATH/usr/lib/ -isysroot $SDK_PATH \
gabomdq@6333
    62
             -miphoneos-version-min=$MIN_OS_VERSION -static-libgcc"
gabomdq@6333
    63
    export CXXFLAGS="$CFLAGS"
gabomdq@6333
    64
    export CXXCPP="$DEV_PATH/usr/bin/llvm-cpp-4.2"
gabomdq@6333
    65
    export CPP="$CXXCPP"
gabomdq@6333
    66
    export CXX="$DEV_PATH/usr/bin/llvm-g++-4.2"
gabomdq@6333
    67
    export CC="$DEV_PATH/usr/bin/llvm-gcc-4.2"
gabomdq@6333
    68
    export LD="$DEV_PATH/usr/bin/ld"
gabomdq@6333
    69
    export AR="$DEV_PATH/usr/bin/ar"
gabomdq@6333
    70
    export AS="$DEV_PATH/usr/bin/ls"
gabomdq@6333
    71
    export NM="$DEV_PATH/usr/bin/nm"
gabomdq@6333
    72
    export RANLIB="$DEV_PATH/usr/bin/ranlib"
gabomdq@6333
    73
    export STRIP="$DEV_PATH/usr/bin/strip"
gabomdq@6333
    74
    
gabomdq@6333
    75
    # We dynamically load X11, so using the system X11 headers is fine.
gabomdq@6333
    76
    CONFIG_FLAGS="--disable-shared --enable-static"
gabomdq@6333
    77
    
gabomdq@6333
    78
    case $ARCH in
gabomdq@6333
    79
        armv6)
gabomdq@6333
    80
            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv6-apple-darwin"
gabomdq@6333
    81
            export CFLAGS="$CFLAGS -arch armv6"
gabomdq@6333
    82
            export LDFLAGS="$LDFLAGS -arch armv6"
gabomdq@6333
    83
            ;;
gabomdq@6333
    84
        armv7)
gabomdq@6333
    85
            export CONFIG_FLAGS="$CONFIG_FLAGS --host=armv7-apple-darwin"
gabomdq@6333
    86
            export CFLAGS="$CFLAGS -arch armv7"
gabomdq@6333
    87
            export LDFLAGS="$LDFLAGS -arch armv7"
gabomdq@6333
    88
            ;;
gabomdq@6333
    89
        i386)
gabomdq@6333
    90
            export CONFIG_FLAGS="$CONFIG_FLAGS --host=i386-apple-darwin"
gabomdq@6333
    91
            export CFLAGS="$CFLAGS -arch i386"
gabomdq@6333
    92
            export LDFLAGS="$LDFLAGS -arch i386"
gabomdq@6333
    93
            ;;
gabomdq@6333
    94
        *)
gabomdq@6333
    95
            echo "Unknown Architecture $ARCH"
gabomdq@6333
    96
            exit 1
gabomdq@6333
    97
            ;;
gabomdq@6333
    98
    esac
gabomdq@6333
    99
}
gabomdq@6333
   100
gabomdq@6333
   101
prepare_environment "armv6"
gabomdq@6333
   102
echo "Building with iOS SDK v$SDK_VERSION for iOS >= $MIN_OS_VERSION"
gabomdq@6333
   103
gabomdq@6333
   104
#
gabomdq@6333
   105
# Find the configure script
gabomdq@6333
   106
#
gabomdq@6333
   107
srcdir=`dirname $0`/..
gabomdq@6333
   108
srcdir=`cd $srcdir && pwd`
gabomdq@6333
   109
auxdir=$srcdir/build-scripts
gabomdq@6333
   110
cd $srcdir
gabomdq@6333
   111
gabomdq@6333
   112
#
gabomdq@6333
   113
# Figure out which phase to build:
gabomdq@6333
   114
# all,
gabomdq@6333
   115
# configure, configure-armv6, configure-armv7, configure-i386
gabomdq@6333
   116
# make, make-armv6, make-armv7, make-i386, merge
gabomdq@6333
   117
# clean
gabomdq@6333
   118
if test x"$1" = x; then
gabomdq@6333
   119
    phase=all
gabomdq@6333
   120
else
gabomdq@6333
   121
    phase="$1"
gabomdq@6333
   122
fi
gabomdq@6333
   123
case $phase in
gabomdq@6333
   124
    all)
gabomdq@6333
   125
        configure_armv6="yes"
gabomdq@6333
   126
        configure_armv7="yes"
gabomdq@6333
   127
        configure_i386="yes"
gabomdq@6333
   128
        make_armv6="yes"
gabomdq@6333
   129
        make_armv7="yes"
gabomdq@6333
   130
        make_i386="yes"
gabomdq@6333
   131
        merge="yes"
gabomdq@6333
   132
        ;;
gabomdq@6333
   133
    configure)
gabomdq@6333
   134
        configure_armv6="yes"
gabomdq@6333
   135
        configure_armv7="yes"
gabomdq@6333
   136
        configure_i386="yes"
gabomdq@6333
   137
        ;;
gabomdq@6333
   138
    configure-armv6)
gabomdq@6333
   139
        configure_armv6="yes"
gabomdq@6333
   140
        ;;
gabomdq@6333
   141
    configure-armv7)
gabomdq@6333
   142
        configure_armv7="yes"
gabomdq@6333
   143
        ;;
gabomdq@6333
   144
    configure-i386)
gabomdq@6333
   145
        configure_i386="yes"
gabomdq@6333
   146
        ;;
gabomdq@6333
   147
    make)
gabomdq@6333
   148
        make_armv6="yes"
gabomdq@6333
   149
        make_armv7="yes"
gabomdq@6333
   150
        make_i386="yes"
gabomdq@6333
   151
        merge="yes"
gabomdq@6333
   152
        ;;
gabomdq@6333
   153
    make-armv6)
gabomdq@6333
   154
        make_armv6="yes"
gabomdq@6333
   155
        ;;
gabomdq@6333
   156
    make-armv7)
gabomdq@6333
   157
        make_armv7="yes"
gabomdq@6333
   158
        ;;
gabomdq@6333
   159
    make-i386)
gabomdq@6333
   160
        make_i386="yes"
gabomdq@6333
   161
        ;;
gabomdq@6333
   162
    merge)
gabomdq@6333
   163
        merge="yes"
gabomdq@6333
   164
        ;;
gabomdq@6333
   165
    clean)
gabomdq@6333
   166
        clean_armv6="yes"
gabomdq@6333
   167
        clean_armv7="yes"
gabomdq@6333
   168
        clean_i386="yes"
gabomdq@6333
   169
        ;;
gabomdq@6333
   170
    clean-armv6)
gabomdq@6333
   171
        clean_armv6="yes"
gabomdq@6333
   172
        ;;
gabomdq@6333
   173
    clean-armv7)
gabomdq@6333
   174
        clean_armv7="yes"
gabomdq@6333
   175
        ;;
gabomdq@6333
   176
    clean-i386)
gabomdq@6333
   177
        clean_i386="yes"
gabomdq@6333
   178
        ;;
gabomdq@6333
   179
    *)
gabomdq@6333
   180
        echo "Usage: $0 [all|configure[-armv6|-armv7|-i386]|make[-armv6|-armv7|-i386]|merge|clean[-armv6|-armv7|-i386]]"
gabomdq@6333
   181
        exit 1
gabomdq@6333
   182
        ;;
gabomdq@6333
   183
esac
gabomdq@6333
   184
gabomdq@6333
   185
#
gabomdq@6333
   186
# Create the build directories
gabomdq@6333
   187
#
gabomdq@6333
   188
for dir in build build/armv6 build/armv7 build/i386; do
gabomdq@6333
   189
    if test -d $dir; then
gabomdq@6333
   190
        :
gabomdq@6333
   191
    else
gabomdq@6333
   192
        mkdir $dir || exit 1
gabomdq@6333
   193
    fi
gabomdq@6333
   194
done
gabomdq@6333
   195
gabomdq@6333
   196
#
gabomdq@6333
   197
# Build the armv6 binary
gabomdq@6333
   198
#
gabomdq@6333
   199
prepare_environment "armv6"
gabomdq@6333
   200
if test x$configure_armv6 = xyes; then
gabomdq@6333
   201
    (cd build/armv6 && \
gabomdq@6333
   202
     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
gabomdq@6333
   203
     # configure is not yet fully ready for iOS, some manual patching is required
gabomdq@6333
   204
     cp include/* build/armv6/include
gabomdq@6333
   205
     cp include/SDL_config_iphoneos.h build/armv6/include/SDL_config.h || exit 2
gabomdq@6333
   206
     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv6/Makefile || exit 2
gabomdq@6333
   207
     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv6/Makefile || exit 2
gabomdq@6333
   208
fi
gabomdq@6333
   209
if test x$make_armv6 = xyes; then
gabomdq@6333
   210
    (cd build/armv6 && make -j$NJOB) || exit 3
gabomdq@6333
   211
fi
gabomdq@6333
   212
#
gabomdq@6333
   213
# Build the armv7 binary
gabomdq@6333
   214
#
gabomdq@6333
   215
prepare_environment "armv7"
gabomdq@6333
   216
if test x$configure_armv7 = xyes; then
gabomdq@6333
   217
    (cd build/armv7 && \
gabomdq@6333
   218
     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
gabomdq@6333
   219
     # configure is not yet fully ready for iOS, some manual patching is required
gabomdq@6333
   220
     cp include/* build/armv7/include
gabomdq@6333
   221
     cp include/SDL_config_iphoneos.h build/armv7/include/SDL_config.h || exit 2
gabomdq@6333
   222
     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/armv7/Makefile || exit 2
gabomdq@6333
   223
     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/armv7/Makefile || exit 2
gabomdq@6333
   224
fi
gabomdq@6333
   225
if test x$make_armv7 = xyes; then
gabomdq@6333
   226
    (cd build/armv7 && make -j$NJOB) || exit 3
gabomdq@6333
   227
fi
gabomdq@6333
   228
#
gabomdq@6333
   229
# Build the i386 binary
gabomdq@6333
   230
#
gabomdq@6333
   231
prepare_environment "i386"
gabomdq@6333
   232
if test x$configure_i386 = xyes; then
gabomdq@6333
   233
    (cd build/i386 && \
gabomdq@6333
   234
     sh ../../configure $CONFIG_FLAGS CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS") || exit 2
gabomdq@6333
   235
     # configure is not yet fully ready for iOS, some manual patching is required
gabomdq@6333
   236
     cp include/* build/i386/include
gabomdq@6333
   237
     cp include/SDL_config_iphoneos.h build/i386/include/SDL_config.h || exit 2
gabomdq@6333
   238
     sed -i "" -e "s|^EXTRA_CFLAGS.*|EXTRA_CFLAGS=-I./include|g" build/i386/Makefile || exit 2
gabomdq@6333
   239
     sed -i "" -e "s|^EXTRA_LDFLAGS.*|EXTRA_LDFLAGS=-lm|g" build/i386/Makefile || exit 2
gabomdq@6333
   240
fi
gabomdq@6333
   241
if test x$make_i386 = xyes; then
gabomdq@6333
   242
    (cd build/i386 && make -j$NJOB) || exit 3
gabomdq@6333
   243
fi
gabomdq@6333
   244
gabomdq@6333
   245
#
gabomdq@6333
   246
# Combine into fat binary
gabomdq@6333
   247
#
gabomdq@6333
   248
if test x$merge = xyes; then
gabomdq@6333
   249
    output=ios/lib
gabomdq@6333
   250
    sh $auxdir/mkinstalldirs build/$output
gabomdq@6333
   251
    cd build
gabomdq@6333
   252
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
gabomdq@6334
   253
    (lipo -create -o $output/libSDL2.a armv6/build/.libs/libSDL2.a armv7/build/.libs/libSDL2.a i386/build/.libs/libSDL2.a &&
gabomdq@6334
   254
     lipo -create -o $output/libSDL2main.a armv6/build/libSDL2main.a armv7/build/libSDL2main.a i386/build/libSDL2main.a &&
gabomdq@6333
   255
     cp -r armv6/include ios
gabomdq@6333
   256
     echo "Build complete!" &&
gabomdq@6333
   257
     echo "Files can be found under the build/ios directory.") || exit 4
gabomdq@6333
   258
    cd ..
gabomdq@6333
   259
fi
gabomdq@6333
   260
gabomdq@6333
   261
#
gabomdq@6333
   262
# Clean up
gabomdq@6333
   263
#
gabomdq@6333
   264
do_clean()
gabomdq@6333
   265
{
gabomdq@6333
   266
    echo $*
gabomdq@6333
   267
    $* || exit 6
gabomdq@6333
   268
}
gabomdq@6333
   269
if test x$clean_armv6 = xyes; then
gabomdq@6333
   270
    do_clean rm -r build/armv6
gabomdq@6333
   271
fi
gabomdq@6333
   272
if test x$clean_armv7 = xyes; then
gabomdq@6333
   273
    do_clean rm -r build/armv7
gabomdq@6333
   274
fi
gabomdq@6333
   275
if test x$clean_i386 = xyes; then
gabomdq@6333
   276
    do_clean rm -r build/i386
gabomdq@6333
   277
fi