diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -641,9 +641,9 @@
 LIBOBJS
 llvm_ldflags
 llvm_includedir
+llvm_target
 llvm_all_libs
 llvm_cppflags
-llvm_target
 EGREP
 GREP
 CPP
@@ -1322,6 +1322,9 @@
 _ACEOF
 
   cat <<\_ACEOF
+
+System types:
+  --target=TARGET   configure for building compilers for TARGET [guessed]
 _ACEOF
 fi
 
@@ -2496,14 +2499,40 @@
 
 
 
+
+
+if test "$target" = ""
+then
+    if test "${compiler}" != ""
+    then
+        target=`${compiler} +RTS --info | grep '^ ,("Target platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
+        echo "Target platform inferred as: $target"
+    else
+        echo "Can't work out target platform"
+        exit 1
+    fi
+fi
+
+case $target in
+i386-apple-darwin)
+    TARGET_CPPFLAGS="-m32"
+    TAGRET_LDFLAGS="-m32"
+    ;;
+x86_64-apple-darwin)
+    TARGET_CPPFLAGS="-m64"
+    TAGRET_LDFLAGS="-m64"
+    ;;
+esac
+
 llvm_cppflags="`$llvm_config --cppflags`"
 llvm_includedir="`$llvm_config --includedir`"
 llvm_ldflags="`$llvm_config --ldflags`"
+
 llvm_all_libs="`$llvm_config --libs all`"
 llvm_target="`$llvm_config --libs engine | sed 's/.*LLVM\(.[^ ]*\)CodeGen.*/\1/'`"
 
-CPPFLAGS="$llvm_cppflags $CPPFLAGS"
-LDFLAGS="$llvm_ldflags $LDFLAGS"
+CPPFLAGS="$llvm_cppflags $CPPFLAGS $TARGET_CPPFLAGS"
+LDFLAGS="$llvm_ldflags $LDFLAGS $TARGET_LDFLAGS"
 
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -4050,6 +4079,7 @@
 $as_echo "$as_me: error: could not find LLVM C bindings" >&2;}
    { (exit 1); exit 1; }; }
 fi
+
 
 
 
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -27,16 +27,56 @@
 AC_PATH_PROG(llvm_config, llvm-config,
   [AC_MSG_ERROR(could not find llvm-config in $llvm_bindir)],
   ["$llvm_bindir:$PATH"])
+  
+dnl * Choose target platform
+dnl
+dnl We don't use the standard autoconf macros for this, but instead
+dnl ask GHC what platform it is for.  Why?  We need to generate a library
+dnl matching the compiler.
+dnl NB: This code is from GHC's configure (where the corresponding code for
+dnl guessing host and build variables can be found, too)
 
+dnl Guess target platform if necessary.
+m4_divert_once([HELP_CANON],
+[[
+System types:
+  --target=TARGET   configure for building compilers for TARGET [guessed]]])dnl
+
+if test "$target" = ""
+then
+    if test "${compiler}" != ""
+    then
+        target=`${compiler} +RTS --info | grep '^ ,("Target platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
+        echo "Target platform inferred as: $target"
+    else
+        echo "Can't work out target platform"
+        exit 1
+    fi
+fi
+
+dnl Determine target-specific options
+dnl This is important as Snow Leopard (Mac OS X 10.6) defaults to generating
+dnl 64-bit code.
+case $target in
+i386-apple-darwin)
+    TARGET_CPPFLAGS="-m32"
+    TAGRET_LDFLAGS="-m32"
+    ;;
+x86_64-apple-darwin)
+    TARGET_CPPFLAGS="-m64"
+    TAGRET_LDFLAGS="-m64"
+    ;;
+esac
+
 llvm_cppflags="`$llvm_config --cppflags`"
 llvm_includedir="`$llvm_config --includedir`"
 llvm_ldflags="`$llvm_config --ldflags`"
 
 llvm_all_libs="`$llvm_config --libs all`"
-llvm_target="`$llvm_config --libs engine | sed 's/.*LLVM\(.[^ ]*\)CodeGen.*/\1/'`"
+llvm_target="`$llvm_config --libs engine | sed 's/.*LLVM\(.[[^ ]]*\)CodeGen.*/\1/'`"
 
-CPPFLAGS="$llvm_cppflags $CPPFLAGS"
-LDFLAGS="$llvm_ldflags $LDFLAGS"
+CPPFLAGS="$llvm_cppflags $CPPFLAGS $TARGET_CPPFLAGS"
+LDFLAGS="$llvm_ldflags $LDFLAGS $TARGET_LDFLAGS"
 
 AC_CHECK_HEADERS([llvm-c/Core.h], [],
   [AC_MSG_ERROR(could not find LLVM C bindings)])
diff --git a/llvm.cabal b/llvm.cabal
--- a/llvm.cabal
+++ b/llvm.cabal
@@ -1,5 +1,5 @@
 name: llvm
-version: 0.7.0.0
+version: 0.7.0.1
 license: BSD3
 license-file: LICENSE
 synopsis: Bindings to the LLVM compiler toolkit.
