monotone

monotone Mtn Source Tree

Root/m4/numeric_vocab.m4

1dnl Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
2dnl This program is made available under the GNU GPL version 2.0 or
3dnl greater. See the accompanying file COPYING for details.
4dnl
5dnl This program is distributed WITHOUT ANY WARRANTY; without even the
6dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7dnl PURPOSE.
8
9dnl @synopsis MTN_NUMERIC_VOCAB
10dnl
11dnl This macro determines appropriate types for Monotone's set of
12dnl exact-width numeric types, u8/u16/u32/u64 (unsigned) and
13dnl s8/s16/s32/s64 (signed). If it cannot find appropriate types, or
14dnl if 'char' is not exactly 8 bits, it aborts the configure
15dnl operation.
16dnl
17dnl It should be mentioned that sizeof([[un]signed] char) is 1 *by
18dnl definition*. It is written into both the C and C++ standards.
19dnl It is never necessary to check this.
20
21dnl We don't use AC_CHECK_SIZEOF because we don't want the macro it
22dnl defines. However, we do use the same test construct and the same
23dnl cache variable; except that, as this is used only with fundamental
24dnl types, we don't bother with the typedef checks.
25AC_DEFUN([MTN_COMPUTE_SIZEOF],
26[AS_LITERAL_IF([$1], [],
27 [AC_FATAL([$0: requires literal arguments])])dnl
28AC_CACHE_CHECK([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
29 [AC_COMPUTE_INT([AS_TR_SH([ac_cv_sizeof_$1])],
30 [(long int)(sizeof (ac__type_sizeof_))],
31 [AC_INCLUDES_DEFAULT()
32 typedef $1 ac__type_sizeof_;],
33 [AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)])])])
34
35AC_DEFUN([MTN_CHOOSE_USE_OF_TYPE], [
36MTN_COMPUTE_SIZEOF([$1])
37case $AS_TR_SH([ac_cv_sizeof_$1]) in
38 2) mtn_s16_type='$1'
39 mtn_u16_type='$2' ;;
40 4) mtn_s32_type='$1'
41 mtn_u32_type='$2' ;;
42 8) mtn_s64_type='$1'
43 mtn_u64_type='$2' ;;
44esac])
45
46dnl AC_LANG_BOOL_COMPILE_TRY is not documented, but is very helpful.
47dnl The content of these conditional definitions was lifted from
48dnl autoconf 2.61.
49m4_ifdef([AC_LANG_BOOL_COMPILE_TRY(C)], [],
50[m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
51[AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
52test_array @<:@0@:>@ = 0
53])])])
54m4_ifdef([AC_LANG_BOOL_COMPILE_TRY(C++)], [],
55[m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])])
56m4_ifdef([AC_LANG_BOOL_COMPILE_TRY], [],
57[AC_DEFUN([AC_LANG_BOOL_COMPILE_TRY],
58[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
59
60dnl AC_COMPUTE_INT is new in autoconf 2.61.
61dnl Let's see if we can get away with just forwarding to the older
62dnl _AC_COMPUTE_INT.
63m4_ifdef([AC_COMPUTE_INT], [],
64[m4_ifdef([_AC_COMPUTE_INT],
65 [AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])],
66 [m4_fatal([A version of Autoconf that provides AC_COMPUTE_INT or _AC_COMPUTE_INT is required], 63)])])
67
68AC_DEFUN([MTN_ASSERT_EIGHT_BIT_CHARS],
69[AC_LANG_ASSERT([C++])
70 AC_MSG_CHECKING([whether char has 8 bits])
71 AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([@%:@include <limits>],
72 [std::numeric_limits<unsigned char>::digits == 8])],
73 [AC_MSG_RESULT([yes])],
74 [AC_MSG_RESULT([no])
75 AC_MSG_ERROR([*** Monotone requires a platform with 8-bit bytes.])])])
76
77AC_DEFUN([MTN_CHECK_PLAIN_CHAR_SIGNED],
78[AC_CACHE_CHECK([whether plain char is signed], mtn_cv_plain_char_signed,
79 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [((int)(char)-1) < 0])],
80 [mtn_cv_plain_char_signed=yes],
81 [mtn_cv_plain_char_signed=no])])])
82
83
84AC_DEFUN([MTN_NUMERIC_VOCAB], [dnl
85MTN_ASSERT_EIGHT_BIT_CHARS
86
87# s8 and u8 will be some sort of 'char', but we want to use the plain
88# variety for whichever one it is.
89MTN_CHECK_PLAIN_CHAR_SIGNED
90if test $mtn_cv_plain_char_signed = yes ; then
91 mtn_s8_type='char'
92 mtn_u8_type='unsigned char'
93else
94 mtn_s8_type='signed char'
95 mtn_u8_type='char'
96fi
97
98mtn_s16_type=unknown
99mtn_u16_type=unknown
100mtn_s32_type=unknown
101mtn_u32_type=unknown
102mtn_s64_type=unknown
103mtn_u64_type=unknown
104
105# See if we can get away without 'long long' (LP64 model).
106# The order here ensures that 'int' will be used if it happens
107# to be the same size as 'short' or 'long'.
108MTN_CHOOSE_USE_OF_TYPE([short], [unsigned short])
109MTN_CHOOSE_USE_OF_TYPE([long], [unsigned long])
110MTN_CHOOSE_USE_OF_TYPE([int], [unsigned int])
111
112# If we didn't get an s16 or an s32 type we are hoz0red.
113if test "$mtn_s16_type" = unknown
114then AC_MSG_ERROR([*** no signed 16-bit type found])
115fi
116if test "$mtn_s32_type" = unknown
117then AC_MSG_ERROR([*** no signed 32-bit type found])
118fi
119
120# If we didn't get an s64 type, try long long.
121if test "$mtn_s64_type" = unknown; then
122 MTN_CHOOSE_USE_OF_TYPE([long long], [unsigned long long])
123 if test "$mtn_s64_type" = unknown
124 then AC_MSG_ERROR([*** no signed 64-bit type found])
125 fi
126fi
127
128AC_DEFINE_UNQUOTED([TYPE_S8], [$mtn_s8_type], [Type to use for `s8'.])
129AC_DEFINE_UNQUOTED([TYPE_S16], [$mtn_s16_type], [Type to use for `s16'.])
130AC_DEFINE_UNQUOTED([TYPE_S32], [$mtn_s32_type], [Type to use for `s32'.])
131AC_DEFINE_UNQUOTED([TYPE_S64], [$mtn_s64_type], [Type to use for `s64'.])
132
133AC_DEFINE_UNQUOTED([TYPE_U8], [$mtn_u8_type], [Type to use for `u8'.])
134AC_DEFINE_UNQUOTED([TYPE_U16], [$mtn_u16_type], [Type to use for `u16'.])
135AC_DEFINE_UNQUOTED([TYPE_U32], [$mtn_u32_type], [Type to use for `u32'.])
136AC_DEFINE_UNQUOTED([TYPE_U64], [$mtn_u64_type], [Type to use for `u64'.])
137])
138
139dnl Local Variables:
140dnl mode: autoconf
141dnl indent-tabs-mode: nil
142dnl End:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status