Blame gl/m4/wchar_h.m4

Packit a4aae4
dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
Packit a4aae4
Packit a4aae4
dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
Packit a4aae4
dnl This file is free software; the Free Software Foundation
Packit a4aae4
dnl gives unlimited permission to copy and/or distribute it,
Packit a4aae4
dnl with or without modifications, as long as this notice is preserved.
Packit a4aae4
Packit a4aae4
dnl Written by Eric Blake.
Packit a4aae4
Packit a4aae4
# wchar_h.m4 serial 42
Packit a4aae4
Packit a4aae4
AC_DEFUN([gl_WCHAR_H],
Packit a4aae4
[
Packit a4aae4
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit a4aae4
  AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
Packit a4aae4
  dnl Prepare for creating substitute <wchar.h>.
Packit a4aae4
  dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
Packit a4aae4
  dnl character support).
Packit a4aae4
  dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
Packit a4aae4
  gl_CHECK_NEXT_HEADERS([wchar.h])
Packit a4aae4
  if test $ac_cv_header_wchar_h = yes; then
Packit a4aae4
    HAVE_WCHAR_H=1
Packit a4aae4
  else
Packit a4aae4
    HAVE_WCHAR_H=0
Packit a4aae4
  fi
Packit a4aae4
  AC_SUBST([HAVE_WCHAR_H])
Packit a4aae4
Packit a4aae4
  AC_REQUIRE([gl_FEATURES_H])
Packit a4aae4
Packit a4aae4
  AC_REQUIRE([gt_TYPE_WINT_T])
Packit a4aae4
  if test $gt_cv_c_wint_t = yes; then
Packit a4aae4
    HAVE_WINT_T=1
Packit a4aae4
  else
Packit a4aae4
    HAVE_WINT_T=0
Packit a4aae4
  fi
Packit a4aae4
  AC_SUBST([HAVE_WINT_T])
Packit a4aae4
Packit a4aae4
  AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
Packit a4aae4
Packit a4aae4
  dnl Check for declarations of anything we want to poison if the
Packit a4aae4
  dnl corresponding gnulib module is not in use.
Packit a4aae4
  gl_WARN_ON_USE_PREPARE([[
Packit a4aae4
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit a4aae4
   <wchar.h>.
Packit a4aae4
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit a4aae4
   included before <wchar.h>.  */
Packit a4aae4
#if !(defined __GLIBC__ && !defined __UCLIBC__)
Packit a4aae4
# include <stddef.h>
Packit a4aae4
# include <stdio.h>
Packit a4aae4
# include <time.h>
Packit a4aae4
#endif
Packit a4aae4
#include <wchar.h>
Packit a4aae4
    ]],
Packit a4aae4
    [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
Packit a4aae4
     wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset
Packit a4aae4
     wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
Packit a4aae4
     wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
Packit a4aae4
     wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
Packit a4aae4
    ])
Packit a4aae4
])
Packit a4aae4
Packit a4aae4
dnl Check whether <wchar.h> is usable at all.
Packit a4aae4
AC_DEFUN([gl_WCHAR_H_INLINE_OK],
Packit a4aae4
[
Packit a4aae4
  dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
Packit a4aae4
  dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
Packit a4aae4
  dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
Packit a4aae4
  dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
Packit a4aae4
  dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
Packit a4aae4
  AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
Packit a4aae4
    [gl_cv_header_wchar_h_correct_inline],
Packit a4aae4
    [gl_cv_header_wchar_h_correct_inline=yes
Packit a4aae4
     AC_LANG_CONFTEST([
Packit a4aae4
       AC_LANG_SOURCE([[#define wcstod renamed_wcstod
Packit a4aae4
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit a4aae4
   <wchar.h>.
Packit a4aae4
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit a4aae4
   included before <wchar.h>.  */
Packit a4aae4
#include <stddef.h>
Packit a4aae4
#include <stdio.h>
Packit a4aae4
#include <time.h>
Packit a4aae4
#include <wchar.h>
Packit a4aae4
extern int zero (void);
Packit a4aae4
int main () { return zero(); }
Packit a4aae4
]])])
Packit a4aae4
     dnl Do not rename the object file from conftest.$ac_objext to
Packit a4aae4
     dnl conftest1.$ac_objext, as this will cause the link to fail on
Packit a4aae4
     dnl z/OS when using the XPLINK object format (due to duplicate
Packit a4aae4
     dnl CSECT names). Instead, temporarily redefine $ac_compile so
Packit a4aae4
     dnl that the object file has the latter name from the start.
Packit a4aae4
     save_ac_compile="$ac_compile"
Packit a4aae4
     ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest1/`
Packit a4aae4
     if AC_TRY_EVAL([ac_compile]); then
Packit a4aae4
       AC_LANG_CONFTEST([
Packit a4aae4
         AC_LANG_SOURCE([[#define wcstod renamed_wcstod
Packit a4aae4
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit a4aae4
   <wchar.h>.
Packit a4aae4
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit a4aae4
   included before <wchar.h>.  */
Packit a4aae4
#include <stddef.h>
Packit a4aae4
#include <stdio.h>
Packit a4aae4
#include <time.h>
Packit a4aae4
#include <wchar.h>
Packit a4aae4
int zero (void) { return 0; }
Packit a4aae4
]])])
Packit a4aae4
       dnl See note above about renaming object files.
Packit a4aae4
       ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest2/`
Packit a4aae4
       if AC_TRY_EVAL([ac_compile]); then
Packit a4aae4
         if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
Packit a4aae4
           :
Packit a4aae4
         else
Packit a4aae4
           gl_cv_header_wchar_h_correct_inline=no
Packit a4aae4
         fi
Packit a4aae4
       fi
Packit a4aae4
     fi
Packit a4aae4
     ac_compile="$save_ac_compile"
Packit a4aae4
     rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
Packit a4aae4
    ])
Packit a4aae4
  if test $gl_cv_header_wchar_h_correct_inline = no; then
Packit a4aae4
    AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
Packit a4aae4
This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
Packit a4aae4
C99 mode. You have four options:
Packit a4aae4
  - Add the flag -fgnu89-inline to CC and reconfigure, or
Packit a4aae4
  - Fix your include files, using parts of
Packit a4aae4
    <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
Packit a4aae4
  - Use a gcc version older than 4.3, or
Packit a4aae4
  - Don't use the flags -std=c99 or -std=gnu99.
Packit a4aae4
Configuration aborted.])
Packit a4aae4
  fi
