Blame m4/wchar_h.m4

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