1 dnl @synopsis MN_C_FIND_ENDIAN
3 dnl Determine endian-ness of target processor.
4 dnl @version 1.1 Mar 03 2002
5 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
7 dnl Majority written from scratch to replace the standard autoconf macro
8 dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation
9 dnl of the AC_TRY_RUN macro.
11 dnl Permission to use, copy, modify, distribute, and sell this file for any
12 dnl purpose is hereby granted without fee, provided that the above copyright
13 dnl and this permission notice appear in all copies. No representations are
14 dnl made about the suitability of this software for any purpose. It is
15 dnl provided "as is" without express or implied warranty.
17 dnl Find endian-ness in the following way:
18 dnl 1) Look in <endian.h>.
19 dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
20 dnl 3) If 1) and 2) fails and not cross compiling run a test program.
21 dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
23 AC_DEFUN([MN_C_FIND_ENDIAN],
24 [AC_CACHE_CHECK(processor byte ordering,
27 # Initialize to unknown
28 ac_cv_c_byte_order=unknown
30 if test x$ac_cv_header_endian_h = xyes ; then
32 # First try <endian.h> which should set BYTE_ORDER.
36 #if BYTE_ORDER != LITTLE_ENDIAN
40 ac_cv_c_byte_order=little
45 #if BYTE_ORDER != BIG_ENDIAN
49 ac_cv_c_byte_order=big
54 if test $ac_cv_c_byte_order = unknown ; then
57 #include <sys/types.h>
58 #include <sys/param.h>
59 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #if BYTE_ORDER != LITTLE_ENDIAN
71 ac_cv_c_byte_order=little
75 #include <sys/types.h>
76 #include <sys/param.h>
77 #if BYTE_ORDER != LITTLE_ENDIAN
81 ac_cv_c_byte_order=little
88 if test $ac_cv_c_byte_order = unknown ; then
89 if test $cross_compiling = yes ; then
90 # This is the last resort. Try to guess the target processor endian-ness
91 # by looking at the target CPU type.
94 alpha* | i?86* | mipsel* | ia64*)
95 ac_cv_c_byte_order=little
98 m68* | mips* | powerpc* | hppa* | sparc*)
99 ac_cv_c_byte_order=big
108 { /* Are we little or big endian? From Harbison&Steele. */
111 char c [sizeof (long)] ;
114 return (u.c [sizeof (long) - 1] == 1);
116 ]], , ac_cv_c_byte_order=big,
121 { /* Are we little or big endian? From Harbison&Steele. */
124 char c [sizeof (long)] ;
127 return (u.c [0] == 1);
128 }]], , ac_cv_c_byte_order=little,
135 if test $ac_cv_c_byte_order = big ; then
137 ac_cv_c_little_endian=0
138 elif test $ac_cv_c_byte_order = little ; then
140 ac_cv_c_little_endian=1
143 ac_cv_c_little_endian=0
145 AC_MSG_WARN([[*****************************************************************]])
146 AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]])
147 AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]])
148 AC_MSG_WARN([[*** src/config.h may need to be hand editied. ]])
149 AC_MSG_WARN([[*****************************************************************]])