Update copyright.
[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 simplified after Autoconf 2.57 is required.
5
6 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
7 # Foundation, Inc.
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
11
12 # _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
13 # -------------------------------------------------------------------------
14 # If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
15 # IF-FALSE.  Use CACHE_VAR.
16 AC_DEFUN([_AC_FUNC_FNMATCH_IF],
17 [AC_CACHE_CHECK(
18    [for working $1 fnmatch],
19    [$2],
20   [dnl Some versions of Solaris, SCO, and the GNU C Library
21    dnl have a broken or incompatible fnmatch.
22    dnl So we run a test program.  If we are cross-compiling, take no chance.
23    dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this test.
24    AC_RUN_IFELSE(
25       [AC_LANG_PROGRAM(
26          [
27 #          include <stdlib.h>
28 #          include <fnmatch.h>
29 #          define y(a, b, c) (fnmatch (a, b, c) == 0)
30 #          define n(a, b, c) (fnmatch (a, b, c) == FNM_NOMATCH)
31            static int
32            fnm (char const *pattern, char const *string, int flags)
33            {
34              return fnmatch (pattern, string, flags);
35            }
36          ],
37          [exit
38            (!((fnm ? fnm : fnmatch) ("a*", "", 0) == FNM_NOMATCH
39               && y ("a*", "abc", 0)
40               && n ("d*/*1", "d/s/1", FNM_PATHNAME)
41               && y ("a\\\\bc", "abc", 0)
42               && n ("a\\\\bc", "abc", FNM_NOESCAPE)
43               && y ("*x", ".x", 0)
44               && n ("*x", ".x", FNM_PERIOD)
45               && m4_if([$1], [GNU],
46                    [y ("xxXX", "xXxX", FNM_CASEFOLD)
47                     && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
48                     && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
49                     && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
50                     && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
51                     && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
52                    1)));])],
53       [$2=yes],
54       [$2=no],
55       [$2=cross])])
56 AS_IF([test $$2 = yes], [$3], [$4])
57 ])# _AC_FUNC_FNMATCH_IF
58
59
60 # _AC_LIBOBJ_FNMATCH
61 # ------------------
62 # Prepare the replacement of fnmatch.
63 AC_DEFUN([_AC_LIBOBJ_FNMATCH],
64 [AC_REQUIRE([AC_C_CONST])dnl
65 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
66 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
67 AC_CHECK_DECLS([getenv])
68 AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
69 AC_CHECK_HEADERS([wchar.h wctype.h])
70 AC_LIBOBJ([fnmatch])
71 FNMATCH_H=fnmatch.h
72 ])# _AC_LIBOBJ_FNMATCH
73
74
75 AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
76 [
77   FNMATCH_H=
78   _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
79                       [rm -f lib/fnmatch.h],
80                       [_AC_LIBOBJ_FNMATCH])
81   if test $ac_cv_func_fnmatch_posix != yes; then
82     dnl We must choose a different name for our function, since on ELF systems
83     dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
84     dnl compiled into a shared library.
85     AC_DEFINE([fnmatch], [posix_fnmatch],
86       [Define to a replacement function name for fnmatch().])
87   fi
88   AC_SUBST([FNMATCH_H])
89 ])
90
91
92 AC_DEFUN([gl_FUNC_FNMATCH_GNU],
93 [
94   dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
95   AC_REQUIRE([AC_GNU_SOURCE])
96
97   FNMATCH_H=
98   _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
99                       [rm -f lib/fnmatch.h],
100                       [_AC_LIBOBJ_FNMATCH])
101   if test $ac_cv_func_fnmatch_gnu != yes; then
102     dnl We must choose a different name for our function, since on ELF systems
103     dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
104     dnl compiled into a shared library.
105     AC_DEFINE([fnmatch], [gnu_fnmatch],
106       [Define to a replacement function name for fnmatch().])
107   fi
108   AC_SUBST([FNMATCH_H])
109 ])