gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 20 Sep 2009 03:57:46 +0000
changeset 198 5ae3ce21b31f
parent 153 ebab84a66b57
child 199 11f2745cb401
permissions -rwxr-xr-x
Updated gcc-fat.sh for Snow Leopard with both 32-bit and 64-bit architectures
slouken@131
     1
#!/bin/sh
slouken@131
     2
#
slouken@131
     3
# Build Universal binaries on Mac OS X, thanks Ryan!
slouken@131
     4
#
slouken@198
     5
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc ppc64 x86 x64
slouken@131
     6
slouken@198
     7
# PowerPC 32-bit compiler flags (10.4 runtime compatibility)
slouken@198
     8
GCC_COMPILE_PPC32="gcc-4.0 -arch ppc -mmacosx-version-min=10.4 \
slouken@198
     9
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@131
    10
-nostdinc \
slouken@198
    11
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@198
    12
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
slouken@198
    13
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
slouken@131
    14
slouken@198
    15
GCC_LINK_PPC32="\
slouken@198
    16
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1 \
slouken@198
    17
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
slouken@131
    18
slouken@198
    19
# PowerPC 64-bit compiler flags (10.5 runtime compatibility)
slouken@198
    20
GCC_COMPILE_PPC64="gcc-4.0 -arch ppc64 -mmacosx-version-min=10.5 \
slouken@198
    21
-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
slouken@198
    22
-nostdinc \
slouken@198
    23
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
slouken@198
    24
-I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
slouken@198
    25
-isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
slouken@198
    26
slouken@198
    27
GCC_LINK_PPC64="\
slouken@198
    28
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/ppc64 \
slouken@198
    29
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
slouken@198
    30
slouken@198
    31
# Intel 32-bit compiler flags (10.4 runtime compatibility)
slouken@131
    32
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
slouken@131
    33
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@131
    34
-nostdinc \
slouken@131
    35
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@198
    36
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
slouken@131
    37
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
slouken@131
    38
slouken@131
    39
GCC_LINK_X86="\
slouken@198
    40
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1 \
slouken@131
    41
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
slouken@131
    42
slouken@198
    43
# Intel 64-bit compiler flags (10.5 runtime compatibility)
slouken@198
    44
GCC_COMPILE_X64="gcc-4.0 -arch x86_64 -mmacosx-version-min=10.5 \
slouken@198
    45
-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
slouken@198
    46
-nostdinc \
slouken@198
    47
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
slouken@198
    48
-I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
slouken@198
    49
-isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
slouken@198
    50
slouken@198
    51
GCC_LINK_X64="\
slouken@198
    52
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
slouken@198
    53
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
slouken@198
    54
slouken@131
    55
# Output both PowerPC and Intel object files
slouken@131
    56
args="$*"
slouken@131
    57
compile=yes
slouken@131
    58
link=yes
slouken@131
    59
while test x$1 != x; do
slouken@131
    60
    case $1 in
slouken@131
    61
        --version) exec gcc $1;;
slouken@131
    62
        -v) exec gcc $1;;
slouken@131
    63
        -V) exec gcc $1;;
slouken@131
    64
        -print-prog-name=*) exec gcc $1;;
slouken@131
    65
        -print-search-dirs) exec gcc $1;;
slouken@131
    66
        -E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
slouken@198
    67
            GCC_COMPILE_PPC64="$GCC_COMPILE_PPC64 -E"
slouken@131
    68
            GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
slouken@198
    69
            GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
slouken@131
    70
            compile=no; link=no;;
slouken@131
    71
        -c) link=no;;
slouken@131
    72
        -o) output=$2;;
slouken@134
    73
        *.c|*.cc|*.cpp|*.S) source=$1;;
slouken@131
    74
    esac
slouken@131
    75
    shift
slouken@131
    76
done
slouken@131
    77
if test x$link = xyes; then
slouken@198
    78
    GCC_COMPILE_PPC32="$GCC_COMPILE_PPC32 $GCC_LINK_PPC32"
slouken@198
    79
    GCC_COMPILE_PPC64="$GCC_COMPILE_PPC64 $GCC_LINK_PPC64"
slouken@131
    80
    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
slouken@198
    81
    GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
slouken@131
    82
fi
slouken@131
    83
if test x"$output" = x; then
slouken@131
    84
    if test x$link = xyes; then
slouken@131
    85
        output=a.out
slouken@131
    86
    elif test x$compile = xyes; then
slouken@134
    87
        output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
slouken@131
    88
    fi
slouken@131
    89
