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 x86 6 7 # PowerPC compiler flags (10.2 runtime compatibility) 8 GCC_COMPILE_PPC="gcc-3.3 -arch ppc \ 9 -DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \ 10 -nostdinc \ 11 -F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \ 12 -I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \ 13 -isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include" 14 15 GCC_LINK_PPC="\ 16 -L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \ 17 -F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \ 18 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk" 19 20 # Intel compiler flags (10.4 runtime compatibility) 21 GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \ 22 -DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \ 23 -nostdinc \ 24 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \ 25 -I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \ 26 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include" 27 28 GCC_LINK_X86="\ 29 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \ 30 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk" 31 32 # Output both PowerPC and Intel object files 33 args="$*" 34 compile=yes 35 link=yes 36 while test x$1 != x; do 37 case $1 in 38 --version) exec gcc $1;; 39 -v) exec gcc $1;; 40 -V) exec gcc $1;; 41 -print-prog-name=*) exec gcc $1;; 42 -print-search-dirs) exec gcc $1;; 43 -E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E" 44 GCC_COMPILE_X86="$GCC_COMPILE_X86 -E" 45 compile=no; link=no;; 46 -c) link=no;; 47 -o) output=$2;; 48 *.c|*.cc|*.cpp|*.S) source=$1;; 49 esac 50 shift 51 done 52 if test x$link = xyes; then 53 GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC" 54 GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86" 55 fi 56 if test x"$output" = x; then 57 if test x$link = xyes; then 58 output=a.out 59 elif test x$compile = xyes; then 60 output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o 61 fi 62 fi 63 64 if test x"$output" != x; then 65 dir=ppc/`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 "ppc/$1" && test "$1" != "$output"; then 75 ppc_args="$ppc_args ppc/$1" 76 else 77 ppc_args="$ppc_args $1" 78 fi 79 shift 80 done 81 $GCC_COMPILE_PPC $ppc_args || exit $? 82 if test x"$output" != x; then 83 cp $output ppc/$output 84 fi 85 86 if test x"$output" != x; then 87 dir=x86/`dirname $output` 88 if test -d $dir; then 89 : 90 else 91 mkdir -p $dir 92 fi 93 fi 94 set -- $args 95 while test x$1 != x; do 96 if test -f "x86/$1" && test "$1" != "$output"; then 97 x86_args="$x86_args x86/$1" 98 else 99 x86_args="$x86_args $1" 100 fi 101 shift 102 done 103 $GCC_COMPILE_X86 $x86_args || exit $? 104 if test x"$output" != x; then 105 cp $output x86/$output 106 fi 107 108 if test x"$output" != x; then 109 lipo -create -o $output ppc/$output x86/$output 110 fi 111