Packit a4aae4
])
Packit a4aae4
Packit a4aae4
AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
Packit a4aae4
[
Packit a4aae4
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
Packit a4aae4
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit a4aae4
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
Packit a4aae4
  dnl Define it also as a C macro, for the benefit of the unit tests.
Packit a4aae4
  gl_MODULE_INDICATOR_FOR_TESTS([$1])
Packit a4aae4
])
Packit a4aae4
Packit a4aae4
AC_DEFUN([gl_WCHAR_H_DEFAULTS],
Packit a4aae4
[
Packit a4aae4
  GNULIB_BTOWC=0;       AC_SUBST([GNULIB_BTOWC])
Packit a4aae4
  GNULIB_WCTOB=0;       AC_SUBST([GNULIB_WCTOB])
Packit a4aae4
  GNULIB_MBSINIT=0;     AC_SUBST([GNULIB_MBSINIT])
Packit a4aae4
  GNULIB_MBRTOWC=0;     AC_SUBST([GNULIB_MBRTOWC])
Packit a4aae4
  GNULIB_MBRLEN=0;      AC_SUBST([GNULIB_MBRLEN])
Packit a4aae4
  GNULIB_MBSRTOWCS=0;   AC_SUBST([GNULIB_MBSRTOWCS])
Packit a4aae4
  GNULIB_MBSNRTOWCS=0;  AC_SUBST([GNULIB_MBSNRTOWCS])
Packit a4aae4
  GNULIB_WCRTOMB=0;     AC_SUBST([GNULIB_WCRTOMB])
Packit a4aae4
  GNULIB_WCSRTOMBS=0;   AC_SUBST([GNULIB_WCSRTOMBS])
Packit a4aae4
  GNULIB_WCSNRTOMBS=0;  AC_SUBST([GNULIB_WCSNRTOMBS])
Packit a4aae4
  GNULIB_WCWIDTH=0;     AC_SUBST([GNULIB_WCWIDTH])
Packit a4aae4
  GNULIB_WMEMCHR=0;     AC_SUBST([GNULIB_WMEMCHR])
Packit a4aae4
  GNULIB_WMEMCMP=0;     AC_SUBST([GNULIB_WMEMCMP])
Packit a4aae4
  GNULIB_WMEMCPY=0;     AC_SUBST([GNULIB_WMEMCPY])
Packit a4aae4
  GNULIB_WMEMMOVE=0;    AC_SUBST([GNULIB_WMEMMOVE])
Packit a4aae4
  GNULIB_WMEMSET=0;     AC_SUBST([GNULIB_WMEMSET])
Packit a4aae4
  GNULIB_WCSLEN=0;      AC_SUBST([GNULIB_WCSLEN])
Packit a4aae4
  GNULIB_WCSNLEN=0;     AC_SUBST([GNULIB_WCSNLEN])
Packit a4aae4
  GNULIB_WCSCPY=0;      AC_SUBST([GNULIB_WCSCPY])
Packit a4aae4
  GNULIB_WCPCPY=0;      AC_SUBST([GNULIB_WCPCPY])
Packit a4aae4
  GNULIB_WCSNCPY=0;     AC_SUBST([GNULIB_WCSNCPY])
Packit a4aae4
  GNULIB_WCPNCPY=0;     AC_SUBST([GNULIB_WCPNCPY])
Packit a4aae4
  GNULIB_WCSCAT=0;      AC_SUBST([GNULIB_WCSCAT])
Packit a4aae4
  GNULIB_WCSNCAT=0;     AC_SUBST([GNULIB_WCSNCAT])
Packit a4aae4
  GNULIB_WCSCMP=0;      AC_SUBST([GNULIB_WCSCMP])
Packit a4aae4
  GNULIB_WCSNCMP=0;     AC_SUBST([GNULIB_WCSNCMP])
Packit a4aae4
  GNULIB_WCSCASECMP=0;  AC_SUBST([GNULIB_WCSCASECMP])
Packit a4aae4
  GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP])
