Fixed autoconf macros for cross compile
authorTrond Norbye <trond.norbye@gmail.com>
Thu, 29 Jul 2010 00:09:42 +0000 (02:09 +0200)
committerTrond Norbye <trond.norbye@gmail.com>
Thu, 29 Jul 2010 00:09:42 +0000 (02:09 +0200)
configure.ac
m4/byteorder.m4
m4/eagain.m4 [new file with mode: 0644]
m4/protocol_binary.m4
m4/setsockopt.m4

index d3a4a349bfbbd1f37eb90310e7cb1dfebd854258..4beb8a0ac65436dcd53783860225265ac51f7281 100644 (file)
@@ -140,25 +140,7 @@ AM_CONDITIONAL(BUILD_POLL, test "x$ac_cv_header_poll_h" = "xno")
 AM_CONDITIONAL(BUILD_WIN32_WRAPPERS, test "x$ac_cv_header_winsock2_h" = "xyes")
 AS_IF(test "x$ac_cv_header_winsock2_h" = "xyes",
       AM_LDFLAGS="$AM_LDFLAGS -lws2_32")
-
-#
-# Some platforms define EWOULDBLOCK == EAGAIN, causing our switch for error
-# codes to be illegal (POSIX.1-2001 allows both return codes from recv, so
-# we need to test both if they differ...)
-#
-AC_MSG_CHECKING([if EWOULDBLOCK == EAGAIN])
-AC_RUN_IFELSE(
-  [AC_LANG_PROGRAM([
-#include <errno.h>
-     ], [dnl
-   return EAGAIN == EWOULDBLOCK ? 0 : 1;
-     ])
-  ],[
-   AC_MSG_RESULT([yes])
-  ], [
-   AC_MSG_RESULT([no])
-   AC_DEFINE([USE_EAGAIN], [1], [Define to true if you need to test for eagain])
-  ])
+DETECT_EAGAIN
 
 AC_CONFIG_FILES([
   Makefile
index 4692bbd205c44a9fe3719e4a534169272b10de15..5a99af7a596838fc072c8ba6c79d1cc705c390e7 100644 (file)
@@ -1,25 +1,19 @@
 AC_DEFUN([DETECT_BYTEORDER],
 [
     AC_REQUIRE([AC_C_BIGENDIAN])
-    AC_CACHE_CHECK([for htonll],[av_cv_have_htonll],[
-
-    AC_RUN_IFELSE([
-       AC_LANG_PROGRAM([[
+    AC_CACHE_CHECK([for htonll], [ac_cv_have_htonll],
+        [AC_TRY_COMPILE([
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <inttypes.h>
-       ]],[[
-          return htonll(0);
-       ]])            
-    ], [
-      ac_cv_have_htonll=yes
-    ],[
-      ac_cv_have_htonll=no
-    ])])
-
+                        ], [
+return htonll(0);
+                        ],
+                        [ ac_cv_have_htonll=yes ],
+                        [ ac_cv_have_htonll=no ])
+        ])
     AS_IF([test "x$ac_cv_have_htonll" = "xyes"],[
-      AC_DEFINE([HAVE_HTONLL], [1], [Have ntohll])])
+          AC_DEFINE([HAVE_HTONLL], [1], [Have ntohll])])
 
     AM_CONDITIONAL([BUILD_BYTEORDER],[test "x$ac_cv_have_htonll" = "xno"])
 ])
-
diff --git a/m4/eagain.m4 b/m4/eagain.m4
new file mode 100644 (file)
index 0000000..3ba8c23
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# Some platforms define EWOULDBLOCK == EAGAIN, causing our switch for error
+# codes to be illegal (POSIX.1-2001 allows both return codes from recv, so
+# we need to test both if they differ...)
+#
+AC_DEFUN([DETECT_EAGAIN],
+[
+    AC_CACHE_CHECK([if EWOULDBLOCK == EAGAIN],[av_cv_eagain_ewouldblock],
+        [AC_TRY_COMPILE([
+#include <errno.h>
+                        ], [
+int error = EAGAIN;
+switch (error) 
+{
+  case EAGAIN:
+  case EWOULDBLOCK:
+       error = 1;
+       break;
+  default:
+       error = 0;
+}
+                        ],
+                        [ av_cv_eagain_ewouldblock=no ],
+                        [ av_cv_eagain_ewouldblock=yes ])
+        ])
+    AS_IF([test "x$ac_cv_eagain_ewouldblock" = "xyes"],[
+          AC_DEFINE([USE_EAGAIN], [1], [Define to true if you need to test for eagain])])
+])
index ba7acaf5f52d01ceaf2a113ba54dbd2860ba3956..5c00b5563ac3c0af118d1c720e7f4e87a0cb78fd 100644 (file)
@@ -1,22 +1,34 @@
 dnl ---------------------------------------------------------------------------
 dnl Macro: PROTOCOL_BINARY_TEST
 dnl ---------------------------------------------------------------------------
