endian.m4 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. dnl Copyright (C) 2012-2023 Xiph.Org Foundation
  2. dnl
  3. dnl Redistribution and use in source and binary forms, with or without
  4. dnl modification, are permitted provided that the following conditions
  5. dnl are met:
  6. dnl
  7. dnl - Redistributions of source code must retain the above copyright
  8. dnl notice, this list of conditions and the following disclaimer.
  9. dnl
  10. dnl - Redistributions in binary form must reproduce the above copyright
  11. dnl notice, this list of conditions and the following disclaimer in the
  12. dnl documentation and/or other materials provided with the distribution.
  13. dnl
  14. dnl - Neither the name of the Xiph.org Foundation nor the names of its
  15. dnl contributors may be used to endorse or promote products derived from
  16. dnl this software without specific prior written permission.
  17. dnl
  18. dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. dnl @synopsis XIPH_C_FIND_ENDIAN
  30. dnl
  31. dnl Determine endian-ness of target processor.
  32. dnl @version 1.1 Mar 03 2002
  33. dnl @author Erik de Castro Lopo <[email protected]>
  34. dnl
  35. dnl Majority written from scratch to replace the standard autoconf macro
  36. dnl AC_C_BIGENDIAN. Only part remaining from the original is the invocation
  37. dnl of the AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[]) macro.
  38. dnl
  39. dnl Find endian-ness in the following way:
  40. dnl 1) Look in <endian.h>.
  41. dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
  42. dnl 3) If 1) and 2) fails and not cross compiling run a test program.
  43. dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
  44. AC_DEFUN([XIPH_C_FIND_ENDIAN],
  45. [AC_CACHE_CHECK(processor byte ordering,
  46. ac_cv_c_byte_order,
  47. # Initialize to unknown
  48. ac_cv_c_byte_order=unknown
  49. if test x$ac_cv_header_endian_h = xyes ; then
  50. # First try <endian.h> which should set BYTE_ORDER.
  51. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  52. #include <endian.h>
  53. #if BYTE_ORDER != LITTLE_ENDIAN
  54. not big endian
  55. #endif
  56. ]], [[return 0 ;]])],[ac_cv_c_byte_order=little
  57. ],[])]
  58. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  59. #include <endian.h>
  60. #if BYTE_ORDER != BIG_ENDIAN
  61. not big endian
  62. #endif
  63. ]], [[return 0 ;]])],[ac_cv_c_byte_order=big
  64. ],[])]
  65. fi
  66. if test $ac_cv_c_byte_order = unknown ; then
  67. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  68. #include <sys/types.h>
  69. #include <sys/param.h>
  70. #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
  71. bogus endian macros
  72. #endif
  73. ]], [[return 0 ;]])],[_au_m4_changequote([,])AC_TRY_LINK([
  74. #include <sys/types.h>
  75. #include <sys/param.h>
  76. #if BYTE_ORDER != LITTLE_ENDIAN
  77. not big endian
  78. #endif
  79. ], return 0 ;,
  80. ac_cv_c_byte_order=little
  81. )
  82. _au_m4_changequote([,])AC_TRY_LINK([
  83. #include <sys/types.h>
  84. #include <sys/param.h>
  85. #if BYTE_ORDER != LITTLE_ENDIAN
  86. not big endian
  87. #endif
  88. ], return 0 ;,
  89. ac_cv_c_byte_order=little
  90. )
  91. ],[])]
  92. fi
  93. if test $ac_cv_c_byte_order = unknown ; then
  94. if test $cross_compiling = yes ; then
  95. # This is the last resort. Try to guess the target processor endian-ness
  96. # by looking at the target CPU type.
  97. [
  98. case "$target_cpu" in
  99. alpha* | i?86* | mipsel* | ia64*)
  100. ac_cv_c_byte_order=little
  101. ;;
  102. m68* | mips* | powerpc* | hppa* | sparc*)
  103. ac_cv_c_byte_order=big
  104. ;;
  105. esac
  106. ]
  107. else
  108. AC_RUN_IFELSE([AC_LANG_SOURCE([[[
  109. int main (void)
  110. { /* Are we little or big endian? From Harbison&Steele. */
  111. union
  112. { long l ;
  113. char c [sizeof (long)] ;
  114. } u ;
  115. u.l = 1 ;
  116. return (u.c [sizeof (long) - 1] == 1);
  117. }
  118. ]]])],[],[ac_cv_c_byte_order=big],[])
  119. AC_RUN_IFELSE([AC_LANG_SOURCE([[[int main (void)
  120. { /* Are we little or big endian? From Harbison&Steele. */
  121. union
  122. { long l ;
  123. char c [sizeof (long)] ;
  124. } u ;
  125. u.l = 1 ;
  126. return (u.c [0] == 1);
  127. }]]])],[],[ac_cv_c_byte_order=little],[])
  128. fi
  129. fi
  130. )
  131. if test $ac_cv_c_byte_order = big ; then
  132. ac_cv_c_big_endian=1
  133. ac_cv_c_little_endian=0
  134. elif test $ac_cv_c_byte_order = little ; then
  135. ac_cv_c_big_endian=0
  136. ac_cv_c_little_endian=1
  137. else
  138. ac_cv_c_big_endian=0
  139. ac_cv_c_little_endian=0
  140. AC_MSG_WARN([[*****************************************************************]])
  141. AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]])
  142. AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]])
  143. AC_MSG_WARN([[*** config.h may need to be hand editied. ]])
  144. AC_MSG_WARN([[*****************************************************************]])
  145. fi
  146. ]
  147. )# XIPH_C_FIND_ENDIAN