Packit a4aae4
  GNULIB_WCSCOLL=0;     AC_SUBST([GNULIB_WCSCOLL])
Packit a4aae4
  GNULIB_WCSXFRM=0;     AC_SUBST([GNULIB_WCSXFRM])
Packit a4aae4
  GNULIB_WCSDUP=0;      AC_SUBST([GNULIB_WCSDUP])
Packit a4aae4
  GNULIB_WCSCHR=0;      AC_SUBST([GNULIB_WCSCHR])
Packit a4aae4
  GNULIB_WCSRCHR=0;     AC_SUBST([GNULIB_WCSRCHR])
Packit a4aae4
  GNULIB_WCSCSPN=0;     AC_SUBST([GNULIB_WCSCSPN])
Packit a4aae4
  GNULIB_WCSSPN=0;      AC_SUBST([GNULIB_WCSSPN])
Packit a4aae4
  GNULIB_WCSPBRK=0;     AC_SUBST([GNULIB_WCSPBRK])
Packit a4aae4
  GNULIB_WCSSTR=0;      AC_SUBST([GNULIB_WCSSTR])
Packit a4aae4
  GNULIB_WCSTOK=0;      AC_SUBST([GNULIB_WCSTOK])
Packit a4aae4
  GNULIB_WCSWIDTH=0;    AC_SUBST([GNULIB_WCSWIDTH])
Packit a4aae4
  GNULIB_WCSFTIME=0;    AC_SUBST([GNULIB_WCSFTIME])
Packit a4aae4
  dnl Assume proper GNU behavior unless another module says otherwise.
Packit a4aae4
  HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
Packit a4aae4
  HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
Packit a4aae4
  HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
Packit a4aae4
  HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
Packit a4aae4
  HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
Packit a4aae4
  HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
Packit a4aae4
  HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
Packit a4aae4
  HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
Packit a4aae4
  HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
Packit a4aae4
  HAVE_WMEMCHR=1;       AC_SUBST([HAVE_WMEMCHR])
