1dnl Copyright (C) 2012-2016 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 <erikd@mega-nerd.com> 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_TRY_RUN 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_TRY_LINK([ 59 #include <endian.h> 60 #if BYTE_ORDER != LITTLE_ENDIAN 61 not big endian 62 #endif 63 ], return 0 ;, 64 ac_cv_c_byte_order=little 65 )] 66 67 [AC_TRY_LINK([ 68 #include <endian.h> 69 #if BYTE_ORDER != BIG_ENDIAN 70 not big endian 71 #endif 72 ], return 0 ;, 73 ac_cv_c_byte_order=big 74 )] 75 76 fi 77 78if test $ac_cv_c_byte_order = unknown ; then 79 80 [AC_TRY_LINK([ 81 #include <sys/types.h> 82 #include <sys/param.h> 83 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN 84 bogus endian macros 85 #endif 86 ], return 0 ;, 87 88 [AC_TRY_LINK([ 89 #include <sys/types.h> 90 #include <sys/param.h> 91 #if BYTE_ORDER != LITTLE_ENDIAN 92 not big endian 93 #endif 94 ], return 0 ;, 95 ac_cv_c_byte_order=little 96 )] 97 98 [AC_TRY_LINK([ 99 #include <sys/types.h> 100 #include <sys/param.h> 101 #if BYTE_ORDER != LITTLE_ENDIAN 102 not big endian 103 #endif 104 ], return 0 ;, 105 ac_cv_c_byte_order=little 106 )] 107 108 )] 109 110 fi 111 112if test $ac_cv_c_byte_order = unknown ; then 113 if test $cross_compiling = yes ; then 114 # This is the last resort. Try to guess the target processor endian-ness 115 # by looking at the target CPU type. 116 [ 117 case "$target_cpu" in 118 alpha* | i?86* | mipsel* | ia64*) 119 ac_cv_c_byte_order=little 120 ;; 121 122 m68* | mips* | powerpc* | hppa* | sparc*) 123 ac_cv_c_byte_order=big 124 ;; 125 126 esac 127 ] 128 else 129 AC_TRY_RUN( 130 [[ 131 int main (void) 132 { /* Are we little or big endian? From Harbison&Steele. */ 133 union 134 { long l ; 135 char c [sizeof (long)] ; 136 } u ; 137 u.l = 1 ; 138 return (u.c [sizeof (long) - 1] == 1); 139 } 140 ]], , ac_cv_c_byte_order=big, 141 ) 142 143 AC_TRY_RUN( 144 [[int main (void) 145 { /* Are we little or big endian? From Harbison&Steele. */ 146 union 147 { long l ; 148 char c [sizeof (long)] ; 149 } u ; 150 u.l = 1 ; 151 return (u.c [0] == 1); 152 }]], , ac_cv_c_byte_order=little, 153 ) 154 fi 155 fi 156 157) 158 159if test $ac_cv_c_byte_order = big ; then 160 ac_cv_c_big_endian=1 161 ac_cv_c_little_endian=0 162elif test $ac_cv_c_byte_order = little ; then 163 ac_cv_c_big_endian=0 164 ac_cv_c_little_endian=1 165else 166 ac_cv_c_big_endian=0 167 ac_cv_c_little_endian=0 168 169 AC_MSG_WARN([[*****************************************************************]]) 170 AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]]) 171 AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]]) 172 AC_MSG_WARN([[*** config.h may need to be hand editied. ]]) 173 AC_MSG_WARN([[*****************************************************************]]) 174 fi 175 176] 177)# XIPH_C_FIND_ENDIAN 178