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