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