annotate m4/size_max.m4 @ 423:079d43b6967b 3.0-beta2 3.0-beta2

Added missing file
author lost@l-w.ca
date Sun, 19 Sep 2010 01:44:47 -0600
parents 3c2e1f24cc7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
421
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
1 # size_max.m4 serial 9
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
2 dnl Copyright (C) 2003, 2005-2006, 2008-2010 Free Software Foundation, Inc.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
6
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
7 dnl From Bruno Haible.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
8
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
9 AC_DEFUN([gl_SIZE_MAX],
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
10 [
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
11 AC_CHECK_HEADERS([stdint.h])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
12 dnl First test whether the system already has SIZE_MAX.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
13 AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
14 gl_cv_size_max=
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
15 AC_EGREP_CPP([Found it], [
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
16 #include <limits.h>
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
17 #if HAVE_STDINT_H
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
18 #include <stdint.h>
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
19 #endif
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
20 #ifdef SIZE_MAX
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
21 Found it
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
22 #endif
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
23 ], [gl_cv_size_max=yes])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
24 if test -z "$gl_cv_size_max"; then
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
25 dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
26 dnl than the type 'unsigned long'. Try hard to find a definition that can
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
27 dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
28 AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1],
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
29 [#include <stddef.h>
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
30 #include <limits.h>], [size_t_bits_minus_1=])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
31 AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)],
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
32 [#include <stddef.h>], [fits_in_uint=])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
33 if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
34 if test $fits_in_uint = 1; then
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
35 dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
36 dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
37 AC_TRY_COMPILE([#include <stddef.h>
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
38 extern size_t foo;
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
39 extern unsigned long foo;
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
40 ], [], [fits_in_uint=0])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
41 fi
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
42 dnl We cannot use 'expr' to simplify this expression, because 'expr'
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
43 dnl works only with 'long' integers in the host environment, while we
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
44 dnl might be cross-compiling from a 32-bit platform to a 64-bit platform.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
45 if test $fits_in_uint = 1; then
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
46 gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)"
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
47 else
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
48 gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)"
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
49 fi
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
50 else
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
51 dnl Shouldn't happen, but who knows...
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
52 gl_cv_size_max='((size_t)~(size_t)0)'
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
53 fi
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
54 fi
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
55 ])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
56 if test "$gl_cv_size_max" != yes; then
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
57 AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max],
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
58 [Define as the maximum value of type 'size_t', if the system doesn't define it.])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
59 fi
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
60 dnl Don't redefine SIZE_MAX in config.h if config.h is re-included after
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
61 dnl <stdint.h>. Remember that the #undef in AH_VERBATIM gets replaced with
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
62 dnl #define by AC_DEFINE_UNQUOTED.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
63 AH_VERBATIM([SIZE_MAX],
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
64 [/* Define as the maximum value of type 'size_t', if the system doesn't define
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
65 it. */
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
66 #ifndef SIZE_MAX
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
67 # undef SIZE_MAX
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
68 #endif])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
69 ])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
70
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
71 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
72 dnl Remove this when we can assume autoconf >= 2.61.
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
73 m4_ifdef([AC_COMPUTE_INT], [], [
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
74 AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
3c2e1f24cc7d Added generated files for release
lost@l-w.ca
parents:
diff changeset
75 ])