Home | History | Annotate | Line # | Download | only in m4
      1      1.1  christos dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
      2      1.1  christos 
      3  1.1.1.2  christos dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
      4      1.1  christos dnl This file is free software; the Free Software Foundation
      5      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      6      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      7      1.1  christos 
      8      1.1  christos dnl Written by Eric Blake.
      9      1.1  christos 
     10  1.1.1.2  christos # wchar_h.m4 serial 55
     11      1.1  christos 
     12  1.1.1.2  christos AC_DEFUN_ONCE([gl_WCHAR_H],
     13      1.1  christos [
     14      1.1  christos   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
     15      1.1  christos   AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
     16      1.1  christos   dnl Prepare for creating substitute <wchar.h>.
     17      1.1  christos   dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
     18      1.1  christos   dnl character support).
     19      1.1  christos   dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
     20      1.1  christos   gl_CHECK_NEXT_HEADERS([wchar.h])
     21      1.1  christos   if test $ac_cv_header_wchar_h = yes; then
     22      1.1  christos     HAVE_WCHAR_H=1
     23      1.1  christos   else
     24      1.1  christos     HAVE_WCHAR_H=0
     25      1.1  christos   fi
     26      1.1  christos   AC_SUBST([HAVE_WCHAR_H])
     27      1.1  christos 
     28      1.1  christos   AC_REQUIRE([gl_FEATURES_H])
     29      1.1  christos 
     30      1.1  christos   AC_REQUIRE([gt_TYPE_WINT_T])
     31      1.1  christos   if test $gt_cv_c_wint_t = yes; then
     32      1.1  christos     HAVE_WINT_T=1
     33      1.1  christos   else
     34      1.1  christos     HAVE_WINT_T=0
     35      1.1  christos   fi
     36      1.1  christos   AC_SUBST([HAVE_WINT_T])
     37      1.1  christos 
     38      1.1  christos   AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
     39      1.1  christos 
     40      1.1  christos   dnl Check for declarations of anything we want to poison if the
     41      1.1  christos   dnl corresponding gnulib module is not in use.
     42      1.1  christos   gl_WARN_ON_USE_PREPARE([[
     43  1.1.1.2  christos       #include <wchar.h>
     44      1.1  christos     ]],
     45      1.1  christos     [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
     46      1.1  christos      wcsrtombs wcsnrtombs wcwidth
     47      1.1  christos      wmemchr wmemcmp wmemcpy wmemmove wmempcpy wmemset
     48      1.1  christos      wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
     49      1.1  christos      wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
     50      1.1  christos      wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
     51      1.1  christos     ])
     52      1.1  christos 
     53      1.1  christos   AC_REQUIRE([AC_C_RESTRICT])
     54  1.1.1.2  christos 
     55  1.1.1.2  christos   AC_CHECK_DECLS([wcsdup], [], [], [[
     56  1.1.1.2  christos       #include <wchar.h>
     57  1.1.1.2  christos     ]])
     58  1.1.1.2  christos   if test $ac_cv_have_decl_wcsdup = no; then
     59  1.1.1.2  christos     HAVE_DECL_WCSDUP=0
     60  1.1.1.2  christos   fi
     61      1.1  christos ])
     62      1.1  christos 
     63      1.1  christos dnl Check whether <wchar.h> is usable at all.
     64      1.1  christos AC_DEFUN([gl_WCHAR_H_INLINE_OK],
     65      1.1  christos [
     66      1.1  christos   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
     67      1.1  christos   dnl 'gnu_inline'. See <https://sourceware.org/bugzilla/show_bug.cgi?id=4022>
     68      1.1  christos   dnl and <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
     69      1.1  christos   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
     70      1.1  christos   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
     71  1.1.1.2  christos   AC_REQUIRE([AC_CANONICAL_HOST])
     72      1.1  christos   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
     73      1.1  christos     [gl_cv_header_wchar_h_correct_inline],
     74      1.1  christos     [gl_cv_header_wchar_h_correct_inline=yes
     75  1.1.1.2  christos      case "$host_os" in
     76  1.1.1.2  christos        *-gnu* | gnu*)
     77  1.1.1.2  christos          AC_LANG_CONFTEST([
     78  1.1.1.2  christos            AC_LANG_SOURCE([[
     79  1.1.1.2  christos              #define wcstod renamed_wcstod
     80  1.1.1.2  christos              #include <wchar.h>
     81  1.1.1.2  christos              extern int zero (void);
     82  1.1.1.2  christos              int main () { return zero(); }
     83  1.1.1.2  christos            ]])])
     84  1.1.1.2  christos          dnl Do not rename the object file from conftest.$ac_objext to
     85  1.1.1.2  christos          dnl conftest1.$ac_objext, as this will cause the link to fail on
     86  1.1.1.2  christos          dnl z/OS when using the XPLINK object format (due to duplicate
     87  1.1.1.2  christos          dnl CSECT names). Instead, temporarily redefine $ac_compile so
     88  1.1.1.2  christos          dnl that the object file has the latter name from the start.
     89  1.1.1.2  christos          save_ac_compile="$ac_compile"
     90  1.1.1.2  christos          ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest1/`
     91  1.1.1.2  christos          if echo '#include "conftest.c"' >conftest1.c \
     92  1.1.1.2  christos             && AC_TRY_EVAL([ac_compile]); then
     93  1.1.1.2  christos            AC_LANG_CONFTEST([
     94  1.1.1.2  christos              AC_LANG_SOURCE([[
     95  1.1.1.2  christos                #define wcstod renamed_wcstod
     96  1.1.1.2  christos                #include <wchar.h>
     97  1.1.1.2  christos                int zero (void) { return 0; }
     98  1.1.1.2  christos              ]])])
     99  1.1.1.2  christos            dnl See note above about renaming object files.
    100  1.1.1.2  christos            ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest2/`
    101  1.1.1.2  christos            if echo '#include "conftest.c"' >conftest2.c \
    102  1.1.1.2  christos               && AC_TRY_EVAL([ac_compile]); then
    103  1.1.1.2  christos              if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
    104  1.1.1.2  christos                :
    105  1.1.1.2  christos              else
    106  1.1.1.2  christos                gl_cv_header_wchar_h_correct_inline=no
    107  1.1.1.2  christos              fi
    108  1.1.1.2  christos            fi
    109      1.1  christos          fi
    110  1.1.1.2  christos          ac_compile="$save_ac_compile"
    111  1.1.1.2  christos          rm -f conftest[12].c conftest[12].$ac_objext conftest$ac_exeext
    112  1.1.1.2  christos          ;;
    113  1.1.1.2  christos      esac
    114      1.1  christos     ])
    115      1.1  christos   if test $gl_cv_header_wchar_h_correct_inline = no; then
    116      1.1  christos     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
    117      1.1  christos This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
    118      1.1  christos C99 mode. You have four options:
    119      1.1  christos   - Add the flag -fgnu89-inline to CC and reconfigure, or
    120      1.1  christos   - Fix your include files, using parts of
    121      1.1  christos     <https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
    122      1.1  christos   - Use a gcc version older than 4.3, or
    123      1.1  christos   - Don't use the flags -std=c99 or -std=gnu99.
    124      1.1  christos Configuration aborted.])
    125      1.1  christos   fi
    126      1.1  christos ])
    127      1.1  christos 
    128  1.1.1.2  christos # gl_WCHAR_MODULE_INDICATOR([modulename])
    129  1.1.1.2  christos # sets the shell variable that indicates the presence of the given module
    130  1.1.1.2  christos # to a C preprocessor expression that will evaluate to 1.
    131  1.1.1.2  christos # This macro invocation must not occur in macros that are AC_REQUIREd.
    132      1.1  christos AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
    133      1.1  christos [
    134  1.1.1.2  christos   dnl Ensure to expand the default settings once only.
    135  1.1.1.2  christos   gl_WCHAR_H_REQUIRE_DEFAULTS
    136      1.1  christos   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
    137      1.1  christos   dnl Define it also as a C macro, for the benefit of the unit tests.
    138      1.1  christos   gl_MODULE_INDICATOR_FOR_TESTS([$1])
    139      1.1  christos ])
    140      1.1  christos 
    141  1.1.1.2  christos # Initializes the default values for AC_SUBSTed shell variables.
    142  1.1.1.2  christos # This macro must not be AC_REQUIREd.  It must only be invoked, and only
    143  1.1.1.2  christos # outside of macros or in macros that are not AC_REQUIREd.
    144  1.1.1.2  christos AC_DEFUN([gl_WCHAR_H_REQUIRE_DEFAULTS],
    145  1.1.1.2  christos [
    146  1.1.1.2  christos   m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS], [
    147  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BTOWC])
    148  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOB])
    149  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSINIT])
    150  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOWC])
    151  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRLEN])
    152  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOWCS])
    153  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOWCS])
    154  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCRTOMB])
    155  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRTOMBS])
    156  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNRTOMBS])
    157  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCWIDTH])
    158  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCHR])
    159  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCMP])
    160  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCPY])
    161  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMMOVE])
    162  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMPCPY])
    163  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMSET])
    164  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSLEN])
    165  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNLEN])
    166  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCPY])
    167  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPCPY])
    168  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCPY])
    169  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPNCPY])
    170  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCAT])
    171  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCAT])
    172  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCMP])
    173  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCMP])
    174  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCASECMP])
    175  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCASECMP])
    176  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCOLL])
    177  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSXFRM])
    178  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSDUP])
    179  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCHR])
    180  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRCHR])
    181  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCSPN])
    182  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSPN])
    183  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSPBRK])
    184  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSTR])
    185  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSTOK])
    186  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSWIDTH])
    187  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSFTIME])
    188  1.1.1.2  christos     dnl Support Microsoft deprecated alias function names by default.
    189  1.1.1.2  christos     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WCSDUP], [1])
    190  1.1.1.2  christos   ])
    191  1.1.1.2  christos   m4_require(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS])
    192  1.1.1.2  christos   dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
    193  1.1.1.2  christos   gl_STDLIB_H_REQUIRE_DEFAULTS
    194  1.1.1.2  christos   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
    195  1.1.1.2  christos ])
    196  1.1.1.2  christos 
    197      1.1  christos AC_DEFUN([gl_WCHAR_H_DEFAULTS],
    198      1.1  christos [
    199      1.1  christos   dnl Assume proper GNU behavior unless another module says otherwise.
    200      1.1  christos   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
    201      1.1  christos   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
    202      1.1  christos   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
    203      1.1  christos   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
    204      1.1  christos   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
    205      1.1  christos   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
    206      1.1  christos   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
    207      1.1  christos   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
    208      1.1  christos   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
    209      1.1  christos   HAVE_WMEMCHR=1;       AC_SUBST([HAVE_WMEMCHR])
    210      1.1  christos   HAVE_WMEMCMP=1;       AC_SUBST([HAVE_WMEMCMP])
    211      1.1  christos   HAVE_WMEMCPY=1;       AC_SUBST([HAVE_WMEMCPY])
    212      1.1  christos   HAVE_WMEMMOVE=1;      AC_SUBST([HAVE_WMEMMOVE])
    213      1.1  christos   HAVE_WMEMPCPY=1;      AC_SUBST([HAVE_WMEMPCPY])
    214      1.1  christos   HAVE_WMEMSET=1;       AC_SUBST([HAVE_WMEMSET])
    215      1.1  christos   HAVE_WCSLEN=1;        AC_SUBST([HAVE_WCSLEN])
    216      1.1  christos   HAVE_WCSNLEN=1;       AC_SUBST([HAVE_WCSNLEN])
    217      1.1  christos   HAVE_WCSCPY=1;        AC_SUBST([HAVE_WCSCPY])
    218      1.1  christos   HAVE_WCPCPY=1;        AC_SUBST([HAVE_WCPCPY])
    219      1.1  christos   HAVE_WCSNCPY=1;       AC_SUBST([HAVE_WCSNCPY])
    220      1.1  christos   HAVE_WCPNCPY=1;       AC_SUBST([HAVE_WCPNCPY])
    221      1.1  christos   HAVE_WCSCAT=1;        AC_SUBST([HAVE_WCSCAT])
    222      1.1  christos   HAVE_WCSNCAT=1;       AC_SUBST([HAVE_WCSNCAT])
    223      1.1  christos   HAVE_WCSCMP=1;        AC_SUBST([HAVE_WCSCMP])
    224      1.1  christos   HAVE_WCSNCMP=1;       AC_SUBST([HAVE_WCSNCMP])
    225      1.1  christos   HAVE_WCSCASECMP=1;    AC_SUBST([HAVE_WCSCASECMP])
    226      1.1  christos   HAVE_WCSNCASECMP=1;   AC_SUBST([HAVE_WCSNCASECMP])
    227      1.1  christos   HAVE_WCSCOLL=1;       AC_SUBST([HAVE_WCSCOLL])
    228      1.1  christos   HAVE_WCSXFRM=1;       AC_SUBST([HAVE_WCSXFRM])
    229      1.1  christos   HAVE_WCSDUP=1;        AC_SUBST([HAVE_WCSDUP])
    230      1.1  christos   HAVE_WCSCHR=1;        AC_SUBST([HAVE_WCSCHR])
    231      1.1  christos   HAVE_WCSRCHR=1;       AC_SUBST([HAVE_WCSRCHR])
    232      1.1  christos   HAVE_WCSCSPN=1;       AC_SUBST([HAVE_WCSCSPN])
    233      1.1  christos   HAVE_WCSSPN=1;        AC_SUBST([HAVE_WCSSPN])
    234      1.1  christos   HAVE_WCSPBRK=1;       AC_SUBST([HAVE_WCSPBRK])
    235      1.1  christos   HAVE_WCSSTR=1;        AC_SUBST([HAVE_WCSSTR])
    236      1.1  christos   HAVE_WCSTOK=1;        AC_SUBST([HAVE_WCSTOK])
    237      1.1  christos   HAVE_WCSWIDTH=1;      AC_SUBST([HAVE_WCSWIDTH])
    238      1.1  christos   HAVE_WCSFTIME=1;      AC_SUBST([HAVE_WCSFTIME])
    239      1.1  christos   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
    240  1.1.1.2  christos   HAVE_DECL_WCSDUP=1;   AC_SUBST([HAVE_DECL_WCSDUP])
    241      1.1  christos   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
    242      1.1  christos   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
    243      1.1  christos   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
    244      1.1  christos   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
    245      1.1  christos   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
    246      1.1  christos   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
    247      1.1  christos   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
    248      1.1  christos   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
    249      1.1  christos   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
    250      1.1  christos   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
    251      1.1  christos   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
    252      1.1  christos   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
    253      1.1  christos   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
    254      1.1  christos   REPLACE_WCSWIDTH=0;   AC_SUBST([REPLACE_WCSWIDTH])
    255      1.1  christos   REPLACE_WCSFTIME=0;   AC_SUBST([REPLACE_WCSFTIME])
    256      1.1  christos   REPLACE_WCSTOK=0;     AC_SUBST([REPLACE_WCSTOK])
    257      1.1  christos ])
    258