source: trunk/m4/ac_c_bigendian_cross.m4 @ 12

Revision 12, 3.0 KB checked in by mmamonski, 9 years ago (diff)

version 1.0.7 release candidate

  • Property svn:keywords set to Id
Line 
1dnl @synopsis AC_C_BIGENDIAN_CROSS
2dnl
3dnl Check endianess even when crosscompiling (partially based on the
4dnl original AC_C_BIGENDIAN).
5dnl
6dnl The implementation will create a binary, but instead of running the
7dnl binary it will be grep'ed for some symbols that differ for
8dnl different endianess of the binary.
9dnl
10dnl NOTE: The upcoming autoconf 2.53 does include the idea of this
11dnl macro, what makes it superfluous by then.
12dnl
13dnl @category CrossCompilation
14dnl @author Guido Draheim <guidod@gmx.de>
15dnl @version 2002-03-18
16dnl @license GPLWithACException
17
18AC_DEFUN([AC_C_BIGENDIAN_CROSS],
19[AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
20[ac_cv_c_bigendian=unknown
21# See if sys/param.h defines the BYTE_ORDER macro.
22AC_TRY_COMPILE([#include <sys/types.h>
23#include <sys/param.h>], [
24#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
25 bogus endian macros
26#endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
27AC_TRY_COMPILE([#include <sys/types.h>
28#include <sys/param.h>], [
29#if BYTE_ORDER != BIG_ENDIAN
30 not big endian
31#endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
32if test $ac_cv_c_bigendian = unknown; then
33AC_TRY_RUN([main () {
34  /* Are we little or big endian?  From Harbison&Steele.  */
35  union
36  {
37    long l;
38    char c[sizeof (long)];
39  } u;
40  u.l = 1;
41  exit (u.c[sizeof (long) - 1] == 1);
42}], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes,
43[ echo $ac_n "cross-compiling... " 2>&AC_FD_MSG ])
44fi])
45if test $ac_cv_c_bigendian = unknown; then
46AC_MSG_CHECKING(to probe for byte ordering)
47[
48cat >conftest.c <<EOF
49short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
50short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
51void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; }
52short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
53short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
54void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; }
55int main() { _ascii (); _ebcdic (); return 0; }
56EOF
57] if test -f conftest.c ; then
58     if ${CC-cc} -c conftest.c -o conftest.o && test -f conftest.o ; then
59        if test `grep -l BIGenDianSyS conftest.o` ; then
60           echo $ac_n ' big endian probe OK, ' 1>&AC_FD_MSG
61           ac_cv_c_bigendian=yes
62        fi
63        if test `grep -l LiTTleEnDian conftest.o` ; then
64           echo $ac_n ' little endian probe OK, ' 1>&AC_FD_MSG
65           if test $ac_cv_c_bigendian = yes ; then
66            ac_cv_c_bigendian=unknown;
67           else
68            ac_cv_c_bigendian=no
69           fi
70        fi
71        echo $ac_n 'guessing bigendian ...  ' >&AC_FD_MSG
72     fi
73  fi
74AC_MSG_RESULT($ac_cv_c_bigendian)
75fi
76if test $ac_cv_c_bigendian = yes; then
77  AC_DEFINE(WORDS_BIGENDIAN, 1, [whether byteorder is bigendian])
78  BYTEORDER=4321
79else
80  BYTEORDER=1234
81fi
82AC_DEFINE_UNQUOTED(BYTEORDER, $BYTEORDER, [1234 = LIL_ENDIAN, 4321 = BIGENDIAN])
83if test $ac_cv_c_bigendian = unknown; then
84  AC_MSG_ERROR(unknown endianess - sorry, please pre-set ac_cv_c_bigendian)
85fi
86])
Note: See TracBrowser for help on using the repository browser.