Toggling cross-compilation

August 2, 2007

Here’s a tidbit I’ve found to be quite useful. Many source distribution will compile fine for both i386 and PPC Macs. For those that don’t, I keep this function in my .bash_profile:

ub () {
  echo -n "Cross-compiling "
  if [ $1 = "on" ]
  then
    export LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386"
    export CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
    echo enabled
  else
    unset LDFLAGS CFLAGS
    echo disabled       
  fi
}