wchar_h.m4 10.0 KB

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