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