1 dnl Copyright (C) 2012-2016 Xiph.org Foundation
3 dnl Redistribution and use in source and binary forms, with or without
4 dnl modification, are permitted provided that the following conditions
7 dnl - Redistributions of source code must retain the above copyright
8 dnl notice, this list of conditions and the following disclaimer.
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.
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.
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.
31 dnl @synopsis XIPH_C_FIND_ENDIAN
33 dnl Determine endian-ness of target processor.
34 dnl @version 1.1 Mar 03 2002
35 dnl @author Erik de Castro Lopo <erikd@mega-nerd.com>
37 dnl Majority written from scratch to replace the standard autoconf macro
38 dnl AC_C_BIGENDIAN. Only part remaining from the original is the invocation
39 dnl of the AC_TRY_RUN macro.
41 dnl Find endian-ness in the following way:
42 dnl 1) Look in <endian.h>.
43 dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
44 dnl 3) If 1) and 2) fails and not cross compiling run a test program.
45 dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
47 AC_DEFUN([XIPH_C_FIND_ENDIAN],
48 [AC_CACHE_CHECK(processor byte ordering,
51 # Initialize to unknown
52 ac_cv_c_byte_order=unknown
54 if test x$ac_cv_header_endian_h = xyes ; then
56 # First try <endian.h> which should set BYTE_ORDER.
60 #if BYTE_ORDER != LITTLE_ENDIAN
64 ac_cv_c_byte_order=little
69 #if BYTE_ORDER != BIG_ENDIAN
73 ac_cv_c_byte_order=big
78 if test $ac_cv_c_byte_order = unknown ; then
81 #include <sys/types.h>
82 #include <sys/param.h>
83 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
89 #include <sys/types.h>
90 #include <sys/param.h>
91 #if BYTE_ORDER != LITTLE_ENDIAN
95 ac_cv_c_byte_order=little
99 #include <sys/types.h>
100 #include <sys/param.h>
101 #if BYTE_ORDER != LITTLE_ENDIAN
105 ac_cv_c_byte_order=little
112 if 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.
117 case "$target_cpu" in
118 alpha* | i?86* | mipsel* | ia64*)
119 ac_cv_c_byte_order=little
122 m68* | mips* | powerpc* | hppa* | sparc*)
123 ac_cv_c_byte_order=big
132 { /* Are we little or big endian? From Harbison&Steele. */
135 char c [sizeof (long)] ;
138 return (u.c [sizeof (long) - 1] == 1);
140 ]], , ac_cv_c_byte_order=big,
145 { /* Are we little or big endian? From Harbison&Steele. */
148 char c [sizeof (long)] ;
151 return (u.c [0] == 1);
152 }]], , ac_cv_c_byte_order=little,
159 if test $ac_cv_c_byte_order = big ; then
161 ac_cv_c_little_endian=0
162 elif test $ac_cv_c_byte_order = little ; then
164 ac_cv_c_little_endian=1
167 ac_cv_c_little_endian=0
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([[*****************************************************************]])
177 )# XIPH_C_FIND_ENDIAN