cafff9
commit b32dcedd13b3fc2ea7a8099cc0f67eaa31b8c298
cafff9
Author: Chris Liddell <chris.liddell@artifex.com>
cafff9
Date:   Thu May 21 09:06:01 2015 +0100
cafff9
cafff9
    Simplify/Improve endian decisions in lcms2.h
cafff9
    
cafff9
    Firstly, protect the endian decisions in lcms2.h so that settings given on the
cafff9
    compiler command line are not silently overridden. Thus being set explicitly
cafff9
    gets the highest priority.
cafff9
    
cafff9
    Secondly, use the endianness detected by the configure script, and remove the
cafff9
    complex and error prone stuff for PPC platforms from lcms2.h. Thus the endianess
cafff9
    from configure gets second highest priority.
cafff9
    
cafff9
    Thirdly, if neither of the above are set, fall back to some simple (and long
cafff9
    standing) platform/compiler specific tests. These should rarely, if ever, come
cafff9
    into play in a "normal" build for a "normal" Unix-like system.
cafff9
cafff9
diff --git a/include/lcms2.h b/include/lcms2.h
cafff9
index a0421d8..f32beec 100644
cafff9
--- a/include/lcms2.h
cafff9
+++ b/include/lcms2.h
cafff9
@@ -173,46 +173,43 @@
cafff9
 #  define CMS_IS_WINDOWS_ 1
cafff9
 #endif
cafff9
 
cafff9
-// Try to detect big endian platforms. This list can be endless, so only some checks are performed over here.
cafff9
-// you can pass this toggle to the compiler by using -DCMS_USE_BIG_ENDIAN or something similar
cafff9
-
cafff9
-#if defined(__sgi__) || defined(__sgi) || defined(sparc)
cafff9
-#   define CMS_USE_BIG_ENDIAN      1
cafff9
-#endif
cafff9
+// Try to detect big endian platforms. This list can be endless, so primarily rely on the configure script
cafff9
+// on Unix-like systems, and allow it to be set on the compiler command line using
cafff9
+// -DCMS_USE_BIG_ENDIAN or something similar
cafff9
+#ifdef CMS_USE_BIG_ENDIAN // set at compiler command line takes overall precedence
cafff9
+#  if CMS_USE_BIG_ENDIAN == 0
cafff9
+#    undef CMS_USE_BIG_ENDIAN
cafff9
+#  endif
cafff9
+#else // CMS_USE_BIG_ENDIAN
cafff9
 
cafff9
-#if defined(__s390__) || defined(__s390x__)
cafff9
-#   define CMS_USE_BIG_ENDIAN   1
cafff9
-#endif
cafff9
+#  ifdef WORDS_BIGENDIAN // set by configure (or explicitly on compiler command line)
cafff9
+#    define CMS_USE_BIG_ENDIAN 1
cafff9
+#  else // WORDS_BIGENDIAN
cafff9
+// Fall back to platform/compiler specific tests
cafff9
+#    if defined(__sgi__) || defined(__sgi) || defined(sparc)
cafff9
+#      define CMS_USE_BIG_ENDIAN      1
cafff9
+#    endif
cafff9
 
cafff9
-#  ifdef TARGET_CPU_PPC
cafff9
-#    if TARGET_CPU_PPC
cafff9
+#    if defined(__s390__) || defined(__s390x__)
cafff9
 #      define CMS_USE_BIG_ENDIAN   1
cafff9
 #    endif
cafff9
-#  endif
cafff9
 
cafff9
-#if defined(__powerpc__) || defined(__ppc__) || defined(TARGET_CPU_PPC)
cafff9
-#   define CMS_USE_BIG_ENDIAN   1
cafff9
-#   if defined (__GNUC__) && defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN)
cafff9
-#       if __BYTE_ORDER  == __LITTLE_ENDIAN
cafff9
-//               // Don't use big endian for PowerPC little endian mode
cafff9
-#                undef CMS_USE_BIG_ENDIAN
cafff9
-#       endif
cafff9
-#   endif
cafff9
-#endif
cafff9
+#    ifdef macintosh
cafff9
+#      ifdef __BIG_ENDIAN__
cafff9
+#        define CMS_USE_BIG_ENDIAN      1
cafff9
+#      endif
cafff9
+#      ifdef __LITTLE_ENDIAN__
cafff9
+#        undef CMS_USE_BIG_ENDIAN
cafff9
+#      endif
cafff9
+#    endif
cafff9
+#  endif  // WORDS_BIGENDIAN
cafff9
 
cafff9
-// WORDS_BIGENDIAN takes precedence
cafff9
-#if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(WORDS_BIGENDIAN)
cafff9
-#   define CMS_USE_BIG_ENDIAN      1
cafff9
-#endif
cafff9
+#  if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
cafff9
+#    define CMS_USE_BIG_ENDIAN      1
cafff9
+#  endif
cafff9
+
cafff9
+#endif  // CMS_USE_BIG_ENDIAN
cafff9
 
cafff9
-#ifdef macintosh
cafff9
-# ifdef __BIG_ENDIAN__
cafff9
-#   define CMS_USE_BIG_ENDIAN      1
cafff9
-# endif
cafff9
-# ifdef __LITTLE_ENDIAN__
cafff9
-#   undef CMS_USE_BIG_ENDIAN
cafff9
-# endif
cafff9
-#endif
cafff9
 
cafff9
 // Calling convention -- this is hardly platform and compiler dependent
cafff9
 #ifdef CMS_IS_WINDOWS_