Commit | Line | Data |
---|---|---|
805e021f CE |
1 | dnl |
2 | dnl $Id$ | |
3 | dnl | |
4 | ||
5 | dnl check if this computer is little or big-endian | |
6 | dnl if we can figure it out at compile-time then don't define the cpp symbol | |
7 | dnl otherwise test for it and define it. also allow options for overriding | |
8 | dnl it when cross-compiling | |
9 | ||
10 | AC_DEFUN([OPENAFS_CHECK_BIGENDIAN], [ | |
11 | AC_ARG_ENABLE([bigendian], | |
12 | [AS_HELP_STRING([--enable-bigendian], [the target is big endian])], | |
13 | [openafs_cv_c_bigendian=yes]) | |
14 | AC_ARG_ENABLE([littleendian], | |
15 | [AS_HELP_STRING([--enable-littleendian], [the target is little endian])], | |
16 | [openafs_cv_c_bigendian=no]) | |
17 | ||
18 | AC_CACHE_CHECK(whether byte order is known at compile time, | |
19 | openafs_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])]) | |
26 | AC_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 | ]) | |
50 | if test "$openafs_cv_c_bigendian" = "yes"; then | |
51 | AC_DEFINE(AUTOCONF_FOUND_BIGENDIAN, 1, [define if target is big endian])dnl | |
52 | fi | |
53 | if 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 | |
55 | fi | |
56 | ]) |