gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Fri, 15 Feb 2013 14:47:06 -0800
changeset 347 ad5034cad524
parent 274 f9ae0edd7bfa
child 382 0940479cefdb
permissions -rwxr-xr-x
Updated copyright year
slouken@131
     1
#!/bin/sh
slouken@131
     2
#
slouken@131
     3
# Build Universal binaries on Mac OS X, thanks Ryan!
slouken@131
     4
#
slouken@274
     5
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf x86 x64
slouken@198
     6
slouken@198
     7
# Intel 32-bit compiler flags (10.4 runtime compatibility)
slouken@131
     8
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
slouken@131
     9
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@131
    10
-nostdinc \
slouken@131
    11
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@198
    12
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
slouken@131
    13
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
slouken@131
    14
slouken@131
    15
GCC_LINK_X86="\
slouken@198
    16
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1 \
slouken@131
    17
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
slouken@131
    18
slouken@198
    19
# Intel 64-bit compiler flags (10.5 runtime compatibility)
slouken@198
    20
GCC_COMPILE_X64="gcc-4.0 -arch x86_64 -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/i686-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_X64="\
slouken@198
    28
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
slouken@198
    29
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
slouken@198
    30
slouken@131
    31
# Output both PowerPC and Intel object files
slouken@131
    32
args="$*"
slouken@131
    33
compile=yes
slouken@131
    34
link=yes
slouken@131
    35
while test x$1 != x; do
slouken@131
    36
    case $1 in
slouken@131
    37
        --version) exec gcc $1;;
slouken@131
    38
        -v) exec gcc $1;;
slouken@131
    39
        -V) exec gcc $1;;
slouken@131
    40
        -print-prog-name=*) exec gcc $1;;
slouken@131
    41
        -print-search-dirs) exec gcc $1;;
slouken@274
    42
        -E) GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
slouken@198
    43
            GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
slouken@131
    44
            compile=no; link=no;;
slouken@131
    45
        -c) link=no;;
slouken@131
    46
        -o) output=$2;;
slouken@134
    47
        *.c|*.cc|*.cpp|*.S) source=$1;;
slouken@131
    48
    esac
slouken@131
    49
    shift
slouken@131
    50
done
slouken@131
    51
if test x$link = xyes; then
slouken@131
    52
    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
slouken@198
    53
    GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
slouken@131
    54
fi
slouken@131
    55
if test x"$output" = x; then
slouken@131
    56
    if test x$link = xyes; then
slouken@131
    57
        output=a.out
slouken@131
    58
    elif test x$compile = xyes; then
slouken@134
    59
        output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
slouken@131
    60
    fi
slouken@131
    61
fi
slouken@131
    62
slouken@198
    63
# Compile X86 32-bit
slouken@131
    64
if test x"$output" != x; then
slouken@131
    65
    dir=x86/`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 "x86/$1" && test "$1" != "$output"; then
slouken@131
    75
        x86_args="$x86_args x86/$1"
slouken@131
    76
    else
slouken@131
    77
        x86_args="$x86_args $1"
slouken@131
    78
    fi
slouken@131
    79
    shift
slouken@131
    80
done
slouken@131
    81
$GCC_COMPILE_X86 $x86_args || exit $?
slouken@131
    82
if test x"$output" != x; then
slouken@131
    83
    cp $output x86/$output
slouken@131
    84
fi
slouken@131
    85
slouken@198
    86
# Compile X86 32-bit
slouken@131
    87
if test x"$output" != x; then
slouken@198
    88
    dir=x64/`dirname $output`
slouken@198
    89
    if test -d $dir; then
slouken@198
    90
        :
slouken@198
    91
    else
slouken@198
    92
        mkdir -p $dir
slouken@198
    93
    fi
slouken@131
    94
fi
slouken@198
    95
set -- $args
slouken@198
    96
while test x$1 != x; do
slouken@198
    97
    if test -f "x64/$1" && test "$1" != "$output"; then
slouken@198
    98
        x64_args="$x64_args x64/$1"
slouken@198
    99
    else
slouken@198
   100
        x64_args="$x64_args $1"
slouken@198
   101
    fi
slouken@198
   102
    shift
slouken@198
   103
done
slouken@198
   104
$GCC_COMPILE_X64 $x64_args || exit $?
slouken@198
   105
if test x"$output" != x; then
slouken@198
   106
    cp $output x64/$output
slouken@198
   107
fi
slouken@198
   108
slouken@198
   109
if test x"$output" != x; then
slouken@274
   110
    lipo -create -o $output x86/$output x64/$output
slouken@198
   111
fi