xgetcwd: Improve documentation.
[gnulib.git] / m4 / uchar.m4
blob0875caa36ddc909fa90fbf3e11b9ed968b5e880c
1 # uchar.m4 serial 14
2 dnl Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl From Bruno Haible.
8 dnl Prepare the overridden <uchar.h>.
10 AC_DEFUN_ONCE([gl_UCHAR_H],
12   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
14   gl_CHECK_NEXT_HEADERS([uchar.h])
15   if test $ac_cv_header_uchar_h = yes; then
16     HAVE_UCHAR_H=1
17   else
18     HAVE_UCHAR_H=0
19   fi
20   AC_SUBST([HAVE_UCHAR_H])
22   gl_TYPE_CHAR16_T
23   gl_TYPE_CHAR32_T
25   dnl Test whether a 'char32_t' can hold more characters than a 'wchar_t'.
26   gl_STDINT_BITSIZEOF([wchar_t], [gl_STDINT_INCLUDES])
27   if test $BITSIZEOF_WCHAR_T -lt 32; then
28     SMALL_WCHAR_T=1
29   else
30     SMALL_WCHAR_T=0
31   fi
32   dnl SMALL_WCHAR_T is expected to be 1 on 32-bit AIX, Cygwin, native Windows.
33   AC_SUBST([SMALL_WCHAR_T])
35   dnl Check for declarations of anything we want to poison if the
36   dnl corresponding gnulib module is not in use, and which is not
37   dnl guaranteed by C11.
38   gl_WARN_ON_USE_PREPARE([[#include <uchar.h>
39     ]], [c32rtomb mbrtoc32])
42 dnl On Haiku 2020, char16_t and char32_t are incorrectly defined.
43 dnl See <https://dev.haiku-os.org/ticket/15990>.
44 AC_DEFUN_ONCE([gl_TYPE_CHAR16_T],
46   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
47   dnl Determine whether gnulib's <uchar.h> would, if present, override char16_t.
48   AC_CACHE_CHECK([whether char16_t is correctly defined],
49     [gl_cv_type_char16_t_works],
50     [AC_COMPILE_IFELSE(
51        [AC_LANG_PROGRAM([[
52           #include <uchar.h>
53           /* For simplicity, assume that uint16_least_t is equivalent to
54              'unsigned short'.  */
55           int verify[(char16_t)(-1) >= 0 && sizeof (char16_t) == sizeof (unsigned short) ? 1 : -1];
56           ]])
57        ],
58        [gl_cv_type_char16_t_works=yes],
59        [gl_cv_type_char16_t_works=no])
60     ])
61   if test $gl_cv_type_char16_t_works = no; then
62     GNULIB_OVERRIDES_CHAR16_T=1
63   fi
65 AC_DEFUN_ONCE([gl_TYPE_CHAR32_T],
67   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
68   dnl Determine whether gnulib's <uchar.h> would, if present, override char32_t.
69   AC_CACHE_CHECK([whether char32_t is correctly defined],
70     [gl_cv_type_char32_t_works],
71     [AC_COMPILE_IFELSE(
72        [AC_LANG_PROGRAM([[
73           #include <uchar.h>
74           /* For simplicity, assume that uint32_least_t is equivalent to
75              'unsigned int'.  */
76           int verify[(char32_t)(-1) >= 0 && sizeof (char32_t) == sizeof (unsigned int) ? 1 : -1];
77           ]])
78        ],
79        [gl_cv_type_char32_t_works=yes],
80        [gl_cv_type_char32_t_works=no])
81     ])
82   if test $gl_cv_type_char32_t_works = no; then
83     GNULIB_OVERRIDES_CHAR32_T=1
84   fi
87 AC_DEFUN([gl_UCHAR_MODULE_INDICATOR],
89   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
90   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
91   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
92   dnl Define it also as a C macro, for the benefit of the unit tests.
93   gl_MODULE_INDICATOR_FOR_TESTS([$1])
96 AC_DEFUN([gl_UCHAR_H_DEFAULTS],
98   GNULIB_OVERRIDES_CHAR16_T=0; AC_SUBST([GNULIB_OVERRIDES_CHAR16_T])
99   GNULIB_OVERRIDES_CHAR32_T=0; AC_SUBST([GNULIB_OVERRIDES_CHAR32_T])
100   GNULIB_BTOC32=0;             AC_SUBST([GNULIB_BTOC32])
101   GNULIB_C32ISALNUM=0;         AC_SUBST([GNULIB_C32ISALNUM])
102   GNULIB_C32ISALPHA=0;         AC_SUBST([GNULIB_C32ISALPHA])
103   GNULIB_C32ISBLANK=0;         AC_SUBST([GNULIB_C32ISBLANK])
104   GNULIB_C32ISCNTRL=0;         AC_SUBST([GNULIB_C32ISCNTRL])
105   GNULIB_C32ISDIGIT=0;         AC_SUBST([GNULIB_C32ISDIGIT])
106   GNULIB_C32ISGRAPH=0;         AC_SUBST([GNULIB_C32ISGRAPH])
107   GNULIB_C32ISLOWER=0;         AC_SUBST([GNULIB_C32ISLOWER])
108   GNULIB_C32ISPRINT=0;         AC_SUBST([GNULIB_C32ISPRINT])
109   GNULIB_C32ISPUNCT=0;         AC_SUBST([GNULIB_C32ISPUNCT])
110   GNULIB_C32ISSPACE=0;         AC_SUBST([GNULIB_C32ISSPACE])
111   GNULIB_C32ISUPPER=0;         AC_SUBST([GNULIB_C32ISUPPER])
112   GNULIB_C32ISXDIGIT=0;        AC_SUBST([GNULIB_C32ISXDIGIT])
113   GNULIB_C32RTOMB=0;           AC_SUBST([GNULIB_C32RTOMB])
114   GNULIB_C32SNRTOMBS=0;        AC_SUBST([GNULIB_C32SNRTOMBS])
115   GNULIB_C32SRTOMBS=0;         AC_SUBST([GNULIB_C32SRTOMBS])
116   GNULIB_C32STOMBS=0;          AC_SUBST([GNULIB_C32STOMBS])
117   GNULIB_C32TOB=0;             AC_SUBST([GNULIB_C32TOB])
118   GNULIB_MBRTOC32=0;           AC_SUBST([GNULIB_MBRTOC32])
119   GNULIB_MBSNRTOC32S=0;        AC_SUBST([GNULIB_MBSNRTOC32S])
120   GNULIB_MBSRTOC32S=0;         AC_SUBST([GNULIB_MBSRTOC32S])
121   GNULIB_MBSTOC32S=0;          AC_SUBST([GNULIB_MBSTOC32S])
122   dnl Assume proper GNU behavior unless another module says otherwise.
123   HAVE_C32RTOMB=1;             AC_SUBST([HAVE_C32RTOMB])
124   HAVE_MBRTOC32=1;             AC_SUBST([HAVE_MBRTOC32])
125   REPLACE_C32RTOMB=0;          AC_SUBST([REPLACE_C32RTOMB])
126   REPLACE_MBRTOC32=0;          AC_SUBST([REPLACE_MBRTOC32])