"Lars J. Aas" wrote:
> : Does anybody sees a means to compute this at compile time?  Using the
> : same trick as we did for SIZEOF etc.
I did need a cross-compile AC_C_BIGENDIAN once upon a time, so there is a
AC_C_BIGENDIAN_CROSS submitted to the autoconf-archive (hopefully Peter
will update the page some day). The basic idea is to create a binary
from special C-source and "grep" the binary for some pattern. The C-source
has a static-array of integers, so the integer-literals will be pushed in
target-order. Anyone has a better idea?

I think AC_C_BIGENDIAN *should* have a cross-compile check, so
may be one should append such a section to the tail of AC_C_BIGENDIAN.
(the macro AC_C_BIGENDIAN_CROSS is just that).

have fun... and here's the code... 

AC_MSG_CHECKING(whether byte order LOOKS bigendian)
[
cat >conftest.c <<EOF
short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
void _ascii() { char* s = (char*)ascii_mm; s = ascii_ii); }
short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*)ebcdic_ii); }
int main() { _ascii (); _ebcdic (); return 0; }
EOF
] if test -f conftest.c ; then 
     if ${CC-cc} conftest.c -o conftest.o && test -f conftest.o ; then
        if test `grep -l BIGenDianSyS conftest.o` ; then
           echo $ac_n "looks big-endian ... " 1>&AC_FD_MSG
           ac_cv_c_bigendian=yes 
        fi
        if test `grep -l LiTTleEnDian conftest.o` ; then
           echo $ac_n 'looks little-endian ... ' 1>&AC_FD_MSG
           ac_cv_c_bigendian=no
        fi
     fi
  fi
AC_MSG_RESULT($ac_cv_c_bigendian)

Reply via email to