libsndfile source files.
[Faustine.git] / interpretor / libsndfile-1.0.25 / M4 / endian.m4
1 dnl @synopsis MN_C_FIND_ENDIAN
2 dnl
3 dnl Determine endian-ness of target processor.
4 dnl @version 1.1 Mar 03 2002
5 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
6 dnl
7 dnl Majority written from scratch to replace the standard autoconf macro
8 dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation
9 dnl of the AC_TRY_RUN macro.
10 dnl
11 dnl Permission to use, copy, modify, distribute, and sell this file for any
12 dnl purpose is hereby granted without fee, provided that the above copyright
13 dnl and this permission notice appear in all copies. No representations are
14 dnl made about the suitability of this software for any purpose. It is
15 dnl provided "as is" without express or implied warranty.
16
17 dnl Find endian-ness in the following way:
18 dnl 1) Look in <endian.h>.
19 dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
20 dnl 3) If 1) and 2) fails and not cross compiling run a test program.
21 dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
22
23 AC_DEFUN([MN_C_FIND_ENDIAN],
24 [AC_CACHE_CHECK(processor byte ordering,
25 ac_cv_c_byte_order,
26
27 # Initialize to unknown
28 ac_cv_c_byte_order=unknown
29
30 if test x$ac_cv_header_endian_h = xyes ; then
31
32 # First try <endian.h> which should set BYTE_ORDER.
33
34 [AC_TRY_LINK([
35 #include <endian.h>
36 #if BYTE_ORDER != LITTLE_ENDIAN
37 not big endian
38 #endif
39 ], return 0 ;,
40 ac_cv_c_byte_order=little
41 )]
42
43 [AC_TRY_LINK([
44 #include <endian.h>
45 #if BYTE_ORDER != BIG_ENDIAN
46 not big endian
47 #endif
48 ], return 0 ;,
49 ac_cv_c_byte_order=big
50 )]
51
52 fi
53
54 if test $ac_cv_c_byte_order = unknown ; then
55
56 [AC_TRY_LINK([
57 #include <sys/types.h>
58 #include <sys/param.h>
59 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
60 bogus endian macros
61 #endif
62 ], return 0 ;,
63
64 [AC_TRY_LINK([
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #if BYTE_ORDER != LITTLE_ENDIAN
68 not big endian
69 #endif
70 ], return 0 ;,
71 ac_cv_c_byte_order=little
72 )]
73
74 [AC_TRY_LINK([
75 #include <sys/types.h>
76 #include <sys/param.h>
77 #if BYTE_ORDER != LITTLE_ENDIAN
78 not big endian
79 #endif
80 ], return 0 ;,
81 ac_cv_c_byte_order=little
82 )]
83
84 )]
85
86 fi
87
88 if test $ac_cv_c_byte_order = unknown ; then
89 if test $cross_compiling = yes ; then
90 # This is the last resort. Try to guess the target processor endian-ness
91 # by looking at the target CPU type.
92 [
93 case "$target_cpu" in
94 alpha* | i?86* | mipsel* | ia64*)
95 ac_cv_c_byte_order=little
96 ;;
97
98 m68* | mips* | powerpc* | hppa* | sparc*)
99 ac_cv_c_byte_order=big
100 ;;
101
102 esac
103 ]
104 else
105 AC_TRY_RUN(
106 [[
107 int main (void)
108 { /* Are we little or big endian? From Harbison&Steele. */
109 union
110 { long l ;
111 char c [sizeof (long)] ;
112 } u ;
113 u.l = 1 ;
114 return (u.c [sizeof (long) - 1] == 1);
115 }
116 ]], , ac_cv_c_byte_order=big,
117 )
118
119 AC_TRY_RUN(
120 [[int main (void)
121 { /* Are we little or big endian? From Harbison&Steele. */
122 union
123 { long l ;
124 char c [sizeof (long)] ;
125 } u ;
126 u.l = 1 ;
127 return (u.c [0] == 1);
128 }]], , ac_cv_c_byte_order=little,
129 )
130 fi
131 fi
132
133 )
134
135 if test $ac_cv_c_byte_order = big ; then
136 ac_cv_c_big_endian=1
137 ac_cv_c_little_endian=0
138 elif test $ac_cv_c_byte_order = little ; then
139 ac_cv_c_big_endian=0
140 ac_cv_c_little_endian=1
141 else
142 ac_cv_c_big_endian=0
143 ac_cv_c_little_endian=0
144
145 AC_MSG_WARN([[*****************************************************************]])
146 AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]])
147 AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]])
148 AC_MSG_WARN([[*** src/config.h may need to be hand editied. ]])
149 AC_MSG_WARN([[*****************************************************************]])
150 fi
151
152 ]
153 )# MN_C_FIND_ENDIAN
154
155