Packit a4aae4
  HAVE_WMEMCMP=1;       AC_SUBST([HAVE_WMEMCMP])
Packit a4aae4
  HAVE_WMEMCPY=1;       AC_SUBST([HAVE_WMEMCPY])
Packit a4aae4
  HAVE_WMEMMOVE=1;      AC_SUBST([HAVE_WMEMMOVE])
Packit a4aae4
  HAVE_WMEMSET=1;       AC_SUBST([HAVE_WMEMSET])
Packit a4aae4
  HAVE_WCSLEN=1;        AC_SUBST([HAVE_WCSLEN])
Packit a4aae4
  HAVE_WCSNLEN=1;       AC_SUBST([HAVE_WCSNLEN])
Packit a4aae4
  HAVE_WCSCPY=1;        AC_SUBST([HAVE_WCSCPY])
Packit a4aae4
  HAVE_WCPCPY=1;        AC_SUBST([HAVE_WCPCPY])
Packit a4aae4
  HAVE_WCSNCPY=1;       AC_SUBST([HAVE_WCSNCPY])
Packit a4aae4
  HAVE_WCPNCPY=1;       AC_SUBST([HAVE_WCPNCPY])
Packit a4aae4
  HAVE_WCSCAT=1;        AC_SUBST([HAVE_WCSCAT])
Packit a4aae4
  HAVE_WCSNCAT=1;       AC_SUBST([HAVE_WCSNCAT])
Packit a4aae4
  HAVE_WCSCMP=1;        AC_SUBST([HAVE_WCSCMP])
Packit a4aae4
  HAVE_WCSNCMP=1;       AC_SUBST([HAVE_WCSNCMP])
Packit a4aae4
  HAVE_WCSCASECMP=1;    AC_SUBST([HAVE_WCSCASECMP])
Packit a4aae4
  HAVE_WCSNCASECMP=1;   AC_SUBST([HAVE_WCSNCASECMP])
Packit a4aae4
  HAVE_WCSCOLL=1;       AC_SUBST([HAVE_WCSCOLL])
Packit a4aae4
  HAVE_WCSXFRM=1;       AC_SUBST([HAVE_WCSXFRM])
Packit a4aae4
  HAVE_WCSDUP=1;        AC_SUBST([HAVE_WCSDUP])
Packit a4aae4
  HAVE_WCSCHR=1;        AC_SUBST([HAVE_WCSCHR])
Packit a4aae4
  HAVE_WCSRCHR=1;       AC_SUBST([HAVE_WCSRCHR])
Packit a4aae4
  HAVE_WCSCSPN=1;       AC_SUBST([HAVE_WCSCSPN])
Packit a4aae4
  HAVE_WCSSPN=1;        AC_SUBST([HAVE_WCSSPN])
Packit a4aae4
  HAVE_WCSPBRK=1;       AC_SUBST([HAVE_WCSPBRK])
Packit a4aae4
  HAVE_WCSSTR=1;        AC_SUBST([HAVE_WCSSTR])
Packit a4aae4
  HAVE_WCSTOK=1;        AC_SUBST([HAVE_WCSTOK])
Packit a4aae4
  HAVE_WCSWIDTH=1;      AC_SUBST([HAVE_WCSWIDTH])
Packit a4aae4
  HAVE_WCSFTIME=1;      AC_SUBST([HAVE_WCSFTIME])
Packit a4aae4
  HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
Packit a4aae4
  HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
Packit a4aae4
  REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
Packit a4aae4
  REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
Packit a4aae4
  REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
Packit a4aae4
  REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
Packit a4aae4
  REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
Packit a4aae4
  REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
Packit a4aae4
  REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
Packit a4aae4
  REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
Packit a4aae4
  REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
Packit a4aae4
  REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
Packit a4aae4
  REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
Packit a4aae4
  REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
Packit a4aae4
  REPLACE_WCSWIDTH=0;   AC_SUBST([REPLACE_WCSWIDTH])
Packit a4aae4
  REPLACE_WCSFTIME=0;   AC_SUBST([REPLACE_WCSFTIME])
Packit a4aae4
])