fi
slouken@131
    90
slouken@198
    91
# Compile PPC 32-bit
slouken@131
    92
if test x"$output" != x; then
slouken@131
    93
    dir=ppc/`dirname $output`
slouken@131
    94
    if test -d $dir; then
slouken@131
    95
        :
slouken@131
    96
    else
slouken@131
    97
        mkdir -p $dir
slouken@131
    98
    fi
slouken@131
    99
fi
slouken@131
   100
set -- $args
slouken@131
   101
while test x$1 != x; do
slouken@132
   102
    if test -f "ppc/$1" && test "$1" != "$output"; then
slouken@131
   103
        ppc_args="$ppc_args ppc/$1"
slouken@131
   104
    else
slouken@131
   105
        ppc_args="$ppc_args $1"
slouken@131
   106
    fi
slouken@131
   107
    shift
slouken@131
   108
done
slouken@198
   109
$GCC_COMPILE_PPC32 $ppc_args || exit $?
slouken@131
   110
if test x"$output" != x; then
slouken@131
   111
    cp $output ppc/$output
slouken@131
   112
fi
slouken@131
   113
slouken@198
   114
# Compile PPC 64-bit
slouken@198
   115
if test x"$output" != x; then
slouken@198
   116
    dir=ppc64/`dirname $output`
slouken@198
   117
    if test -d $dir; then
slouken@198
   118
        :
slouken@198
   119
    else
slouken@198
   120
        mkdir -p $dir
slouken@198
   121
    fi
slouken@198
   122
fi
slouken@198
   123
set -- $args
slouken@198
   124
while test x$1 != x; do
slouken@198
   125
    if test -f "ppc64/$1" && test "$1" != "$output"; then
slouken@198
   126
        ppc64_args="$ppc64_args ppc64/$1"
slouken@198
   127
    else
slouken@198
   128
        ppc64_args="$ppc64_args $1"
slouken@198
   129
    fi
slouken@198
   130
    shift
slouken@198
   131
done
slouken@198
   132
$GCC_COMPILE_PPC64 $ppc64_args || exit $?
slouken@198
   133
if test x"$output" != x; then
slouken@198
   134
    cp $output ppc64/$output
slouken@198
   135
fi
slouken@198
   136
slouken@198
   137
# Compile X86 32-bit
slouken@131
   138
if test x"$output" != x; then
slouken@131
   139
    dir=x86/`dirname $output`
slouken@131
   140
    if test -d $dir; then
slouken@131
   141
        :
slouken@131
   142
    else
slouken@131
   143
        mkdir -p $dir
slouken@131
   144
    fi
slouken@131
   145
fi
slouken@131
   146
set -- $args
slouken@131
   147
while test x$1 != x; do
slouken@132
   148
    if test -f "x86/$1" && test "$1" != "$output"; then
slouken@131
   149
        x86_args="$x86_args x86/$1"
slouken@131
   150
    else
slouken@131
   151
        x86_args="$x86_args $1"
slouken@131
   152
    fi
slouken@131
   153
    shift
slouken@131
   154
done
slouken@131
   155
$GCC_COMPILE_X86 $x86_args || exit $?
slouken@131
   156
if test x"$output" != x; then
slouken@131
   157
    cp $output x86/$output
slouken@131
   158
fi
slouken@131
   159
slouken@198
   160
# Compile X86 32-bit
slouken@131
   161
if test x"$output" != x; then
slouken@198
   162
    dir=x64/`dirname $output`
slouken@198
   163
    if test -d $dir; then
slouken@198
   164
        :
slouken@198
   165
    else
slouken@198
   166
        mkdir -p $dir
slouken@198
   167
    fi
slouken@131
   168
fi
slouken@198
   169
set -- $args
slouken@198
   170
while test x$1 != x; do
slouken@198
   171
    if test -f "x64/$1" && test "$1" != "$output"; then
slouken@198
   172
        x64_args="$x64_args x64/$1"
slouken@198
   173
    else
slouken@198
   174
        x64_args="$x64_args $1"
slouken@198
   175
    fi
slouken@198
   176
    shift
slouken@198
   177
done
slouken@198
   178
$GCC_COMPILE_X64 $x64_args || exit $?
slouken@198
   179
if test x"$output" != x; then
slouken@198
   180
    cp $output x64/$output
slouken@198
   181
fi
slouken@198
   182
slouken@198
   183
if test x"$output" != x; then
slouken@198
   184
    lipo -create -o $output ppc/$output ppc64/$output x86/$output x64/$output
slouken@198
   185
fi