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