spawn: Use special invocation for <spawn.h> on OS/2 kLIBC.
[gnulib.git] / m4 / wcwidth.m4
blob40fdea714d6665a610aa6f86dbe4ffaf16088eab
1 # wcwidth.m4 serial 33
2 dnl Copyright (C) 2006-2021 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.
7 AC_DEFUN([gl_FUNC_WCWIDTH],
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   dnl Persuade glibc <wchar.h> to declare wcwidth().
13   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15   AC_REQUIRE([gt_TYPE_WCHAR_T])
16   AC_REQUIRE([gt_TYPE_WINT_T])
18   AC_CHECK_HEADERS_ONCE([wchar.h])
19   AC_CHECK_FUNCS_ONCE([wcwidth])
21   AC_CHECK_DECLS([wcwidth], [], [], [[
22     #include <wchar.h>
23   ]])
24   if test $ac_cv_have_decl_wcwidth != yes; then
25     HAVE_DECL_WCWIDTH=0
26   fi
28   if test $ac_cv_func_wcwidth != yes; then
29     AC_CACHE_CHECK([whether wcwidth is a macro],
30       [gl_cv_func_wcwidth_macro],
31       [AC_EGREP_CPP([wchar_header_defines_wcwidth], [
32 #include <wchar.h>
33 #ifdef wcwidth
34  wchar_header_defines_wcwidth
35 #endif],
36          [gl_cv_func_wcwidth_macro=yes],
37          [gl_cv_func_wcwidth_macro=no])
38       ])
39   fi
41   if test $ac_cv_func_wcwidth = yes || test $gl_cv_func_wcwidth_macro = yes; then
42     HAVE_WCWIDTH=1
43     dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
44     dnl On NetBSD 9.0, OpenBSD 5.0, wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
45     dnl On NetBSD 9.0, OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
46     dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
47     dnl This leads to bugs in 'ls' (coreutils).
48     dnl On Solaris 11.4, wcwidth(0x2202) (PARTIAL DIFFERENTIAL) returns 2,
49     dnl even in Western locales.
50     AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
51       [gl_cv_func_wcwidth_works],
52       [
53         AC_RUN_IFELSE(
54           [AC_LANG_SOURCE([[
55 #include <locale.h>
56 #include <wchar.h>
57 #if !HAVE_DECL_WCWIDTH
58 extern
59 # ifdef __cplusplus
60 "C"
61 # endif
62 int wcwidth (int);
63 #endif
64 int main ()
66   int result = 0;
67   if (setlocale (LC_ALL, "en_US.UTF-8") != NULL)
68     {
69       if (wcwidth (0x0301) > 0)
70         result |= 1;
71       if (wcwidth (0x05B0) > 0)
72         result |= 2;
73       if (wcwidth (0x200B) > 0)
74         result |= 4;
75       if (wcwidth (0xFF1A) == 0)
76         result |= 8;
77       if (wcwidth (0x2202) > 1)
78         result |= 16;
79     }
80   return result;
81 }]])],
82           [gl_cv_func_wcwidth_works=yes],
83           [gl_cv_func_wcwidth_works=no],
84           [
85 changequote(,)dnl
86            case "$host_os" in
87                             # Guess yes on glibc systems.
88              *-gnu* | gnu*) gl_cv_func_wcwidth_works="guessing yes";;
89                             # Guess yes on musl systems.
90              *-musl*)       gl_cv_func_wcwidth_works="guessing yes";;
91                             # Guess yes on AIX 7 systems.
92              aix[7-9]*)     gl_cv_func_wcwidth_works="guessing yes";;
93              *)             gl_cv_func_wcwidth_works="$gl_cross_guess_normal";;
94            esac
95 changequote([,])dnl
96           ])
97       ])
98     case "$gl_cv_func_wcwidth_works" in
99       *yes) ;;
100       *no) REPLACE_WCWIDTH=1 ;;
101     esac
102   else
103     HAVE_WCWIDTH=0
104   fi
105   dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
106   dnl have the wcwidth function, then it does not declare it.
109 # Prerequisites of lib/wcwidth.c.
110 AC_DEFUN([gl_PREREQ_WCWIDTH], [
111   AC_REQUIRE([AC_C_INLINE])
112   :