History

Use AC_C_BIGENDIAN for detecting $HOST endianness

* AC_C_BIGENDIAN is fully cross-compile aware

David Seifert committed 9 years ago

Commit d2e7cb51 parent ca40d093 files · +13 −162Browse files

Unified · Split

3 files
  1. Win32/config.h +2 −2
  2. configure.ac +11 −5
  3. m4/endian.m4 +0 −155
Win32/config.h+2−2
@@ -43,10 +43,10 @@ · 42 unmodified lines
43/* Target processor clips on positive float to int conversion. */43/* Target processor clips on positive float to int conversion. */
44#define CPU_CLIPS_POSITIVE 044#define CPU_CLIPS_POSITIVE 0
45 45
46/* Target processor is big endian. */46/* Host processor is big endian. */
47#define CPU_IS_BIG_ENDIAN 047#define CPU_IS_BIG_ENDIAN 0
48 48
49/* Target processor is little endian. */49/* Host processor is little endian. */
50#define CPU_IS_LITTLE_ENDIAN 150#define CPU_IS_LITTLE_ENDIAN 1
51 51
52/* Set to 1 to enable debugging. */52/* Set to 1 to enable debugging. */
configure.ac+11−5
@@ -112,12 +112,18 @@ AC_CHECK_SIZEOF(double,8) · 111 unmodified lines
112#====================================================================================112#====================================================================================
113# Determine endian-ness of target processor.113# Determine endian-ness of target processor.
114 114
115AC_C_FIND_ENDIAN115AC_C_BIGENDIAN([
116 dnl big-endian
117 ac_cv_c_big_endian=1
118 ac_cv_c_little_endian=0
119 ], [
120 dnl little-endian
121 ac_cv_c_big_endian=0
122 ac_cv_c_little_endian=1
123 ])
116 124
117AC_DEFINE_UNQUOTED(CPU_IS_BIG_ENDIAN, ${ac_cv_c_big_endian},125AC_DEFINE_UNQUOTED([CPU_IS_BIG_ENDIAN], [${ac_cv_c_big_endian}], [Host processor is big endian.])
118 [Target processor is big endian.])126AC_DEFINE_UNQUOTED([CPU_IS_LITTLE_ENDIAN], [${ac_cv_c_little_endian}], [Host processor is little endian.])
119AC_DEFINE_UNQUOTED(CPU_IS_LITTLE_ENDIAN, ${ac_cv_c_little_endian},
120 [Target processor is little endian.])
121 127
122#====================================================================================128#====================================================================================
123# Check for functions.129# Check for functions.
m4/endian.m4+0−155
@@ -1,155 +0,0 @@
1dnl @synopsis AC_C_FIND_ENDIAN
2dnl
3dnl Determine endian-ness of target processor.
4dnl @version 1.1 Mar 03 2002
5dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
6dnl
7dnl Majority written from scratch to replace the standard autoconf macro
8dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation
9dnl of the AC_TRY_RUN macro.
10dnl
11dnl Permission to use, copy, modify, distribute, and sell this file for any
12dnl purpose is hereby granted without fee, provided that the above copyright
13dnl and this permission notice appear in all copies. No representations are
14dnl made about the suitability of this software for any purpose. It is
15dnl provided "as is" without express or implied warranty.
16
17dnl Find endian-ness in the following way:
18dnl 1) Look in <endian.h>.
19dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
20dnl 3) If 1) and 2) fails and not cross compiling run a test program.
21dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
22
23AC_DEFUN([AC_C_FIND_ENDIAN],
24[AC_CACHE_CHECK(processor byte ordering,
25 ac_cv_c_byte_order,
26
27# Initialize to unknown
28ac_cv_c_byte_order=unknown
29
30if 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
54if 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
88if 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
135if test $ac_cv_c_byte_order = big ; then
136 ac_cv_c_big_endian=1
137 ac_cv_c_little_endian=0
138elif test $ac_cv_c_byte_order = little ; then
139 ac_cv_c_big_endian=0
140 ac_cv_c_little_endian=1
141else
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)# AC_C_FIND_ENDIAN
154
155

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t