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