wchar_h.m4 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
  2. dnl Copyright (C) 2007-2010 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 33
  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. AC_CHECK_HEADERS_ONCE([wchar.h])
  17. gl_CHECK_NEXT_HEADERS([wchar.h])
  18. if test $ac_cv_header_wchar_h = yes; then
  19. HAVE_WCHAR_H=1
  20. else
  21. HAVE_WCHAR_H=0
  22. fi
  23. AC_SUBST([HAVE_WCHAR_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. /* Some systems require additional headers. */
  35. #ifndef __GLIBC__
  36. # include <stddef.h>
  37. # include <stdio.h>
  38. # include <time.h>
  39. #endif
  40. #include <wchar.h>
  41. ]], [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
  42. wcsrtombs wcsnrtombs wcwidth])
  43. ])
  44. dnl Check whether <wchar.h> is usable at all.
  45. AC_DEFUN([gl_WCHAR_H_INLINE_OK],
  46. [
  47. dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
  48. dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
  49. dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
  50. dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
  51. dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
  52. AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
  53. [gl_cv_header_wchar_h_correct_inline],
  54. [gl_cv_header_wchar_h_correct_inline=yes
  55. AC_LANG_CONFTEST([
  56. AC_LANG_SOURCE([[#define wcstod renamed_wcstod
  57. #include <wchar.h>
  58. extern int zero (void);
  59. int main () { return zero(); }
  60. ]])])
  61. if AC_TRY_EVAL([ac_compile]); then
  62. mv conftest.$ac_objext conftest1.$ac_objext
  63. AC_LANG_CONFTEST([
  64. AC_LANG_SOURCE([[#define wcstod renamed_wcstod
  65. #include <wchar.h>
  66. int zero (void) { return 0; }
  67. ]])])
  68. if AC_TRY_EVAL([ac_compile]); then
  69. mv conftest.$ac_objext conftest2.$ac_objext
  70. if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
  71. :
  72. else
  73. gl_cv_header_wchar_h_correct_inline=no
  74. fi
  75. fi
  76. fi
  77. rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
  78. ])
  79. if test $gl_cv_header_wchar_h_correct_inline = no; then
  80. AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
  81. This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
  82. C99 mode. You have four options:
  83. - Add the flag -fgnu89-inline to CC and reconfigure, or
  84. - Fix your include files, using parts of
  85. <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
  86. - Use a gcc version older than 4.3, or
  87. - Don't use the flags -std=c99 or -std=gnu99.
  88. Configuration aborted.])
  89. fi
  90. ])
  91. dnl Unconditionally enables the replacement of <wchar.h>.
  92. AC_DEFUN([gl_REPLACE_WCHAR_H],
  93. [
  94. dnl This is a no-op, because <wchar.h> is always overridden.
  95. :
  96. ])
  97. AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
  98. [
  99. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  100. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  101. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  102. dnl Define it also as a C macro, for the benefit of the unit tests.
  103. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  104. ])
  105. AC_DEFUN([gl_WCHAR_H_DEFAULTS],
  106. [
  107. GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
  108. GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
  109. GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
  110. GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
  111. GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
  112. GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
  113. GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
  114. GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
  115. GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
  116. GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
  117. GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
  118. dnl Assume proper GNU behavior unless another module says otherwise.
  119. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
  120. HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
  121. HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
  122. HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
  123. HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
  124. HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
  125. HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
  126. HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
  127. HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
  128. HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
  129. HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
  130. REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
  131. REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
  132. REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
  133. REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
  134. REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
  135. REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
  136. REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
  137. REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
  138. REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
  139. REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
  140. REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
  141. REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
  142. ])