wchar_h.m4 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
  2. dnl Copyright (C) 2007-2017 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 40
  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. dnl Check for declarations of anything we want to poison if the
  32. dnl corresponding gnulib module is not in use.
  33. gl_WARN_ON_USE_PREPARE([[
  34. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  35. <wchar.h>.
  36. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  37. included before <wchar.h>. */
  38. #if !(defined __GLIBC__ && !defined __UCLIBC__)
  39. # include <stddef.h>
  40. # include <stdio.h>
  41. # include <time.h>
  42. #endif
  43. #include <wchar.h>
  44. ]],
  45. [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
  46. wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset
  47. wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
  48. wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
  49. wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth
  50. ])
  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 <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
  57. dnl and <http://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_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
  61. [gl_cv_header_wchar_h_correct_inline],
  62. [gl_cv_header_wchar_h_correct_inline=yes
  63. AC_LANG_CONFTEST([
  64. AC_LANG_SOURCE([[#define wcstod renamed_wcstod
  65. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  66. <wchar.h>.
  67. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  68. included before <wchar.h>. */
  69. #include <stddef.h>
  70. #include <stdio.h>
  71. #include <time.h>
  72. #include <wchar.h>
  73. extern int zero (void);
  74. int main () { return zero(); }
  75. ]])])
  76. dnl Do not rename the object file from conftest.$ac_objext to
  77. dnl conftest1.$ac_objext, as this will cause the link to fail on
  78. dnl z/OS when using the XPLINK object format (due to duplicate
  79. dnl CSECT names). Instead, temporarily redefine $ac_compile so
  80. dnl that the object file has the latter name from the start.
  81. save_ac_compile="$ac_compile"
  82. ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest1/`
  83. if AC_TRY_EVAL([ac_compile]); then
  84. AC_LANG_CONFTEST([
  85. AC_LANG_SOURCE([[#define wcstod renamed_wcstod
  86. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  87. <wchar.h>.
  88. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  89. included before <wchar.h>. */
  90. #include <stddef.h>
  91. #include <stdio.h>
  92. #include <time.h>
  93. #include <wchar.h>
  94. int zero (void) { return 0; }
  95. ]])])
  96. dnl See note above about renaming object files.
  97. ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest2/`
  98. if AC_TRY_EVAL([ac_compile]); then
  99. if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
  100. :
  101. else
  102. gl_cv_header_wchar_h_correct_inline=no
  103. fi
  104. fi
  105. fi
  106. ac_compile="$save_ac_compile"
  107. rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
  108. ])
  109. if test $gl_cv_header_wchar_h_correct_inline = no; then
  110. AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
  111. This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
  112. C99 mode. You have four options:
  113. - Add the flag -fgnu89-inline to CC and reconfigure, or
  114. - Fix your include files, using parts of
  115. <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
  116. - Use a gcc version older than 4.3, or
  117. - Don't use the flags -std=c99 or -std=gnu99.
  118. Configuration aborted.])
  119. fi
  120. ])
  121. AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
  122. [
  123. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  124. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  125. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  126. dnl Define it also as a C macro, for the benefit of the unit tests.
  127. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  128. ])
  129. AC_DEFUN([gl_WCHAR_H_DEFAULTS],
  130. [
  131. GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
  132. GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
  133. GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
  134. GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
  135. GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
  136. GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
  137. GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
  138. GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
  139. GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
  140. GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
  141. GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
  142. GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR])
  143. GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP])
  144. GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY])
  145. GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE])
  146. GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET])
  147. GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN])
  148. GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN])
  149. GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY])
  150. GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY])
  151. GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY])
  152. GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY])
  153. GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT])
  154. GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT])
  155. GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP])
  156. GNULIB_WCSNCMP=0; AC_SUBST([GNULIB_WCSNCMP])
  157. GNULIB_WCSCASECMP=0; AC_SUBST([GNULIB_WCSCASECMP])
  158. GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP])
  159. GNULIB_WCSCOLL=0; AC_SUBST([GNULIB_WCSCOLL])
  160. GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM])
  161. GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP])
  162. GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR])
  163. GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR])
  164. GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN])
  165. GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN])
  166. GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK])
  167. GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR])
  168. GNULIB_WCSTOK=0; AC_SUBST([GNULIB_WCSTOK])
  169. GNULIB_WCSWIDTH=0; AC_SUBST([GNULIB_WCSWIDTH])
  170. dnl Assume proper GNU behavior unless another module says otherwise.
  171. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
  172. HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
  173. HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
  174. HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
  175. HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
  176. HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
  177. HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
  178. HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
  179. HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
  180. HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR])
  181. HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP])
  182. HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY])
  183. HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE])
  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_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
  209. HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
  210. REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
  211. REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
  212. REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
  213. REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
  214. REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
  215. REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
  216. REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
  217. REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
  218. REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
  219. REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
  220. REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
  221. REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
  222. REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH])
  223. ])