gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Nov 2009 18:40:07 +0000
changeset 474 a2c238c0c4b2
parent 394 c7f780bb6a33
child 511 55a686ef0680
permissions -rwxr-xr-x
Don't break binary compatibility!
     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 ppc ppc64 x86 x64
     6 
     7 # PowerPC 32-bit compiler flags (10.4 runtime compatibility)
     8 GCC_COMPILE_PPC32="gcc-4.0 -arch ppc -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/powerpc-apple-darwin10/4.0.1/include \
    13 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    14 
    15 GCC_LINK_PPC32="\
    16 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1 \
    17 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    18 
    19 # PowerPC 64-bit compiler flags (10.5 runtime compatibility)
    20 GCC_COMPILE_PPC64="gcc-4.0 -arch ppc64 -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/powerpc-apple-darwin10/4.0.1/include \
    25 -isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
    26 
    27 GCC_LINK_PPC64="\
    28 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/ppc64 \
    29 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
    30 
    31 # Intel 32-bit compiler flags (10.4 runtime compatibility)
    32 GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
    33 -DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    34 -nostdinc \
    35 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    36 -I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
    37 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    38 
    39 GCC_LINK_X86="\
    40 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1 \
    41 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    42 
    43 # Intel 64-bit compiler flags (10.5 runtime compatibility)
    44 GCC_COMPILE_X64="gcc-4.0 -arch x86_64 -mmacosx-version-min=10.5 \
    45 -DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
    46 -nostdinc \
    47 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
    48 -I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
    49 -isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
    50 
    51 GCC_LINK_X64="\
    52 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
    53 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
    54 
    55 # Output both PowerPC and Intel object files
    56 args="$*"
    57 compile=yes
    58 link=yes
    59 while test x$1 != x; do
    60     case $1 in
    61         --version) exec gcc $1;;
    62         -v) exec gcc $1;;
    63         -V) exec gcc $1;;
    64         -print-prog-name=*) exec gcc $1;;
    65         -print-search-dirs) exec gcc $1;;
    66         -E) GCC_COMPILE_PPC32="$GCC_COMPILE_PPC32 -E"
    67             GCC_COMPILE_PPC64="$GCC_COMPILE_PPC64 -E"
    68             GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
    69             GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
    70             compile=no; link=no;;
    71         -c) link=no;;
    72         -o) output=$2;;
    73         *.c|*.cc|*.cpp|*.S) source=$1;;
    74     esac
    75     shift
    76 done
    77 if test x$link = xyes; then
    78     GCC_COMPILE_PPC32="$GCC_COMPILE_PPC32 $GCC_LINK_PPC32"
    79     GCC_COMPILE_PPC64="$GCC_COMPILE_PPC64 $GCC_LINK_PPC64"
    80     GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
    81     GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
    82 fi
    83 if test x"$output" = x; then
    84     if test x$link = xyes; then
    85         output=a.out
    86     elif test x$compile = xyes; then
    87         output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
    88     fi
    89 fi
    90 
    91 # Compile PPC 32-bit
    92 if test x"$output" != x; then
    93     dir=ppc/`dirname $output`
    94     if test -d $dir; then
    95         :
    96     else
    97         mkdir -p $dir
    98     fi
    99 fi
   100 set -- $args
   101 while test x$1 != x; do
   102     if test -f "ppc/$1" && test "$1" != "$output"; then
   103         ppc_args="$ppc_args ppc/$1"
   104     else
   105         ppc_args="$ppc_args $1"
   106     fi
   107     shift
   108 done
   109 $GCC_COMPILE_PPC32 $ppc_args || exit $?
   110 if test x"$output" != x; then
   111     cp $output ppc/$output
   112 fi
   113 
   114 # Compile PPC 64-bit
   115 if test x"$output" != x; then
   116     dir=ppc64/`dirname $output`
   117     if test -d $dir; then
   118         :
   119     else
   120         mkdir -p $dir
   121     fi
   122 fi
   123 set -- $args
   124 while test x$1 != x; do
   125     if test -f "ppc64/$1" && test "$1" != "$output"; then
   126         ppc64_args="$ppc64_args ppc64/$1"
   127     else
   128         ppc64_args="$ppc64_args $1"
   129     fi
   130     shift
   131 done
   132 $GCC_COMPILE_PPC64 $ppc64_args || exit $?
   133 if test x"$output" != x; then
   134     cp $output ppc64/$output
   135 fi
   136 
   137 # Compile X86 32-bit
   138 if test x"$output" != x; then
   139     dir=x86/`dirname $output`
   140     if test -d $dir; then
   141         :
   142     else
   143         mkdir -p $dir
   144     fi
   145 fi
   146 set -- $args
   147 while test x$1 != x; do
   148     if test -f "x86/$1" && test "$1" != "$output"; then
   149         x86_args="$x86_args x86/$1"
   150     else
   151         x86_args="$x86_args $1"
   152     fi
   153     shift
   154 done
   155 $GCC_COMPILE_X86 $x86_args || exit $?
   156 if test x"$output" != x; then
   157     cp $output x86/$output
   158 fi
   159 
   160 # Compile X86 32-bit
   161 if test x"$output" != x; then
   162     dir=x64/`dirname $output`
   163     if test -d $dir; then
   164         :
   165     else
   166         mkdir -p $dir
   167     fi
   168 fi
   169 set -- $args
   170 while test x$1 != x; do
   171     if test -f "x64/$1" && test "$1" != "$output"; then
   172         x64_args="$x64_args x64/$1"
   173     else
   174         x64_args="$x64_args $1"
   175     fi
   176     shift
   177 done
   178 $GCC_COMPILE_X64 $x64_args || exit $?
   179 if test x"$output" != x; then
   180     cp $output x64/$output
   181 fi
   182 
   183 if test x"$output" != x; then
   184     lipo -create -o $output ppc/$output ppc64/$output x86/$output x64/$output
   185 fi