| 1 | AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], | 
|---|
| 2 | [changequote(<<, >>)dnl | 
|---|
| 3 | dnl The name to #define. | 
|---|
| 4 | define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl | 
|---|
| 5 | dnl The cache variable name. | 
|---|
| 6 | define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl | 
|---|
| 7 | changequote([, ])dnl | 
|---|
| 8 | AC_MSG_CHECKING(size of $1) | 
|---|
| 9 | AC_CACHE_VAL(AC_CV_NAME, | 
|---|
| 10 | [for ac_size in 4 8 1 2 16 12 $2 ; do # List sizes in rough order of prevalence. | 
|---|
| 11 | AC_TRY_COMPILE([#include "confdefs.h" | 
|---|
| 12 | #include <sys/types.h> | 
|---|
| 13 | $2 | 
|---|
| 14 | ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size) | 
|---|
| 15 | if test x$AC_CV_NAME != x ; then break; fi | 
|---|
| 16 | done | 
|---|
| 17 | ]) | 
|---|
| 18 | if test x$AC_CV_NAME = x ; then | 
|---|
| 19 | AC_MSG_ERROR([cannot determine a size for $1]) | 
|---|
| 20 | fi | 
|---|
| 21 | AC_MSG_RESULT($AC_CV_NAME) | 
|---|
| 22 | AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) | 
|---|
| 23 | undefine([AC_TYPE_NAME])dnl | 
|---|
| 24 | undefine([AC_CV_NAME])dnl | 
|---|
| 25 | ]) | 
|---|
| 26 |  | 
|---|
| 27 | AC_DEFUN([AC_C_BIGENDIAN_CROSS], | 
|---|
| 28 | [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian, | 
|---|
| 29 | [ac_cv_c_bigendian=unknown | 
|---|
| 30 | # See if sys/param.h defines the BYTE_ORDER macro. | 
|---|
| 31 | AC_TRY_COMPILE([#include <sys/types.h> | 
|---|
| 32 | #include <sys/param.h>], [ | 
|---|
| 33 | #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN | 
|---|
| 34 | bogus endian macros | 
|---|
| 35 | #endif], [# It does; now see whether it defined to BIG_ENDIAN or not. | 
|---|
| 36 | AC_TRY_COMPILE([#include <sys/types.h> | 
|---|
| 37 | #include <sys/param.h>], [ | 
|---|
| 38 | #if BYTE_ORDER != BIG_ENDIAN | 
|---|
| 39 | not big endian | 
|---|
| 40 | #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)]) | 
|---|
| 41 | if test $ac_cv_c_bigendian = unknown; then | 
|---|
| 42 | AC_TRY_RUN([main () { | 
|---|
| 43 | /* Are we little or big endian?  From Harbison&Steele.  */ | 
|---|
| 44 | union | 
|---|
| 45 | { | 
|---|
| 46 | long l; | 
|---|
| 47 | char c[sizeof (long)]; | 
|---|
| 48 | } u; | 
|---|
| 49 | u.l = 1; | 
|---|
| 50 | exit (u.c[sizeof (long) - 1] == 1); | 
|---|
| 51 | }], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes, | 
|---|
| 52 | [ echo $ac_n "cross-compiling... " 2>&AC_FD_MSG ]) | 
|---|
| 53 | fi]) | 
|---|
| 54 | if test $ac_cv_c_bigendian = unknown; then | 
|---|
| 55 | AC_MSG_CHECKING(to probe for byte ordering) | 
|---|
| 56 | [ | 
|---|
| 57 | cat >conftest.c <<EOF | 
|---|
| 58 | short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; | 
|---|
| 59 | short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; | 
|---|
| 60 | void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; } | 
|---|
| 61 | short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; | 
|---|
| 62 | short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; | 
|---|
| 63 | void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; } | 
|---|
| 64 | int main() { _ascii (); _ebcdic (); return 0; } | 
|---|
| 65 | EOF | 
|---|
| 66 | ] if test -f conftest.c ; then | 
|---|
| 67 | if ${CC-cc} ${CFLAGS} conftest.c -o conftest.o && test -f conftest.o ; then | 
|---|
| 68 | if test `grep -l BIGenDianSyS conftest.o` ; then | 
|---|
| 69 | echo $ac_n ' big endian probe OK, ' 1>&AC_FD_MSG | 
|---|
| 70 | ac_cv_c_bigendian=yes | 
|---|
| 71 | fi | 
|---|
| 72 | if test `grep -l LiTTleEnDian conftest.o` ; then | 
|---|
| 73 | echo $ac_n ' little endian probe OK, ' 1>&AC_FD_MSG | 
|---|
| 74 | if test $ac_cv_c_bigendian = yes ; then | 
|---|
| 75 | ac_cv_c_bigendian=unknown; | 
|---|
| 76 | else | 
|---|
| 77 | ac_cv_c_bigendian=no | 
|---|
| 78 | fi | 
|---|
| 79 | fi | 
|---|
| 80 | echo $ac_n 'guessing bigendian ...  ' >&AC_FD_MSG | 
|---|
| 81 | fi | 
|---|
| 82 | fi | 
|---|
| 83 | AC_MSG_RESULT($ac_cv_c_bigendian) | 
|---|
| 84 | fi | 
|---|
| 85 | if test $ac_cv_c_bigendian = yes; then | 
|---|
| 86 | AC_DEFINE(WORDS_BIGENDIAN, 1, [whether byteorder is bigendian]) | 
|---|
| 87 | AC_DEFINE(HOST_WORDS_BIG_ENDIAN, 1, | 
|---|
| 88 | [Define if the host machine stores words of multi-word integers in | 
|---|
| 89 | big-endian order.]) | 
|---|
| 90 | BYTEORDER=4321 | 
|---|
| 91 | else | 
|---|
| 92 | BYTEORDER=1234 | 
|---|
| 93 | fi | 
|---|
| 94 | AC_DEFINE_UNQUOTED(BYTEORDER, $BYTEORDER, [1234 = LIL_ENDIAN, 4321 = BIGENDIAN]) | 
|---|
| 95 | if test $ac_cv_c_bigendian = unknown; then | 
|---|
| 96 | AC_MSG_ERROR(unknown endianess - sorry, please pre-set ac_cv_c_bigendian) | 
|---|
| 97 | fi | 
|---|
| 98 | ]) | 
|---|