Adjust endianness detection
authorEric Biggers <ebiggers3@gmail.com>
Tue, 30 Dec 2014 03:26:06 +0000 (21:26 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 30 Dec 2014 03:27:09 +0000 (21:27 -0600)
__BYTE_ORDER__ isn't available in older gcc, unfortunately.

configure.ac
include/wimlib/compiler-gcc.h
include/wimlib/compiler.h

index e5e834f..27d6fa3 100644 (file)
@@ -5,6 +5,7 @@ AC_CONFIG_SRCDIR([src/wim.c])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE([-Wall -Werror subdir-objects foreign])
+AC_C_BIGENDIAN
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
 LT_INIT
 
index 4698330..cb42c89 100644 (file)
 #define inline                 inline __attribute__((always_inline))
 #define noinline               __attribute__((noinline))
 
-#define CPU_IS_BIG_ENDIAN      (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+/* Newer gcc supports __BYTE_ORDER__.  Older gcc doesn't.  */
+#ifdef __BYTE_ORDER__
+#  define CPU_IS_BIG_ENDIAN    (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#elif defined(HAVE_CONFIG_H)
+#  include "config.h"
+#  ifdef WORDS_BIGENDIAN
+#    define CPU_IS_BIG_ENDIAN 1
+#  else
+#    define CPU_IS_BIG_ENDIAN 0
+#  endif
+#endif
 
 #if defined(__x86_64__) || defined(__i386__)
 #  define UNALIGNED_ACCESS_SPEED 3
index 11eaa23..4bd92d7 100644 (file)
@@ -59,7 +59,7 @@
 #endif
 
 #ifndef CPU_IS_BIG_ENDIAN
-#  error "missing required definition of CPU_IS_BIG_ENDIAN"
+#  error "missing required endianness definition"
 #endif
 
 #define CPU_IS_LITTLE_ENDIAN (!CPU_IS_BIG_ENDIAN)