Fix COPYING.EXCEPTION license notices
[gnulib.git] / m4 / wchar_h.m4
blob995bdc659d9d39cdb030b9269bc4a111006b0dc8
1 # wchar_h.m4
2 # serial 64
3 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
10 dnl Written by Eric Blake.
12 AC_DEFUN_ONCE([gl_WCHAR_H],
14   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
15   AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
16   dnl Prepare for creating substitute <wchar.h>.
17   dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
18   dnl character support).
19   dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
20   gl_CHECK_NEXT_HEADERS([wchar.h])
21   if test $ac_cv_header_wchar_h = yes; then
22     HAVE_WCHAR_H=1
23   else
24     HAVE_WCHAR_H=0
25   fi
26   AC_SUBST([HAVE_WCHAR_H])
28   AC_REQUIRE([gl_FEATURES_H])
30   AC_REQUIRE([gt_TYPE_WINT_T])
31   if test $gt_cv_c_wint_t = yes; then
32     HAVE_WINT_T=1
33   else
34     HAVE_WINT_T=0
35   fi
36   AC_SUBST([HAVE_WINT_T])
38   AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
40   dnl Check for declarations of anything we want to poison if the
41   dnl corresponding gnulib module is not in use.
42   gl_WARN_ON_USE_PREPARE([[
43       #include <wchar.h>
44     ]],
45     [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
46      wcsrtombs wcsnrtombs wcwidth
47      wmemchr wmemcmp wmemcpy wmemmove wmempcpy wmemset
48      wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
49      wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
50      wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
51     ])
53   AC_REQUIRE([AC_C_RESTRICT])
55   AC_CHECK_DECLS([wcsdup], [], [], [[
56       #include <wchar.h>
57     ]])
58   if test $ac_cv_have_decl_wcsdup = no; then
59     HAVE_DECL_WCSDUP=0
60   fi
63 dnl Check whether <wchar.h> is usable at all.
64 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
66   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
67   dnl 'gnu_inline'. See <https://sourceware.org/bugzilla/show_bug.cgi?id=4022>
68   dnl and <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
69   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
70   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
71   AC_REQUIRE([AC_CANONICAL_HOST])
72   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
73     [gl_cv_header_wchar_h_correct_inline],
74     [gl_cv_header_wchar_h_correct_inline=yes
75      case "$host_os" in
76        *-gnu* | gnu*)
77          AC_LANG_CONFTEST([
78            AC_LANG_SOURCE([[
79              #define wcstod renamed_wcstod
80              #include <wchar.h>
81              extern int zero (void);
82              int main () { return zero(); }
83            ]])])
84          dnl Do not rename the object file from conftest.$ac_objext to
85          dnl conftest1.$ac_objext, as this will cause the link to fail on
86          dnl z/OS when using the XPLINK object format (due to duplicate
87          dnl CSECT names). Instead, temporarily redefine $ac_compile so
88          dnl that the object file has the latter name from the start.
89          saved_ac_compile="$ac_compile"
90          ac_compile=`echo "$saved_ac_compile" | sed s/conftest/conftest1/`
91          if echo '#include "conftest.c"' >conftest1.c \
92             && AC_TRY_EVAL([ac_compile]); then
93            AC_LANG_CONFTEST([
94              AC_LANG_SOURCE([[
95                #define wcstod renamed_wcstod
96                #include <wchar.h>
97                int zero (void) { return 0; }
98              ]])])
99            dnl See note above about renaming object files.
100            ac_compile=`echo "$saved_ac_compile" | sed s/conftest/conftest2/`
101            if echo '#include "conftest.c"' >conftest2.c \
102               && AC_TRY_EVAL([ac_compile]); then
103              if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
104                :
105              else
106                gl_cv_header_wchar_h_correct_inline=no
107              fi
108            fi
109          fi
110          ac_compile="$saved_ac_compile"
111          rm -f conftest[12].c conftest[12].$ac_objext conftest$ac_exeext
112          ;;
113      esac
114     ])
115   if test $gl_cv_header_wchar_h_correct_inline = no; then
116     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
117 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
118 C99 mode. You have four options:
119   - Add the flag -fgnu89-inline to CC and reconfigure, or
120   - Fix your include files, using parts of
121     <https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
122   - Use a gcc version older than 4.3, or
123   - Don't use the flags -std=c99 or -std=gnu99.
124 Configuration aborted.])
125   fi
128 # gl_WCHAR_MODULE_INDICATOR([modulename])
129 # sets the shell variable that indicates the presence of the given module
130 # to a C preprocessor expression that will evaluate to 1.
131 # This macro invocation must not occur in macros that are AC_REQUIREd.
132 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
134   dnl Ensure to expand the default settings once only.
135   gl_WCHAR_H_REQUIRE_DEFAULTS
136   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
137   dnl Define it also as a C macro, for the benefit of the unit tests.
138   gl_MODULE_INDICATOR_FOR_TESTS([$1])
141 # Initializes the default values for AC_SUBSTed shell variables.
142 # This macro must not be AC_REQUIREd.  It must only be invoked, and only
143 # outside of macros or in macros that are not AC_REQUIREd.
144 AC_DEFUN([gl_WCHAR_H_REQUIRE_DEFAULTS],
146   m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS], [
147     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BTOWC])
148     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOB])
149     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSINIT])
150     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSZERO])
151     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOWC])
152     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRLEN])
153     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOWCS])
154     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOWCS])
155     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCRTOMB])
156     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRTOMBS])
157     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNRTOMBS])
158     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCWIDTH])
159     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCHR])
160     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCMP])
161     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCPY])
162     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMMOVE])
163     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMPCPY])
164     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMSET])
165     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSLEN])
166     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNLEN])
167     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCPY])
168     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPCPY])
169     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCPY])
170     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPNCPY])
171     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCAT])
172     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCAT])
173     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCMP])
174     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCMP])
175     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCASECMP])
176     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCASECMP])
177     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCOLL])
178     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSXFRM])
179     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSDUP])
180     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCHR])
181     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRCHR])
182     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCSPN])
183     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSPN])
184     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSPBRK])
185     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSTR])
186     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSTOK])
187     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSWIDTH])
188     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSFTIME])
189     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WGETCWD])
190     dnl Support Microsoft deprecated alias function names by default.
191     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WCSDUP], [1])
192   ])
193   m4_require(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS])
194   dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
195   gl_STDLIB_H_REQUIRE_DEFAULTS
196   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
199 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
201   dnl Assume proper GNU behavior unless another module says otherwise.
202   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
203   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
204   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
205   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
206   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
207   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
208   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
209   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
210   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
211   HAVE_WMEMCHR=1;       AC_SUBST([HAVE_WMEMCHR])
212   HAVE_WMEMCMP=1;       AC_SUBST([HAVE_WMEMCMP])
213   HAVE_WMEMCPY=1;       AC_SUBST([HAVE_WMEMCPY])
214   HAVE_WMEMMOVE=1;      AC_SUBST([HAVE_WMEMMOVE])
215   HAVE_WMEMPCPY=1;      AC_SUBST([HAVE_WMEMPCPY])
216   HAVE_WMEMSET=1;       AC_SUBST([HAVE_WMEMSET])
217   HAVE_WCSLEN=1;        AC_SUBST([HAVE_WCSLEN])
218   HAVE_WCSNLEN=1;       AC_SUBST([HAVE_WCSNLEN])
219   HAVE_WCSCPY=1;        AC_SUBST([HAVE_WCSCPY])
220   HAVE_WCPCPY=1;        AC_SUBST([HAVE_WCPCPY])
221   HAVE_WCSNCPY=1;       AC_SUBST([HAVE_WCSNCPY])
222   HAVE_WCPNCPY=1;       AC_SUBST([HAVE_WCPNCPY])
223   HAVE_WCSCAT=1;        AC_SUBST([HAVE_WCSCAT])
224   HAVE_WCSNCAT=1;       AC_SUBST([HAVE_WCSNCAT])
225   HAVE_WCSCMP=1;        AC_SUBST([HAVE_WCSCMP])
226   HAVE_WCSNCMP=1;       AC_SUBST([HAVE_WCSNCMP])
227   HAVE_WCSCASECMP=1;    AC_SUBST([HAVE_WCSCASECMP])
228   HAVE_WCSNCASECMP=1;   AC_SUBST([HAVE_WCSNCASECMP])
229   HAVE_WCSCOLL=1;       AC_SUBST([HAVE_WCSCOLL])
230   HAVE_WCSXFRM=1;       AC_SUBST([HAVE_WCSXFRM])
231   HAVE_WCSDUP=1;        AC_SUBST([HAVE_WCSDUP])
232   HAVE_WCSCHR=1;        AC_SUBST([HAVE_WCSCHR])
233   HAVE_WCSRCHR=1;       AC_SUBST([HAVE_WCSRCHR])
234   HAVE_WCSCSPN=1;       AC_SUBST([HAVE_WCSCSPN])
235   HAVE_WCSSPN=1;        AC_SUBST([HAVE_WCSSPN])
236   HAVE_WCSPBRK=1;       AC_SUBST([HAVE_WCSPBRK])
237   HAVE_WCSSTR=1;        AC_SUBST([HAVE_WCSSTR])
238   HAVE_WCSTOK=1;        AC_SUBST([HAVE_WCSTOK])
239   HAVE_WCSWIDTH=1;      AC_SUBST([HAVE_WCSWIDTH])
240   HAVE_WCSFTIME=1;      AC_SUBST([HAVE_WCSFTIME])
241   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
242   HAVE_DECL_WCSDUP=1;   AC_SUBST([HAVE_DECL_WCSDUP])
243   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
244   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
245   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
246   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
247   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
248   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
249   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
250   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
251   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
252   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
253   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
254   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
255   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
256   REPLACE_WCSWIDTH=0;   AC_SUBST([REPLACE_WCSWIDTH])
257   REPLACE_WCSFTIME=0;   AC_SUBST([REPLACE_WCSFTIME])
258   REPLACE_WCSCMP=0;     AC_SUBST([REPLACE_WCSCMP])
259   REPLACE_WCSNCMP=0;    AC_SUBST([REPLACE_WCSNCMP])
260   REPLACE_WCSSTR=0;     AC_SUBST([REPLACE_WCSSTR])
261   REPLACE_WCSTOK=0;     AC_SUBST([REPLACE_WCSTOK])
262   REPLACE_WMEMCMP=0;    AC_SUBST([REPLACE_WMEMCMP])
263   REPLACE_WMEMPCPY=0;   AC_SUBST([REPLACE_WMEMPCPY])