Cache the results of all runtime checks.

This will be helpful to people who want to compile Python with a
cross-compiler. Now you can upload the configure script on your host
machine, run it with caching enabled, and download the cached results
on your build machine.
diff --git a/configure.in b/configure.in
index 652a751..ef2549e 100644
--- a/configure.in
+++ b/configure.in
@@ -873,10 +873,11 @@
     AC_MSG_CHECKING(whether $CC accepts -fno-strict-aliasing)
      ac_save_cc="$CC"
      CC="$CC -fno-strict-aliasing"
+     AC_CACHE_VAL(ac_cv_no_strict_aliasing_ok,
      AC_TRY_RUN([int main() { return 0; }],
      ac_cv_no_strict_aliasing_ok=yes,
      ac_cv_no_strict_aliasing_ok=no,
-     ac_cv_no_strict_aliasing_ok=no)
+     ac_cv_no_strict_aliasing_ok=no))
      CC="$ac_save_cc"
     AC_MSG_RESULT($ac_cv_no_strict_aliasing_ok)
     if test $ac_cv_no_strict_aliasing_ok = yes
@@ -2496,7 +2497,8 @@
 # On Tru64, chflags seems to be present, but calling it will
 # exit Python
 AC_MSG_CHECKING(for chflags)
-AC_TRY_RUN([
+AC_CACHE_VAL(ac_cv_have_chflags,
+AC_TRY_RUN([[
 #include <sys/stat.h>
 #include <unistd.h>
 int main(int argc, char*argv[])
@@ -2505,13 +2507,19 @@
     return 1;
   return 0;
 }
-],AC_DEFINE(HAVE_CHFLAGS, 1, Define to 1 if you have the `chflags' function.)
-  AC_MSG_RESULT(yes),
-  AC_MSG_RESULT(no)
+]], ac_cv_have_chflags=yes,
+    ac_cv_have_chflags=no,
+    ac_cv_have_chflags=no)
 )
+AC_MSG_RESULT($ac_cv_have_chflags)
+if test $ac_cv_have_chflags = yes
+then
+  AC_DEFINE(HAVE_CHFLAGS, 1, Define to 1 if you have the `chflags' function.)
+fi
 
 AC_MSG_CHECKING(for lchflags)
-AC_TRY_RUN([
+AC_CACHE_VAL(ac_cv_have_lchflags,
+AC_TRY_RUN([[
 #include <sys/stat.h>
 #include <unistd.h>
 int main(int argc, char*argv[])
@@ -2520,10 +2528,15 @@
     return 1;
   return 0;
 }
-],AC_DEFINE(HAVE_LCHFLAGS, 1, Define to 1 if you have the `lchflags' function.)
-  AC_MSG_RESULT(yes),
-  AC_MSG_RESULT(no)
+]], ac_cv_have_lchflags=yes,
+    ac_cv_have_lchflags=no,
+    ac_cv_have_lchflags=no)
 )
+AC_MSG_RESULT($ac_cv_have_lchflags)
+if test $ac_cv_have_lchflags = yes
+then
+  AC_DEFINE(HAVE_LCHFLAGS, 1, Define to 1 if you have the `lchflags' function.)
+fi
 
 dnl Check if system zlib has *Copy() functions
 dnl
@@ -2677,19 +2690,22 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <stdio.h>
-],[
-getaddrinfo(NULL, NULL, NULL, NULL);
-], [
-AC_MSG_RESULT(yes)
-AC_MSG_CHECKING(getaddrinfo bug)
-AC_TRY_RUN([
+], [getaddrinfo(NULL, NULL, NULL, NULL);],
+have_getaddrinfo=yes,
+have_getaddrinfo=no)
+AC_MSG_RESULT($have_getaddrinfo)
+if test $have_getaddrinfo = yes
+then
+  AC_MSG_CHECKING(getaddrinfo bug)
+  AC_CACHE_VAL(ac_cv_buggy_getaddrinfo,
+  AC_TRY_RUN([[
 #include <sys/types.h>
 #include <netdb.h>
 #include <string.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
-main()
+int main()
 {
   int passive, gaierr, inet4 = 0, inet6 = 0;
   struct addrinfo hints, *ai, *aitop;
@@ -2761,26 +2777,22 @@
 
   if (aitop)
     freeaddrinfo(aitop);
-  exit(0);
+  return 0;
 
  bad:
   if (aitop)
     freeaddrinfo(aitop);
-  exit(1);
+  return 1;
 }
-],
-AC_MSG_RESULT(good)
-buggygetaddrinfo=no,
-AC_MSG_RESULT(buggy)
-buggygetaddrinfo=yes,
-AC_MSG_RESULT(buggy)
-buggygetaddrinfo=yes)], [
-AC_MSG_RESULT(no)
-buggygetaddrinfo=yes
-])
+]], ac_cv_buggy_getaddrinfo=no,
+    ac_cv_buggy_getaddrinfo=yes,
+    ac_cv_buggy_getaddrinfo=yes))
+fi
 
-if test "$buggygetaddrinfo" = "yes"; then
-	if test "$ipv6" = "yes"; then
+if test $have_getaddrinfo = no -o $ac_cv_buggy_getaddrinfo = yes
+then
+	if test $ipv6 = yes
+	then
 		echo 'Fatal: You must get working getaddrinfo() function.'
 		echo '       or you can specify "--disable-ipv6"'.
 		exit 1
@@ -3247,6 +3259,7 @@
 
 # Multiprocessing check for broken sem_getvalue
 AC_MSG_CHECKING(for broken sem_getvalue)
+AC_CACHE_VAL(ac_cv_broken_sem_getvalue,
 AC_TRY_RUN([
 #include <unistd.h>
 #include <fcntl.h>
@@ -3267,11 +3280,16 @@
   sem_close(a);
   return res==-1 ? 1 : 0;
 }
-]
-,AC_MSG_RESULT(no),
- AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_BROKEN_SEM_GETVALUE, 1, define to 1 if your sem_getvalue is broken.)
+], ac_cv_broken_sem_getvalue=no,
+   ac_cv_broken_sem_getvalue=yes,
+   ac_cv_broken_sem_getvalue=yes)
 )
+AC_MSG_RESULT($ac_cv_broken_sem_getvalue)
+if test $ac_cv_broken_sem_getvalue = yes
+then
+  AC_DEFINE(HAVE_BROKEN_SEM_GETVALUE, 1,
+  [define to 1 if your sem_getvalue is broken.])
+fi
 
 # determine what size digit to use for Python's longs
 AC_MSG_CHECKING([digit size for Python's longs])
@@ -3528,6 +3546,7 @@
 fi
 
 AC_MSG_CHECKING(for broken poll())
+AC_CACHE_VAL(ac_cv_broken_poll,
 AC_TRY_RUN([
 #include <poll.h>
 
@@ -3555,7 +3574,7 @@
 ],
 ac_cv_broken_poll=yes,
 ac_cv_broken_poll=no,
-ac_cv_broken_poll=no)
+ac_cv_broken_poll=no))
 AC_MSG_RESULT($ac_cv_broken_poll)
 if test "$ac_cv_broken_poll" = yes
 then
@@ -3757,6 +3776,7 @@
 fi
 
 AC_MSG_CHECKING(for %zd printf() format support)
+AC_CACHE_VAL(ac_cv_have_size_t_format,
 AC_TRY_RUN([#include <stdio.h>
 #include <stddef.h>
 #include <string.h>
@@ -3790,10 +3810,17 @@
 	return 1;
 
     return 0;
-}],
-[AC_MSG_RESULT(yes)
- AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])],
- AC_MSG_RESULT(no))
+}
+], ac_cv_have_size_t_format=yes,
+   ac_cv_have_size_t_format=no,
+   ac_cv_have_size_t_format=no)
+)
+AC_MSG_RESULT($ac_cv_have_size_t_format)
+if test $ac_cv_have_size_t_format = yes
+then
+  AC_DEFINE(PY_FORMAT_SIZE_T, "z",
+  [Define to printf format modifier for Py_ssize_t])
+fi
 
 AC_CHECK_TYPE(socklen_t,,
   AC_DEFINE(socklen_t,int,
@@ -3807,6 +3834,7 @@
 ])
 
 AC_MSG_CHECKING(for broken mbstowcs)
+AC_CACHE_VAL(ac_cv_broken_mbstowcs,
 AC_TRY_RUN([
 #include<stdlib.h>
 int main() {
@@ -3818,7 +3846,7 @@
 ],
 ac_cv_broken_mbstowcs=no,
 ac_cv_broken_mbstowcs=yes,
-ac_cv_broken_mbstowcs=no)
+ac_cv_broken_mbstowcs=no))
 AC_MSG_RESULT($ac_cv_broken_mbstowcs)
 if test "$ac_cv_broken_mbstowcs" = yes
 then