(_AC_LIBOBJ_FNMATCH): Check for btowc.
[gnulib.git] / m4 / fnmatch.m4
1 # Check for fnmatch.
2
3 # This is a modified version of autoconf's AC_FUNC_FNMATCH.
4 # This file should be removed after Autoconf 2.54 is required.
5
6 # Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # 02111-1307, USA.
22
23 # _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
24 # -------------------------------------------------------------------------
25 # If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
26 # IF-FALSE.  Use CACHE_VAR.
27 AC_DEFUN([_AC_FUNC_FNMATCH_IF],
28 [AC_CACHE_CHECK(
29    [for working $1 fnmatch],
30    [$2],
31   [# Some versions of Solaris, SCO, and the GNU C Library
32    # have a broken or incompatible fnmatch.
33    # So we run a test program.  If we are cross-compiling, take no chance.
34    # Thanks to John Oleynick, Franc,ois Pinard, and Paul Eggert for this test.
35    AC_RUN_IFELSE(
36       [AC_LANG_PROGRAM(
37          [#include <fnmatch.h>
38 #          define y(a, b, c) (fnmatch (a, b, c) == 0)
39 #          define n(a, b, c) (fnmatch (a, b, c) == FNM_NOMATCH)
40          ],
41          [exit
42            (!(y ("a*", "abc", 0)
43               && n ("d*/*1", "d/s/1", FNM_PATHNAME)
44               && y ("a\\\\bc", "abc", 0)
45               && n ("a\\\\bc", "abc", FNM_NOESCAPE)
46               && y ("*x", ".x", 0)
47               && n ("*x", ".x", FNM_PERIOD)
48               && m4_if([$1], [GNU],
49                    [y ("xxXX", "xXxX", FNM_CASEFOLD)
50                     && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
51                     && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
52                     && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
53                     && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
54                     && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
55                    1)));])],
56       [$2=yes],
57       [$2=no],
58       [$2=cross])])
59 AS_IF([test $$2 = yes], [$3], [$4])
60 ])# _AC_FUNC_FNMATCH_IF
61
62
63 # _AC_LIBOBJ_FNMATCH
64 # ------------------
65 # Prepare the replacement of fnmatch.
66 AC_DEFUN([_AC_LIBOBJ_FNMATCH],
67 [AC_REQUIRE([AC_C_CONST])dnl
68 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
69 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
70 AC_CHECK_DECLS([getenv])
71 AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmempcpy])
72 AC_CHECK_HEADERS([wchar.h wctype.h])
73 AC_LIBOBJ([fnmatch])
74 AC_CONFIG_LINKS([lib/fnmatch.h:lib/fnmatch_.h])
75 AC_DEFINE(fnmatch, rpl_fnmatch,
76           [Define to rpl_fnmatch if the replacement function should be used.])
77 ])# _AC_LIBOBJ_FNMATCH
78
79
80 # AC_FUNC_FNMATCH_GNU
81 # -------------------
82 AC_DEFUN([AC_FUNC_FNMATCH_GNU],
83 [AC_REQUIRE([AC_GNU_SOURCE])
84 _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
85                     [rm -f lib/fnmatch.h],
86                     [_AC_LIBOBJ_FNMATCH])
87 ])# AC_FUNC_FNMATCH_GNU