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