wchar_h.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
  2. dnl Copyright (C) 2007-2023 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 55
  8. AC_DEFUN_ONCE([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. # gl_WCHAR_MODULE_INDICATOR([modulename])
  117. # sets the shell variable that indicates the presence of the given module
  118. # to a C preprocessor expression that will evaluate to 1.
  119. # This macro invocation must not occur in macros that are AC_REQUIREd.
  120. AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
  121. [
  122. dnl Ensure to expand the default settings once only.
  123. gl_WCHAR_H_REQUIRE_DEFAULTS
  124. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  125. dnl Define it also as a C macro, for the benefit of the unit tests.
  126. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  127. ])
  128. # Initializes the default values for AC_SUBSTed shell variables.
  129. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  130. # outside of macros or in macros that are not AC_REQUIREd.
  131. AC_DEFUN([gl_WCHAR_H_REQUIRE_DEFAULTS],
  132. [
  133. m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS], [
  134. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BTOWC])
  135. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOB])
  136. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSINIT])
  137. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOWC])
  138. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRLEN])
  139. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOWCS])
  140. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOWCS])
  141. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCRTOMB])
  142. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRTOMBS])
  143. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNRTOMBS])
  144. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCWIDTH])
  145. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCHR])
  146. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCMP])
  147. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCPY])
  148. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMMOVE])
  149. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMPCPY])
  150. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMSET])
  151. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSLEN])
  152. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNLEN])
  153. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCPY])
  154. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPCPY])
  155. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCPY])
  156. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPNCPY])
  157. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCAT])
  158. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCAT])
  159. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCMP])
  160. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCMP])
  161. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCASECMP])
  162. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCASECMP])
  163. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCOLL])
  164. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSXFRM])
  165. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSDUP])
  166. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCHR])
  167. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRCHR])
  168. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCSPN])
  169. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSPN])
  170. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSPBRK])
  171. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSTR])
  172. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSTOK])
  173. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSWIDTH])
  174. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSFTIME])
  175. dnl Support Microsoft deprecated alias function names by default.
  176. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WCSDUP], [1])
  177. ])
  178. m4_require(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS])
  179. dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
  180. gl_STDLIB_H_REQUIRE_DEFAULTS
  181. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  182. ])
  183. AC_DEFUN([gl_WCHAR_H_DEFAULTS],
  184. [
  185. dnl Assume proper GNU behavior unless another module says otherwise.
  186. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
  187. HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
  188. HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
  189. HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
  190. HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
  191. HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
  192. HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
  193. HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
  194. HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
  195. HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR])
  196. HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP])
  197. HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY])
  198. HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE])
  199. HAVE_WMEMPCPY=1; AC_SUBST([HAVE_WMEMPCPY])
  200. HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET])
  201. HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN])
  202. HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN])
  203. HAVE_WCSCPY=1; AC_SUBST([HAVE_WCSCPY])
  204. HAVE_WCPCPY=1; AC_SUBST([HAVE_WCPCPY])
  205. HAVE_WCSNCPY=1; AC_SUBST([HAVE_WCSNCPY])
  206. HAVE_WCPNCPY=1; AC_SUBST([HAVE_WCPNCPY])
  207. HAVE_WCSCAT=1; AC_SUBST([HAVE_WCSCAT])
  208. HAVE_WCSNCAT=1; AC_SUBST([HAVE_WCSNCAT])
  209. HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP])
  210. HAVE_WCSNCMP=1; AC_SUBST([HAVE_WCSNCMP])
  211. HAVE_WCSCASECMP=1; AC_SUBST([HAVE_WCSCASECMP])
  212. HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP])
  213. HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL])
  214. HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM])
  215. HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP])
  216. HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR])
  217. HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR])
  218. HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN])
  219. HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN])
  220. HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK])
  221. HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR])
  222. HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK])
  223. HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH])
  224. HAVE_WCSFTIME=1; AC_SUBST([HAVE_WCSFTIME])
  225. HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
  226. HAVE_DECL_WCSDUP=1; AC_SUBST([HAVE_DECL_WCSDUP])
  227. HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
  228. REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
  229. REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
  230. REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
  231. REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
  232. REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
  233. REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
  234. REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
  235. REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
  236. REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
  237. REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
  238. REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
  239. REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
  240. REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH])
  241. REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME])
  242. REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK])
  243. ])