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