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