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