]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/autoconf/c.m4 (AC_C_BIGENDIAN): Guess endianness by grep'ing
authorAlexandre Duret-Lutz <adl@gnu.org>
Sun, 12 Aug 2001 12:22:29 +0000 (12:22 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Sun, 12 Aug 2001 12:22:29 +0000 (12:22 +0000)
magic values from an object file when cross-compiling.
Based on code by Guido Draheim <Guido.Draheim@gmx.de>.

ChangeLog
NEWS
THANKS
lib/autoconf/c.m4

index 9b36a2c40e13c491365ce51c4d8f2faa13eba9a8..618fae766fc73330dc162fa207444b386ebb21f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-08-11  Alexandre Duret-Lutz  <duret_g@epita.fr>
+
+       * lib/autoconf/c.m4 (AC_C_BIGENDIAN): Guess endianness by grep'ing
+       magic values from an object file when cross-compiling.
+       Based on code by Guido Draheim <Guido.Draheim@gmx.de>.
+
 2001-08-10  Akim Demaille  <akim@epita.fr>
 
        * bin/autom4te.in (&handle_output): Don't use `grep' with side
diff --git a/NEWS b/NEWS
index d41b3b0a1f55d8fd14c5dc9d41eb86a60fae0041..933f8de35aed322de9c8c1976f9f9139e0c7313d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@
 - --force, -f
 ** Bug fixes
 - The top level $prefix is propagated to the AC_CONFIG_SUBDIRS configures.
+** C Macros
+- AC_C_BIGENDIAN supports the cross-compiling case.
 \f
 * Major changes in Autoconf 2.52
 ** Documentation
diff --git a/THANKS b/THANKS
index bd43c27f5e56b7f32b1131c834ed4de207c8c627..f009aba4e80b6e14ee8cbf0333b8652be04a32d6 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -56,6 +56,7 @@ Godmar Back                 gback@cs.utah.edu
 Gordon Matzigkeit           gord@trick.fig.org
 Graham Jenkins              c714553@vus415.telstra.com.au
 Greg A. Woods               woods@weird.com
+Guido Draheim               Guido.Draheim@gmx.de
 Guido Flohr                 gufl0000@stud.uni-sb.de
 Guillermo Gomez             gomez@mi.uni-erlangen.de
 Hans Olsson                 Hans.Olsson@dna.lth.se
index ffcc7dae076aaa4df150e734b85975255a2a1905..7cd84d95dfc9dd7406d576f78049079868c6d8a0 100644 (file)
@@ -832,8 +832,7 @@ fi
 # --------------
 AC_DEFUN([AC_C_BIGENDIAN],
 [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
-[ac_cv_c_bigendian=unknown
-# See if sys/param.h defines the BYTE_ORDER macro.
+[# See if sys/param.h defines the BYTE_ORDER macro.
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
 #include <sys/param.h>
 ],
@@ -847,9 +846,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
 ], [#if BYTE_ORDER != BIG_ENDIAN
  not big endian
 #endif
-])],               [ac_cv_c_bigendian=yes],
-                   [ac_cv_c_bigendian=no])])
-if test $ac_cv_c_bigendian = unknown; then
+])], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=no])],
+[# It does not; compile a test program.
 AC_TRY_RUN(
 [int
 main ()
@@ -862,13 +860,39 @@ main ()
   } u;
   u.l = 1;
   exit (u.c[sizeof (long) - 1] == 1);
-}], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes)
-fi])
-if test $ac_cv_c_bigendian = yes; then
-  AC_DEFINE(WORDS_BIGENDIAN, 1,
-            [Define if your processor stores words with the most significant
-             byte first (like Motorola and SPARC, unlike Intel and VAX).])
+}], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes],
+[# try to guess the endianess by grep'ing values into an object file
+  ac_cv_c_bigendian=unknown
+  AC_COMPILE_IFELSE(
+[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 = (char *) 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; }],
+[if test `grep -l BIGenDianSyS conftest.$ac_objext` ; then
+  ac_cv_c_bigendian=yes
 fi
+if test `grep -l LiTTleEnDian conftest.$ac_objext` ; then
+  if test "$ac_cv_c_bigendian" = unknown; then
+    ac_cv_c_bigendian=no
+  else
+    # finding both strings is unlikely to happen, but who knows?
+    ac_cv_c_bigendian=unknown
+  fi
+fi])])])])
+case $ac_cv_c_bigendian in
+  yes)
+    AC_DEFINE(WORDS_BIGENDIAN, 1,
+             [Define if your processor stores words with the most significant
+              byte first (like Motorola and SPARC, unlike Intel and VAX).]);;
+  no)
+    ;;
+  *)
+    AC_MSG_ERROR([unknown endianess
+presetting ac_cv_c_bigendian=no (or yes) will help]);;
+esac
 ])# AC_C_BIGENDIAN