1dnl @synopsis AX_DECL_WCHAR_MAX
2dnl
3dnl Checks whether the system headers define WCHAR_MAX or not.  If it is
4dnl already defined, does nothing.  Otherwise checks the size and signedness
5dnl of `wchar_t', and defines WCHAR_MAX to the maximum value that can be
6dnl stored in a variable of type `wchar_t'.
7dnl
8dnl @version 1.1
9dnl @author Ville Laurikari <vl@iki.fi>
10dnl
11AC_DEFUN([AX_DECL_WCHAR_MAX], [
12  AC_CACHE_CHECK([whether WCHAR_MAX is defined], ax_cv_decl_wchar_max, [
13    AC_COMPILE_IFELSE(
14      [AC_LANG_PROGRAM([
15#ifdef HAVE_WCHAR_H
16#include <wchar.h>
17#endif
18], [WCHAR_MAX])],
19      [ax_cv_decl_wchar_max="yes"],
20      [ax_cv_decl_wchar_max="no"])])
21  if test $ax_cv_decl_wchar_max = "no"; then
22    AX_CHECK_SIGN([wchar_t],
23      [ wc_signed="yes"
24        AC_DEFINE(WCHAR_T_SIGNED, 1, [Define if wchar_t is signed]) ],
25      [ wc_signed="no"
26        AC_DEFINE(WCHAR_T_UNSIGNED, 1, [Define if wchar_t is unsigned])], [
27#ifdef HAVE_WCHAR_H
28#include <wchar.h>
29#endif
30])
31    if test "$wc_signed" = "yes"; then
32      AC_DEFINE(WCHAR_MAX, [(1L << (sizeof(wchar_t) * 8 - 1) - 1)], [
33Define to the maximum value of wchar_t if not already defined elsewhere])
34    elif test "$wc_signed" = "no"; then
35      AC_DEFINE(WCHAR_MAX, [(1L << (sizeof(wchar_t) * 8) - 1)])
36    fi
37  fi
38])dnl
39