build-scripts/gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Tue, 30 Jul 2013 00:02:45 -0700
changeset 7547 abdea1385dbb
parent 7507 885b4aab4190
child 9221 0702f9d6e2b1
permissions -rwxr-xr-x
Fixed compiler warning with gcc
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
7507
885b4aab4190 Mac: Codify SDK and OS requirements, and clean up.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7255
diff changeset
     9
# Intel 32-bit compiler flags (10.5 runtime compatibility)
885b4aab4190 Mac: Codify SDK and OS requirements, and clean up.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7255
diff changeset
    10
GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.5 \
7255
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
-I/usr/local/include"
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
7507
885b4aab4190 Mac: Codify SDK and OS requirements, and clean up.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7255
diff changeset
    13
GCC_LINK_X86="-mmacosx-version-min=10.5"
7255
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
# 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
    16
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
    17
-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
    18
-I/usr/local/include"
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
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
    21
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
# 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
    23
args="$*"
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
compile=yes
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
link=yes
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
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
    27
    case $1 in
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
        --version) exec gcc $1;;
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
        -v) 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
        -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
    32
        -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
    33
        -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
    34
            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
    35
            compile=no; link=no;;
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
        -c) link=no;;
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
        -o) output=$2;;
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
        *.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
    39
    esac
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
    shift
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
done
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
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
    43
    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
    44
    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
    45
fi
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
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
    47
    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
    48
        output=a.out
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
    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
    50
        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
    51
    fi
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
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
# Compile X86 32-bit
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
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
    56
    dir=x86/`dirname $output`
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    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
    58
        :
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
    else
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
        mkdir -p $dir
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
    fi
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
set -- $args
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
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
    65
    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
    66
        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
    67
    else
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
        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
    69
    fi
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    shift
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
done
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
$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
    73
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
    74
    cp $output x86/$output
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
fi
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
# Compile X86 32-bit
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
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
    79
    dir=x64/`dirname $output`
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    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
    81
        :
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    else
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
        mkdir -p $dir
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    fi
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
set -- $args
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
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
    88
    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
    89
        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
    90
    else
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
        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
    92
    fi
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    shift
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
done
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
$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
    96
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
    97
    cp $output x64/$output
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
fi
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
ea30c1b99365 The standard fat gcc scripts work well with SDL 2.0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
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
   101
    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
   102
fi