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