build-scripts/gcc-fat.sh
author Cameron Gutman <aicommander@gmail.com>
Sun, 28 Apr 2019 17:37:49 -0700
changeset 12746 132a2af7edac
parent 10182 4980c48b8dbe
permissions -rwxr-xr-x
Fix use-after-free when pumping the event loop after SDL_DestroyWindow()

Closing the window is asynchronous, but we free the window data immediately,
so we can get an updateLayer callback before the window is really destroyed which
will cause us to access the freed memory.

Clearing the content view will cause it to be immediately released, so no further
updateLayer callbacks will occur.
     1 #!/bin/sh
     2 #
     3 # Build Universal binaries on Mac OS X, thanks Ryan!
     4 #
     5 # Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf x86 x64
     6 
     7 DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer"
     8 
     9 # Intel 32-bit compiler flags (10.6 runtime compatibility)
    10 GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.6 \
    11 -I/usr/local/include"
    12 
    13 GCC_LINK_X86="-mmacosx-version-min=10.6"
    14 
    15 # Intel 64-bit compiler flags (10.6 runtime compatibility)
    16 GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \
    17 -DMAC_OS_X_VERSION_MIN_REQUIRED=1060 \
    18 -I/usr/local/include"
    19 
    20 GCC_LINK_X64="-mmacosx-version-min=10.6"
    21 
    22 # Output both PowerPC and Intel object files
    23 args="$*"
    24 compile=yes
    25 link=yes
    26 while test x$1 != x; do
    27     case $1 in
    28         --version) exec gcc $1;;
    29         -v) exec gcc $1;;
    30         -V) exec gcc $1;;
    31         -print-prog-name=*) exec gcc $1;;
    32         -print-search-dirs) exec gcc $1;;
    33         -E) GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
    34             GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
    35             compile=no; link=no;;
    36         -c) link=no;;
    37         -o) output=$2;;
    38         *.c|*.cc|*.cpp|*.S|*.m|*.mm) source=$1;;
    39     esac
    40     shift
    41 done
    42 if test x$link = xyes; then
    43     GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
    44     GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
    45 fi
    46 if test x"$output" = x; then
    47     if test x$link = xyes; then
    48         output=a.out
    49     elif test x$compile = xyes; then
    50         output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
    51     fi
    52 fi
    53 
    54 # Compile X86 32-bit
    55 if test x"$output" != x; then
    56     dir=x86/`dirname $output`
    57     if test -d $dir; then
    58         :
    59     else
    60         mkdir -p $dir
    61     fi
    62 fi
    63 set -- $args
    64 while test x$1 != x; do
    65     if test -f "x86/$1" && test "$1" != "$output"; then
    66         x86_args="$x86_args x86/$1"
    67     else
    68         x86_args="$x86_args $1"
    69     fi
    70     shift
    71 done
    72 $GCC_COMPILE_X86 $x86_args || exit $?
    73 if test x"$output" != x; then
    74     cp $output x86/$output
    75 fi
    76 
    77 # Compile X86 32-bit
    78 if test x"$output" != x; then
    79     dir=x64/`dirname $output`
    80     if test -d $dir; then
    81         :
    82     else
    83         mkdir -p $dir
    84     fi
    85 fi
    86 set -- $args
    87 while test x$1 != x; do
    88     if test -f "x64/$1" && test "$1" != "$output"; then
    89         x64_args="$x64_args x64/$1"
    90     else
    91         x64_args="$x64_args $1"
    92     fi
    93     shift
    94 done
    95 $GCC_COMPILE_X64 $x64_args || exit $?
    96 if test x"$output" != x; then
    97     cp $output x64/$output
    98 fi
    99 
   100 if test x"$output" != x; then
   101     lipo -create -o $output x86/$output x64/$output
   102 fi