Check if the operating system provides a working ntohll
[awesomized/libmemcached] / config / byteorder.m4
index fe88605a0d9aba5b61bb68575798b7d338855982..0d8cc8f8920918b0024385ddcd9dd1e5800acbe6 100644 (file)
@@ -1,11 +1,41 @@
-AC_RUN_IFELSE([ 
-   AC_LANG_PROGRAM([
+AC_DEFUN([DETECT_BYTEORDER],
+[
+    AC_MSG_CHECKING([for htonll])
+    have_htoll="no"
+    AC_RUN_IFELSE([
+       AC_LANG_PROGRAM([
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <inttypes.h>
-      ], [
+       ], [
+          return htonll(0);
+       ])            
+    ], [
+      have_htoll="yes"
+      AC_DEFINE([HAVE_HTONLL], [1], [Have ntohll])
+    ])
+
+    AC_MSG_RESULT([$have_htoll])
+    AM_CONDITIONAL([BUILD_BYTEORDER],[test "x$have_htoll" == "xno"])
+    if test "x$have_htoll" == "xno"
+    then
+       AC_MSG_CHECKING([byteorder])
+       have_htoll="no"
+       AC_RUN_IFELSE([
+          AC_LANG_PROGRAM([
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <inttypes.h>
+          ], [
 if (htonl(5) != 5) {
    return 1;
 }
-      ])            
-   ], AC_DEFINE([BYTEORDER_BIG_ENDIAN], [1], [Enable big endian byteorder]))
+          ])            
+       ], [
+          AC_MSG_RESULT([big endian])
+          AC_DEFINE([BYTEORDER_BIG_ENDIAN], [1], [Enable big endian byteorder])
+       ], AC_MSG_RESULT([little endian]))
+    fi
+])
+
+DETECT_BYTEORDER