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