1f59d82ffSelricdnl
2*fcfd9267Selricdnl Id
3f59d82ffSelricdnl
4f59d82ffSelric
5f59d82ffSelricdnl check if this computer is little or big-endian
6f59d82ffSelricdnl if we can figure it out at compile-time then don't define the cpp symbol
7f59d82ffSelricdnl otherwise test for it and define it.  also allow options for overriding
8f59d82ffSelricdnl it when cross-compiling
9f59d82ffSelric
10f59d82ffSelricAC_DEFUN([KRB_C_BIGENDIAN], [
11f59d82ffSelricAC_ARG_ENABLE(bigendian,
12f59d82ffSelric	AS_HELP_STRING([--enable-bigendian],[the target is big endian]),
13f59d82ffSelrickrb_cv_c_bigendian=yes)
14f59d82ffSelricAC_ARG_ENABLE(littleendian,
15f59d82ffSelric	AS_HELP_STRING([--enable-littleendian],[the target is little endian]),
16f59d82ffSelrickrb_cv_c_bigendian=no)
17f59d82ffSelricAC_CACHE_CHECK([whether byte order is known at compile time],
18f59d82ffSelrickrb_cv_c_bigendian_compile,
19f59d82ffSelric[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
20f59d82ffSelric#include <sys/types.h>
21f59d82ffSelric#include <sys/param.h>
22f59d82ffSelric#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
23f59d82ffSelric bogus endian macros
24f59d82ffSelric#endif]])],[krb_cv_c_bigendian_compile=yes],[krb_cv_c_bigendian_compile=no])])
25f59d82ffSelricAC_CACHE_CHECK(whether byte ordering is bigendian, krb_cv_c_bigendian,[
26f59d82ffSelric  if test "$krb_cv_c_bigendian_compile" = "yes"; then
27f59d82ffSelric    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
28f59d82ffSelric#include <sys/types.h>
29f59d82ffSelric#include <sys/param.h>
30f59d82ffSelric#if BYTE_ORDER != BIG_ENDIAN
31f59d82ffSelric  not big endian
32f59d82ffSelric#endif]])],[krb_cv_c_bigendian=yes],[krb_cv_c_bigendian=no])
33f59d82ffSelric  else
34f59d82ffSelric    AC_RUN_IFELSE([AC_LANG_SOURCE([[main (int argc, char **argv) {
35f59d82ffSelric      /* Are we little or big endian?  From Harbison&Steele.  */
36f59d82ffSelric      union
37f59d82ffSelric      {
38f59d82ffSelric	long l;
39f59d82ffSelric	char c[sizeof (long)];
40f59d82ffSelric    } u;
41f59d82ffSelric    u.l = 1;
42f59d82ffSelric    exit (u.c[sizeof (long) - 1] == 1);
43f59d82ffSelric  }]])],[krb_cv_c_bigendian=no],[krb_cv_c_bigendian=yes],
44f59d82ffSelric  [AC_MSG_ERROR([specify either --enable-bigendian or --enable-littleendian])])
45f59d82ffSelric  fi
46f59d82ffSelric])
47f59d82ffSelricif test "$krb_cv_c_bigendian" = "yes"; then
48f59d82ffSelric  AC_DEFINE(WORDS_BIGENDIAN, 1, [define if target is big endian])dnl
49f59d82ffSelricfi
50f59d82ffSelricif test "$krb_cv_c_bigendian_compile" = "yes"; then
51f59d82ffSelric  AC_DEFINE(ENDIANESS_IN_SYS_PARAM_H, 1, [define if sys/param.h defines the endiness])dnl
52f59d82ffSelricfi
53f59d82ffSelricAH_BOTTOM([
54f59d82ffSelric#ifdef ENDIANESS_IN_SYS_PARAM_H
55f59d82ffSelric#  include <sys/types.h>
56f59d82ffSelric#  include <sys/param.h>
57f59d82ffSelric#  if BYTE_ORDER == BIG_ENDIAN
58f59d82ffSelric#  define WORDS_BIGENDIAN 1
59f59d82ffSelric#  endif
60f59d82ffSelric#endif
61f59d82ffSelric])
62f59d82ffSelric])
63