Chris@41: dnl @synopsis AC_C_FIND_ENDIAN Chris@41: dnl Chris@41: dnl Determine endian-ness of target processor. Chris@41: dnl @version 1.1 Mar 03 2002 Chris@41: dnl @author Erik de Castro Lopo Chris@41: dnl Chris@41: dnl Majority written from scratch to replace the standard autoconf macro Chris@41: dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation Chris@41: dnl of the AC_TRY_RUN macro. Chris@41: dnl Chris@41: dnl Permission to use, copy, modify, distribute, and sell this file for any Chris@41: dnl purpose is hereby granted without fee, provided that the above copyright Chris@41: dnl and this permission notice appear in all copies. No representations are Chris@41: dnl made about the suitability of this software for any purpose. It is Chris@41: dnl provided "as is" without express or implied warranty. Chris@41: Chris@41: dnl Find endian-ness in the following way: Chris@41: dnl 1) Look in . Chris@41: dnl 2) If 1) fails, look in and . Chris@41: dnl 3) If 1) and 2) fails and not cross compiling run a test program. Chris@41: dnl 4) If 1) and 2) fails and cross compiling then guess based on target. Chris@41: Chris@41: AC_DEFUN([AC_C_FIND_ENDIAN], Chris@41: [AC_CACHE_CHECK(processor byte ordering, Chris@41: ac_cv_c_byte_order, Chris@41: Chris@41: # Initialize to unknown Chris@41: ac_cv_c_byte_order=unknown Chris@41: Chris@41: if test x$ac_cv_header_endian_h = xyes ; then Chris@41: Chris@41: # First try which should set BYTE_ORDER. Chris@41: Chris@41: [AC_TRY_LINK([ Chris@41: #include Chris@41: #if BYTE_ORDER != LITTLE_ENDIAN Chris@41: not big endian Chris@41: #endif Chris@41: ], return 0 ;, Chris@41: ac_cv_c_byte_order=little Chris@41: )] Chris@41: Chris@41: [AC_TRY_LINK([ Chris@41: #include Chris@41: #if BYTE_ORDER != BIG_ENDIAN Chris@41: not big endian Chris@41: #endif Chris@41: ], return 0 ;, Chris@41: ac_cv_c_byte_order=big Chris@41: )] Chris@41: Chris@41: fi Chris@41: Chris@41: if test $ac_cv_c_byte_order = unknown ; then Chris@41: Chris@41: [AC_TRY_LINK([ Chris@41: #include Chris@41: #include Chris@41: #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN Chris@41: bogus endian macros Chris@41: #endif Chris@41: ], return 0 ;, Chris@41: Chris@41: [AC_TRY_LINK([ Chris@41: #include Chris@41: #include Chris@41: #if BYTE_ORDER != LITTLE_ENDIAN Chris@41: not big endian Chris@41: #endif Chris@41: ], return 0 ;, Chris@41: ac_cv_c_byte_order=little Chris@41: )] Chris@41: Chris@41: [AC_TRY_LINK([ Chris@41: #include Chris@41: #include Chris@41: #if BYTE_ORDER != LITTLE_ENDIAN Chris@41: not big endian Chris@41: #endif Chris@41: ], return 0 ;, Chris@41: ac_cv_c_byte_order=little Chris@41: )] Chris@41: Chris@41: )] Chris@41: Chris@41: fi Chris@41: Chris@41: if test $ac_cv_c_byte_order = unknown ; then Chris@41: if test $cross_compiling = yes ; then Chris@41: # This is the last resort. Try to guess the target processor endian-ness Chris@41: # by looking at the target CPU type. Chris@41: [ Chris@41: case "$target_cpu" in Chris@41: alpha* | i?86* | mipsel* | ia64*) Chris@41: ac_cv_c_byte_order=little Chris@41: ;; Chris@41: Chris@41: m68* | mips* | powerpc* | hppa* | sparc*) Chris@41: ac_cv_c_byte_order=big Chris@41: ;; Chris@41: Chris@41: esac Chris@41: ] Chris@41: else Chris@41: AC_TRY_RUN( Chris@41: [[ Chris@41: int main (void) Chris@41: { /* Are we little or big endian? From Harbison&Steele. */ Chris@41: union Chris@41: { long l ; Chris@41: char c [sizeof (long)] ; Chris@41: } u ; Chris@41: u.l = 1 ; Chris@41: return (u.c [sizeof (long) - 1] == 1); Chris@41: } Chris@41: ]], , ac_cv_c_byte_order=big, Chris@41: ) Chris@41: Chris@41: AC_TRY_RUN( Chris@41: [[int main (void) Chris@41: { /* Are we little or big endian? From Harbison&Steele. */ Chris@41: union Chris@41: { long l ; Chris@41: char c [sizeof (long)] ; Chris@41: } u ; Chris@41: u.l = 1 ; Chris@41: return (u.c [0] == 1); Chris@41: }]], , ac_cv_c_byte_order=little, Chris@41: ) Chris@41: fi Chris@41: fi Chris@41: Chris@41: ) Chris@41: Chris@41: if test $ac_cv_c_byte_order = big ; then Chris@41: ac_cv_c_big_endian=1 Chris@41: ac_cv_c_little_endian=0 Chris@41: elif test $ac_cv_c_byte_order = little ; then Chris@41: ac_cv_c_big_endian=0 Chris@41: ac_cv_c_little_endian=1 Chris@41: else Chris@41: ac_cv_c_big_endian=0 Chris@41: ac_cv_c_little_endian=0 Chris@41: Chris@41: AC_MSG_WARN([[*****************************************************************]]) Chris@41: AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]]) Chris@41: AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]]) Chris@41: AC_MSG_WARN([[*** src/config.h may need to be hand editied. ]]) Chris@41: AC_MSG_WARN([[*****************************************************************]]) Chris@41: fi Chris@41: Chris@41: ] Chris@41: )# AC_C_FIND_ENDIAN Chris@41: Chris@41: