2 dnl $Heimdal: krb-bigendian.m4 15456 2005-06-16 21:04:43Z lha $
6 dnl check if this computer is little or big-endian
7 dnl if we can figure it out at compile-time then don't define the cpp symbol
8 dnl otherwise test for it and define it. also allow options for overriding
9 dnl it when cross-compiling
11 AC_DEFUN([KRB_C_BIGENDIAN], [
12 AC_ARG_ENABLE(bigendian,
13 AS_HELP_STRING([--enable-bigendian],[the target is big endian]),
14 krb_cv_c_bigendian=yes)
15 AC_ARG_ENABLE(littleendian,
16 AS_HELP_STRING([--enable-littleendian],[the target is little endian]),
17 krb_cv_c_bigendian=no)
18 AC_CACHE_CHECK([whether byte order is known at compile time],
19 krb_cv_c_bigendian_compile,
20 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
21 #include <sys/types.h>
22 #include <sys/param.h>
23 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
25 #endif]])],[krb_cv_c_bigendian_compile=yes],[krb_cv_c_bigendian_compile=no])])
26 AC_CACHE_CHECK(whether byte ordering is bigendian, krb_cv_c_bigendian,[
27 if test "$krb_cv_c_bigendian_compile" = "yes"; then
28 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #if BYTE_ORDER != BIG_ENDIAN
33 #endif]])],[krb_cv_c_bigendian=yes],[krb_cv_c_bigendian=no])
35 AC_RUN_IFELSE([AC_LANG_SOURCE([[main (int argc, char **argv) {
36 /* Are we little or big endian? From Harbison&Steele. */
40 char c[sizeof (long)];
43 exit (u.c[sizeof (long) - 1] == 1);
44 }]])],[krb_cv_c_bigendian=no],[krb_cv_c_bigendian=yes],
45 [AC_MSG_ERROR([specify either --enable-bigendian or --enable-littleendian])])
48 if test "$krb_cv_c_bigendian" = "yes"; then
49 AC_DEFINE(WORDS_BIGENDIAN, 1, [define if target is big endian])dnl
51 if test "$krb_cv_c_bigendian_compile" = "yes"; then
52 AC_DEFINE(ENDIANESS_IN_SYS_PARAM_H, 1, [define if sys/param.h defines the endiness])dnl
55 #if ENDIANESS_IN_SYS_PARAM_H
56 # include <sys/types.h>
57 # include <sys/param.h>
58 # if BYTE_ORDER == BIG_ENDIAN
59 # define WORDS_BIGENDIAN 1