--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 27627431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 05:08:04 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id KfU3jAf6E6Ep for <notmuch@notmuchmail.org>;\r
+ Tue, 26 Nov 2013 05:07:56 -0800 (PST)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 33642431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 05:07:56 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1VlIMq-0008Tq-Kw; Tue, 26 Nov 2013 09:07:52 -0400\r
+Received: (nullmailer pid 31884 invoked by uid 1000); Tue, 26 Nov 2013\r
+ 13:07:48 -0000\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] util: detect byte order\r
+Date: Tue, 26 Nov 2013 09:07:37 -0400\r
+Message-Id: <1385471257-31835-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.8.4.2\r
+In-Reply-To: <1385328583-24602-2-git-send-email-david@tethera.net>\r
+References: <1385328583-24602-2-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 26 Nov 2013 13:08:04 -0000\r
+\r
+From: David Bremner <david@tethera.net>\r
+\r
+Unfortunately old versions of GCC and clang do not provide byte order\r
+macros, so we re-invent them.\r
+\r
+If UTIL_BYTE_ORDER is not defined, we fall back to macros supported by\r
+recent versions of GCC and clang\r
+---\r
+\r
+I pushed the series\r
+id:1385328583-24602-1-git-send-email-david@tethera.net; unfortunately\r
+that broke compilation on old versions of GCC, in particular on our\r
+buildbot. Here is a proposed fix for the fix.\r
+\r
+ configure | 26 ++++++++++++++++++++++++--\r
+ lib/libsha1.c | 19 +++++--------------\r
+ util/endian-util.h | 39 +++++++++++++++++++++++++++++++++++++++\r
+ 3 files changed, 68 insertions(+), 16 deletions(-)\r
+ create mode 100644 util/endian-util.h\r
+\r
+diff --git a/configure b/configure\r
+index 1a8e939..02d6396 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -441,6 +441,21 @@ else\r
+ EOF\r
+ fi\r
+ \r
++printf "Checking byte order... "\r
++cat> _byteorder.c <<EOF\r
++#include <stdio.h>\r
++#include <stdint.h>\r
++#include <string.h>\r
++uint32_t test = 0x31323334;\r
++char buf[5];\r
++int main() { memcpy(buf, &test, 4); buf[4] = '\0'; printf("%s\n", buf); return 0; }\r
++EOF\r
++${CC} ${CFLAGS} _byteorder.c -o _byteorder > /dev/null 2>&1\r
++util_byte_order=$(./_byteorder)\r
++echo $util_byte_order\r
++\r
++#rm -f _byteorder _byteorder.c\r
++\r
+ if [ $errors -gt 0 ]; then\r
+ cat <<EOF\r
+ \r
+@@ -702,6 +717,9 @@ prefix = ${PREFIX}\r
+ # LIBDIR_IN_LDCONFIG value below is still set correctly.\r
+ libdir = ${LIBDIR:=\$(prefix)/lib}\r
+ \r
++# byte order within a 32 bit word. 4321 = little, 1234 = big, 0 = guess\r
++UTIL_BYTE_ORDER = ${util_byte_order}\r
++\r
+ # Whether libdir is in a path configured into ldconfig\r
+ LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}\r
+ \r
+@@ -807,7 +825,9 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+ -DHAVE_STRSEP=\$(HAVE_STRSEP) \\\r
+ -DSTD_GETPWUID=\$(STD_GETPWUID) \\\r
+ -DSTD_ASCTIME=\$(STD_ASCTIME) \\\r
+- -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
++ -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\\r
++ -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
++\r
+ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+ \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+ \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\\r
+@@ -815,6 +835,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+ -DHAVE_STRSEP=\$(HAVE_STRSEP) \\\r
+ -DSTD_GETPWUID=\$(STD_GETPWUID) \\\r
+ -DSTD_ASCTIME=\$(STD_ASCTIME) \\\r
+- -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
++ -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\\r
++ -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
++\r
+ CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+ EOF\r
+diff --git a/lib/libsha1.c b/lib/libsha1.c\r
+index 87c7c52..3566ed7 100644\r
+--- a/lib/libsha1.c\r
++++ b/lib/libsha1.c\r
+@@ -34,7 +34,7 @@\r
+ */\r
+ \r
+ #include <string.h> /* for memcpy() etc. */\r
+-\r
++#include "endian-util.h"\r
+ #include "libsha1.h"\r
+ \r
+ #if defined(__cplusplus)\r
+@@ -49,20 +49,11 @@ extern "C"\r
+ \r
+ #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))\r
+ \r
+-/* The macros __BYTE_ORDER__ and __ORDER_*_ENDIAN__ are GNU C\r
+- * extensions. They are also supported by clang as of v3.2 */\r
+-\r
+-#ifdef __BYTE_ORDER__\r
+-# if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
+-# define bsw_32(p,n) \\r
+- { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
+-# elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
+-# define bsw_32(p,n)\r
+-# else\r
+-# error "unknown byte order"\r
+-# endif\r
++#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN)\r
++# define bsw_32(p,n) \\r
++ { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
+ #else\r
+-# error "macro __BYTE_ORDER__ is not defined"\r
++# define bsw_32(p,n)\r
+ #endif\r
+ \r
+ #define SHA1_MASK (SHA1_BLOCK_SIZE - 1)\r
+diff --git a/util/endian-util.h b/util/endian-util.h\r
+new file mode 100644\r
+index 0000000..cbecf66\r
+--- /dev/null\r
++++ b/util/endian-util.h\r
+@@ -0,0 +1,39 @@\r
++/* this file mimics the macros present in recent GCC and CLANG */\r
++\r
++#ifndef _ENDIAN_UTIL_H\r
++#define _ENDIAN_UTIL_H\r
++\r
++/* This are prefixed with UTIL to avoid collisions\r
++ *\r
++ * You can use something like the following to define UTIL_BYTE_ORDER\r
++ * in a configure script.\r
++ */\r
++#if 0\r
++#include <stdio.h>\r
++#include <stdint.h>\r
++#include <string.h>\r
++uint32_t test = 0x31323334;\r
++char buf[5];\r
++int main() { memcpy(buf, &test, 4); buf[4] = '\0'; printf("%s\n", buf); return 0; }\r
++#endif\r
++\r
++#define UTIL_ORDER_LITTLE_ENDIAN 4321\r
++#define UTIL_ORDER_BIG_ENDIAN 1234\r
++\r
++\r
++#if !defined(UTIL_BYTE_ORDER) || ((UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN) && \\r
++ (UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN))\r
++#ifdef __BYTE_ORDER__\r
++# if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
++# define UTIL_BYTE_ORDER UTIL_ORDER_LITTLE_ENDIAN\r
++# elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
++# define UTIL_BYTE_ORDER UTIL_ORDER_BIG_ENDIAN\r
++# else\r
++# error "Unsupported __BYTE_ORDER__"\r
++# endif\r
++#else\r
++# error "UTIL_BYTE_ORDER not correctly defined and __BYTE_ORDER__ not defined."\r
++#endif\r
++#endif\r
++\r
++#endif\r
+-- \r
+1.8.4.2\r
+\r