+
 AC_DEFUN([PROTOCOL_BINARY_TEST],
-  [AC_LANG_PUSH([C])
-   save_CFLAGS="$CFLAGS"
-   CFLAGS="$CFLAGS -I${srcdir}"
-   AC_RUN_IFELSE([
-      AC_LANG_PROGRAM([[
+[
+  AC_CACHE_CHECK([for supported struct padding], [ac_cv_supported_struct_padding], [
+    AC_LANG_PUSH([C])
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS -I${srcdir}"
+    AC_TRY_COMPILE([
 #include <inttypes.h>
 #include "libmemcached/memcached/protocol_binary.h"
-   ]],[[
+                   ], [
       protocol_binary_request_set request;
-      if (sizeof(request) != sizeof(request.bytes)) {
-         return 1;
+      int a = 1;
+      switch (a) {
+      case sizeof(request):
+      case sizeof(request.bytes):
+          break;
+      default:
+          a = 2;
       }
-   ]])],, AC_MSG_ERROR([Unsupported struct padding done by compiler.]))
+                   ],
+                   [ ac_cv_supported_struct_padding=no ],
+                   [ ac_cv_supported_struct_padding=yes ])
    CFLAGS="$save_CFLAGS"
    AC_LANG_POP
+  ])
+  AS_IF([test "x$ac_cv_supported_struct_padding" = "xno"],[
+        AC_MSG_ERROR([Unsupported struct padding done by compiler.])])
 ])
 
 dnl ---------------------------------------------------------------------------
index e37fe2ae7c0e9b0df3e3d2081af6dc1bea628ca7..58c61c0ab9fa4c6a0e63989a14b8229988be6786 100644 (file)
@@ -2,6 +2,7 @@ dnl ---------------------------------------------------------------------------
 dnl Macro: SETSOCKOPT_SANITY
 dnl ---------------------------------------------------------------------------
 AC_DEFUN([SETSOCKOPT_SANITY],[
+  AC_CACHE_CHECK([for working SO_SNDTIMEO], [ac_cv_have_so_sndtimeo],
   AC_LANG_PUSH([C])
   AC_RUN_IFELSE([ 
     AC_LANG_PROGRAM([[
@@ -25,8 +26,17 @@ AC_DEFUN([SETSOCKOPT_SANITY],[
      }
      return 0;
    ]])],
-   [AC_DEFINE(HAVE_SNDTIMEO, 1, [Define to 1 if you have a working SO_SNDTIMEO])]) 
+   [ac_cv_have_so_sndtimeo=yes],
+   [ac_cv_have_so_sndtimeo=no],
+   [ac_cv_have_so_sndtimeo=yes])
 
+   AS_IF([test "x$ac_cv_have_so_sndtimeo" = "xyes"], [
+          AC_DEFINE(HAVE_SNDTIMEO, 1, [Define to 1 if you have a working SO_SNDTIMEO])])
+   AC_LANG_POP
+   )
+
+  AC_CACHE_CHECK([for working SO_RCVTIMEO], [ac_cv_have_so_rcvtimeo],
+  AC_LANG_PUSH([C])
   AC_RUN_IFELSE([ 
     AC_LANG_PROGRAM([[
 #include <sys/types.h>
@@ -34,7 +44,7 @@ AC_DEFUN([SETSOCKOPT_SANITY],[
 #include <time.h>
 #include <sys/time.h>
 #include <errno.h>
-    ]],[[
+   ]],[[
      int sock = socket(AF_INET, SOCK_STREAM, 0);
      struct timeval waittime;
    
@@ -48,9 +58,15 @@ AC_DEFUN([SETSOCKOPT_SANITY],[
        }
      }
      return 0;
-   ]])], [AC_DEFINE(HAVE_RCVTIMEO, 1, [Define to 1 if you have a working SO_RCVTIMEO])]) 
+   ]])],
+   [ac_cv_have_so_rcvtimeo=yes],
+   [ac_cv_have_so_rcvtimeo=no],
+   [ac_cv_have_so_rcvtimeo=yes])
 
-  AC_LANG_POP
+   AS_IF([test "x$ac_cv_have_so_rcvtimeo" = "xyes"], [
+          AC_DEFINE(HAVE_RCVTIMEO, 1, [Define to 1 if you have a working SO_RCVTIMEO])])
+   AC_LANG_POP
+   )
 ])
 dnl ---------------------------------------------------------------------------
 dnl End Macro: SETSOCKOPT_SANITY