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
4343 /* Target processor clips on positive float to int conversion. */
4444 #define CPU_CLIPS_POSITIVE 0
4545
46−/* Target processor is big endian. */
46+/* Host processor is big endian. */
4747 #define CPU_IS_BIG_ENDIAN 0
4848
49−/* Target processor is little endian. */
49+/* Host processor is little endian. */
5050 #define CPU_IS_LITTLE_ENDIAN 1
5151
5252 /* Set to 1 to enable debugging. */
configure.ac+11−5
@@ -112,12 +112,18 @@ AC_CHECK_SIZEOF(double,8) · 111 unmodified lines
112112 #====================================================================================
113113 # Determine endian-ness of target processor.
114114
115−AC_C_FIND_ENDIAN
115+AC_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+ ])
116124
117−AC_DEFINE_UNQUOTED(CPU_IS_BIG_ENDIAN, ${ac_cv_c_big_endian},
118− [Target processor is big endian.])
119−AC_DEFINE_UNQUOTED(CPU_IS_LITTLE_ENDIAN, ${ac_cv_c_little_endian},
120− [Target processor is little endian.])
125+AC_DEFINE_UNQUOTED([CPU_IS_BIG_ENDIAN], [${ac_cv_c_big_endian}], [Host processor is big endian.])
126+AC_DEFINE_UNQUOTED([CPU_IS_LITTLE_ENDIAN], [${ac_cv_c_little_endian}], [Host processor is little endian.])
121127
122128 #====================================================================================
123129 # Check for functions.
m4/endian.m4+0−155
@@ -1,155 +0,0 @@
1−dnl @synopsis AC_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([AC_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−)# 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