1dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues. 2 3dnl Copyright (C) 2007-2021 Free Software Foundation, Inc. 4dnl This file is free software; the Free Software Foundation 5dnl gives unlimited permission to copy and/or distribute it, 6dnl with or without modifications, as long as this notice is preserved. 7 8dnl Written by Eric Blake. 9 10# wchar_h.m4 serial 53 11 12AC_DEFUN_ONCE([gl_WCHAR_H], 13[ 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]) 27 28 AC_REQUIRE([gl_FEATURES_H]) 29 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]) 37 38 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ]) 39 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 ]) 52 53 AC_REQUIRE([AC_C_RESTRICT]) 54 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 61]) 62 63dnl Check whether <wchar.h> is usable at all. 64AC_DEFUN([gl_WCHAR_H_INLINE_OK], 65[ 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 save_ac_compile="$ac_compile" 90 ac_compile=`echo "$save_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 "$save_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="$save_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). 117This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in 118C99 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. 124Configuration aborted.]) 125 fi 126]) 127 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. 132AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], 133[ 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]) 139]) 140 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. 144AC_DEFUN([gl_WCHAR_H_REQUIRE_DEFAULTS], 145[ 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_MBRTOWC]) 151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRLEN]) 152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOWCS]) 153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOWCS]) 154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCRTOMB]) 155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRTOMBS]) 156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNRTOMBS]) 157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCWIDTH]) 158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCHR]) 159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCMP]) 160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCPY]) 161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMMOVE]) 162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMPCPY]) 163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMSET]) 164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSLEN]) 165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNLEN]) 166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCPY]) 167 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPCPY]) 168 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCPY]) 169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPNCPY]) 170 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCAT]) 171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCAT]) 172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCMP]) 173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCMP]) 174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCASECMP]) 175 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCASECMP]) 176 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCOLL]) 177 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSXFRM]) 178 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSDUP]) 179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCHR]) 180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRCHR]) 181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCSPN]) 182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSPN]) 183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSPBRK]) 184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSTR]) 185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSTOK]) 186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSWIDTH]) 187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSFTIME]) 188 dnl Support Microsoft deprecated alias function names by default. 189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WCSDUP], [1]) 190 ]) 191 m4_require(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS]) 192 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 193]) 194 195AC_DEFUN([gl_WCHAR_H_DEFAULTS], 196[ 197 dnl Assume proper GNU behavior unless another module says otherwise. 198 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) 199 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) 200 HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC]) 201 HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN]) 202 HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS]) 203 HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS]) 204 HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB]) 205 HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS]) 206 HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS]) 207 HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR]) 208 HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP]) 209 HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY]) 210 HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE]) 211 HAVE_WMEMPCPY=1; AC_SUBST([HAVE_WMEMPCPY]) 212 HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET]) 213 HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN]) 214 HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN]) 215 HAVE_WCSCPY=1; AC_SUBST([HAVE_WCSCPY]) 216 HAVE_WCPCPY=1; AC_SUBST([HAVE_WCPCPY]) 217 HAVE_WCSNCPY=1; AC_SUBST([HAVE_WCSNCPY]) 218 HAVE_WCPNCPY=1; AC_SUBST([HAVE_WCPNCPY]) 219 HAVE_WCSCAT=1; AC_SUBST([HAVE_WCSCAT]) 220 HAVE_WCSNCAT=1; AC_SUBST([HAVE_WCSNCAT]) 221 HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP]) 222 HAVE_WCSNCMP=1; AC_SUBST([HAVE_WCSNCMP]) 223 HAVE_WCSCASECMP=1; AC_SUBST([HAVE_WCSCASECMP]) 224 HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP]) 225 HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL]) 226 HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM]) 227 HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP]) 228 HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR]) 229 HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR]) 230 HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN]) 231 HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN]) 232 HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK]) 233 HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR]) 234 HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK]) 235 HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH]) 236 HAVE_WCSFTIME=1; AC_SUBST([HAVE_WCSFTIME]) 237 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB]) 238 HAVE_DECL_WCSDUP=1; AC_SUBST([HAVE_DECL_WCSDUP]) 239 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) 240 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T]) 241 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC]) 242 REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB]) 243 REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT]) 244 REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC]) 245 REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN]) 246 REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS]) 247 REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS]) 248 REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB]) 249 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS]) 250 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS]) 251 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) 252 REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) 253 REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME]) 254 REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK]) 255]) 256