You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.7KB

  1. dnl @synopsis AC_C_FIND_ENDIAN
  2. dnl
  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>
  6. dnl
  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.
  10. dnl
  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.
  16. dnl Find endian-ness in the following way:
  17. dnl 1) Look in <endian.h>.
  18. dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
  19. dnl 3) If 1) and 2) fails and not cross compiling run a test program.
  20. dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
  21. AC_DEFUN([AC_C_FIND_ENDIAN],
  22. [AC_CACHE_CHECK(processor byte ordering,
  23. ac_cv_c_byte_order,
  24. # Initialize to unknown
  25. ac_cv_c_byte_order=unknown
  26. if test x$ac_cv_header_endian_h = xyes ; then
  27. # First try <endian.h> which should set BYTE_ORDER.
  28. [AC_TRY_LINK([
  29. #include <endian.h>
  30. #if BYTE_ORDER != LITTLE_ENDIAN
  31. not big endian
  32. #endif
  33. ], return 0 ;,
  34. ac_cv_c_byte_order=little
  35. )]
  36. [AC_TRY_LINK([
  37. #include <endian.h>
  38. #if BYTE_ORDER != BIG_ENDIAN
  39. not big endian
  40. #endif
  41. ], return 0 ;,
  42. ac_cv_c_byte_order=big
  43. )]
  44. fi
  45. if test $ac_cv_c_byte_order = unknown ; then
  46. [AC_TRY_LINK([
  47. #include <sys/types.h>
  48. #include <sys/param.h>
  49. #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
  50. bogus endian macros
  51. #endif
  52. ], return 0 ;,
  53. [AC_TRY_LINK([
  54. #include <sys/types.h>
  55. #include <sys/param.h>
  56. #if BYTE_ORDER != LITTLE_ENDIAN
  57. not big endian
  58. #endif
  59. ], return 0 ;,
  60. ac_cv_c_byte_order=little
  61. )]
  62. [AC_TRY_LINK([
  63. #include <sys/types.h>
  64. #include <sys/param.h>
  65. #if BYTE_ORDER != LITTLE_ENDIAN
  66. not big endian
  67. #endif
  68. ], return 0 ;,
  69. ac_cv_c_byte_order=little
  70. )]
  71. )]
  72. fi
  73. if test $ac_cv_c_byte_order = unknown ; then
  74. if test $cross_compiling = yes ; then
  75. # This is the last resort. Try to guess the target processor endian-ness
  76. # by looking at the target CPU type.
  77. [
  78. case "$target_cpu" in
  79. alpha* | i?86* | mipsel* | ia64*)
  80. ac_cv_c_byte_order=little
  81. ;;
  82. m68* | mips* | powerpc* | hppa* | sparc*)
  83. ac_cv_c_byte_order=big
  84. ;;
  85. esac
  86. ]
  87. else
  88. AC_TRY_RUN(
  89. [[
  90. int main (void)
  91. { /* Are we little or big endian? From Harbison&Steele. */
  92. union
  93. { long l ;
  94. char c [sizeof (long)] ;
  95. } u ;
  96. u.l = 1 ;
  97. return (u.c [sizeof (long) - 1] == 1);
  98. }
  99. ]], , ac_cv_c_byte_order=big,
  100. )
  101. AC_TRY_RUN(
  102. [[int main (void)
  103. { /* Are we little or big endian? From Harbison&Steele. */
  104. union
  105. { long l ;
  106. char c [sizeof (long)] ;
  107. } u ;
  108. u.l = 1 ;
  109. return (u.c [0] == 1);
  110. }]], , ac_cv_c_byte_order=little,
  111. )
  112. fi
  113. fi
  114. )
  115. if test $ac_cv_c_byte_order = big ; then
  116. ac_cv_c_big_endian=1
  117. ac_cv_c_little_endian=0
  118. elif test $ac_cv_c_byte_order = little ; then
  119. ac_cv_c_big_endian=0
  120. ac_cv_c_little_endian=1
  121. else
  122. ac_cv_c_big_endian=0
  123. ac_cv_c_little_endian=0
  124. AC_MSG_WARN([[*****************************************************************]])
  125. AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]])
  126. AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]])
  127. AC_MSG_WARN([[*** src/config.h may need to be hand editied. ]])
  128. AC_MSG_WARN([[*****************************************************************]])
  129. fi
  130. ]
  131. )# AC_C_FIND_ENDIAN