gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 30 Apr 2006 20:29:21 +0000
changeset 132 1cfe0957a376
parent 131 df3a2df8ccc0
child 134 a3c5787089b0
permissions -rwxr-xr-x
(none)
slouken@131
     1
#!/bin/sh
slouken@131
     2
#
slouken@131
     3
# Build Universal binaries on Mac OS X, thanks Ryan!
slouken@131
     4
#
slouken@131
     5
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
slouken@131
     6
slouken@131
     7
# PowerPC compiler flags (10.2 runtime compatibility)
slouken@131
     8
GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
slouken@131
     9
-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
slouken@131
    10
-nostdinc \
slouken@131
    11
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
slouken@131
    12
-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
slouken@131
    13
-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
slouken@131
    14
slouken@131
    15
GCC_LINK_PPC="\
slouken@131
    16
-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
slouken@131
    17
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
slouken@131
    18
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
slouken@131
    19
slouken@131
    20
# Intel compiler flags (10.4 runtime compatibility)
slouken@131
    21
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
slouken@131
    22
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@131
    23
-nostdinc \
slouken@131
    24
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@131
    25
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
slouken@131
    26
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
slouken@131
    27
slouken@131
    28
GCC_LINK_X86="\
slouken@131
    29
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
slouken@131
    30
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
slouken@131
    31
slouken@131
    32
# Output both PowerPC and Intel object files
slouken@131
    33
args="$*"
slouken@131
    34
compile=yes
slouken@131
    35
link=yes
slouken@131
    36
while test x$1 != x; do
slouken@131
    37
    case $1 in
slouken@131
    38
        --version) exec gcc $1;;
slouken@131
    39
        -v) exec gcc $1;;
slouken@131
    40
        -V) exec gcc $1;;
slouken@131
    41
        -print-prog-name=*) exec gcc $1;;
slouken@131
    42
        -print-search-dirs) exec gcc $1;;
slouken@131
    43
        -E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
slouken@131
    44
            GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
slouken@131
    45
            compile=no; link=no;;
slouken@131
    46
        -c) link=no;;
slouken@131
    47
        -o) output=$2;;
slouken@131
    48
        *.c) source=$1;;
slouken@131
    49
    esac
slouken@131
    50
    shift
slouken@131
    51
done
slouken@131
    52
if test x$link = xyes; then
slouken@131
    53
    GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
slouken@131
    54
    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
slouken@131
    55
fi
slouken@131
    56
if test x"$output" = x; then
slouken@131
    57
    if test x$link = xyes; then
slouken@131
    58
        output=a.out
slouken@131
    59
    elif test x$compile = xyes; then
slouken@131
    60
        output=`basename $source .c`.o
slouken@131
    61
    fi
slouken@131
    62
fi
slouken@131
    63
slouken@131
    64
if test x"$output" != x; then
slouken@131
    65
    dir=ppc/`dirname $output`
slouken@131
    66
    if test -d $dir; then
slouken@131
    67
        :
slouken@131
    68
    else
slouken@131
    69
        mkdir -p $dir
slouken@131
    70
    fi
slouken@131
    71
fi
slouken@131
    72
set -- $args
slouken@131
    73
while test x$1 != x; do
slouken@132
    74
    if test -f "ppc/$1" && test "$1" != "$output"; then
slouken@131
    75
        ppc_args="$ppc_args ppc/$1"
slouken@131
    76
    else
slouken@131
    77
        ppc_args="$ppc_args $1"
slouken@131
    78
    fi
slouken@131
    79
    shift
slouken@131
    80
done
slouken@131
    81
$GCC_COMPILE_PPC $ppc_args || exit $?
slouken@131
    82
if test x"$output" != x; then
slouken@131
    83
    cp $output ppc/$output
slouken@131
    84
fi
slouken@131
    85
slouken@131
    86
if test x"$output" != x; then
slouken@131
    87
    dir=x86/`dirname $output`
slouken@131
    88
    if test -d $dir; then
slouken@131
    89
        :
slouken@131
    90
    else
slouken@131
    91
        mkdir -p $dir
slouken@131
    92
    fi
slouken@131
    93
fi
slouken@131
    94
set -- $args
slouken@131
    95
while test x$1 != x; do
slouken@132
    96
    if test -f "x86/$1" && test "$1" != "$output"; then
slouken@131
    97
        x86_args="$x86_args x86/$1"
slouken@131
    98
    else
slouken@131
    99
        x86_args="$x86_args $1"
slouken@131
   100
    fi
slouken@131
   101
    shift
slouken@131
   102
done
slouken@131
   103
$GCC_COMPILE_X86 $x86_args || exit $?
slouken@131
   104
if test x"$output" != x; then
slouken@131
   105
    cp $output x86/$output
slouken@131
   106
fi
slouken@131
   107
slouken@131
   108
if test x"$output" != x; then
slouken@131
   109
    lipo -create -o $output ppc/$output x86/$output
slouken@131
   110
fi