Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / cf / bigendian.m4
CommitLineData
805e021f
CE
1dnl
2dnl $Id$
3dnl
4
5dnl check if this computer is little or big-endian
6dnl if we can figure it out at compile-time then don't define the cpp symbol
7dnl otherwise test for it and define it. also allow options for overriding
8dnl it when cross-compiling
9
10AC_DEFUN([OPENAFS_CHECK_BIGENDIAN], [
11AC_ARG_ENABLE([bigendian],
12 [AS_HELP_STRING([--enable-bigendian], [the target is big endian])],
13 [openafs_cv_c_bigendian=yes])
14AC_ARG_ENABLE([littleendian],
15 [AS_HELP_STRING([--enable-littleendian], [the target is little endian])],
16 [openafs_cv_c_bigendian=no])
17
18AC_CACHE_CHECK(whether byte order is known at compile time,
19openafs_cv_c_bigendian_compile,
20[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
21#include <sys/types.h>
22#include <sys/param.h>]], [[
23#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
24 bogus endian macros
25#endif]])],[openafs_cv_c_bigendian_compile=yes],[openafs_cv_c_bigendian_compile=no])])
26AC_CACHE_CHECK(whether byte ordering is bigendian, openafs_cv_c_bigendian,[
27 if test "$openafs_cv_c_bigendian_compile" = "yes"; then
28 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
29#include <sys/types.h>
30#include <sys/param.h>]], [[
31#if BYTE_ORDER != BIG_ENDIAN
32 not big endian
33#endif]])],[openafs_cv_c_bigendian=yes],[openafs_cv_c_bigendian=no])
34 else
35 AC_RUN_IFELSE([AC_LANG_SOURCE([[main () {
36 /* Are we little or big endian? From Harbison&Steele. */
37 union
38 {
39 long l;
40 char c[sizeof (long)];
41 } u;
42 u.l = 1;
43 exit (u.c[sizeof (long) - 1] == 1);
44 }]])],
45 [openafs_cv_c_bigendian=no],
46 [openafs_cv_c_bigendian=yes],
47 [AC_MSG_ERROR(specify either --enable-bigendian or --enable-littleendian)])
48 fi
49])
50if test "$openafs_cv_c_bigendian" = "yes"; then
51 AC_DEFINE(AUTOCONF_FOUND_BIGENDIAN, 1, [define if target is big endian])dnl
52fi
53if test "$openafs_cv_c_bigendian_compile" = "yes"; then
54 AC_DEFINE(ENDIANESS_IN_SYS_PARAM_H, 1, [define if sys/param.h defines the endiness])dnl
55fi
56])