gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Wed, 07 Nov 2018 07:47:50 -0800
changeset 924 9be60a9582a6
parent 623 5a86e7d5107f
permissions -rwxr-xr-x
The Debian maintainers aren't using these rules, so enable dynamic loading of shared libraries by default for the Steam Linux Runtime
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@623
     7
DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer"
slouken@623
     8
slouken@623
     9
# Intel 32-bit compiler flags (10.6 runtime compatibility)
slouken@623
    10
GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.6 \
slouken@295
    11
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@623
    12
-I/usr/local/include"
slouken@295
    13
slouken@623
    14
GCC_LINK_X86="-mmacosx-version-min=10.6"
slouken@295
    15
slouken@623
    16
# Intel 64-bit compiler flags (10.6 runtime compatibility)
slouken@623
    17
GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \
slouken@393
    18
-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
slouken@623
    19
-I/usr/local/include"
slouken@393
    20
slouken@623
    21
GCC_LINK_X64="-mmacosx-version-min=10.6"
slouken@393
    22
slouken@295
    23
# Output both PowerPC and Intel object files
slouken@295
    24
args="$*"
slouken@295
    25
compile=yes
slouken@295
    26
link=yes
slouken@295
    27
while test x$1 != x; do
slouken@295
    28
    case $1 in
slouken@295
    29
        --version) exec gcc $1;;
slouken@295
    30
        -v) exec gcc $1;;
slouken@295
    31
        -V) exec gcc $1;;
slouken@295
    32
        -print-prog-name=*) exec gcc $1;;
slouken@295
    33
        -print-search-dirs) exec gcc $1;;
slouken@511
    34
        -E) GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
slouken@393
    35
            GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
slouken@295
    36
            compile=no; link=no;;
slouken@295
    37
        -c) link=no;;
slouken@295
    38
        -o) output=$2;;
slouken@299
    39
        *.c|*.cc|*.cpp|*.S) source=$1;;
slouken@295
    40
    esac
slouken@295
    41
    shift
slouken@295
    42
done
slouken@295
    43
if test x$link = xyes; then
slouken@295
    44
    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
slouken@393
    45
    GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
slouken@295
    46
fi
slouken@295
    47
if test x"$output" = x; then
slouken@295
    48
    if test x$link = xyes; then
slouken@295
    49
        output=a.out
slouken@295
    50
    elif test x$compile = xyes; then
slouken@299
    51
        output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
slouken@295
    52
    fi
slouken@295
    53
fi
slouken@295
    54
slouken@393
    55
# Compile X86 32-bit
slouken@295
    56
if test x"$output" != x; then
slouken@295
    57
    dir=x86/`dirname $output`
slouken@295
    58
    if test -d $dir; then
slouken@295
    59
        :
slouken@295
    60
    else
slouken@295
    61
        mkdir -p $dir
slouken@295
    62
    fi
slouken@295
    63
fi
slouken@295
    64
set -- $args
slouken@295
    65
while test x$1 != x; do
slouken@295
    66
    if test -f "x86/$1" && test "$1" != "$output"; then
slouken@295
    67
        x86_args="$x86_args x86/$1"
slouken@295
    68
    else
slouken@295
    69
        x86_args="$x86_args $1"
slouken@295
    70
    fi
slouken@295
    71
    shift
slouken@295
    72
done
slouken@295
    73
$GCC_COMPILE_X86 $x86_args || exit $?
slouken@295
    74
if test x"$output" != x; then
slouken@295
    75
    cp $output x86/$output
slouken@295
    76
fi
slouken@295
    77
slouken@393
    78
# Compile X86 32-bit
slouken@295
    79
if test x"$output" != x; then
slouken@393
    80
    dir=x64/`dirname $output`
slouken@393
    81
    if test -d $dir; then
slouken@393
    82
        :
slouken@393
    83
    else
slouken@393
    84
        mkdir -p $dir
slouken@393
    85
    fi
slouken@295
    86
fi
slouken@393
    87
set -- $args
slouken@393
    88
while test x$1 != x; do
slouken@393
    89
    if test -f "x64/$1" && test "$1" != "$output"; then
slouken@393
    90
        x64_args="$x64_args x64/$1"
slouken@393
    91
    else
slouken@393
    92
        x64_args="$x64_args $1"
slouken@393
    93
    fi
slouken@393
    94
    shift
slouken@393
    95
done
slouken@393
    96
$GCC_COMPILE_X64 $x64_args || exit $?
slouken@393
    97
if test x"$output" != x; then
slouken@393
    98
    cp $output x64/$output
slouken@393
    99
fi
slouken@393
   100
slouken@393
   101
if test x"$output" != x; then
slouken@511
   102
    lipo -create -o $output x86/$output x64/$output
slouken@393
   103
fi