xref: /netbsd-src/external/gpl2/xcvs/dist/m4/fnmatch.m4 (revision a7c918477dd5f12c1da816ba05caf44eab2d06d6)
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.
15AC_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         ],
31	 [exit
32	   (!(y ("a*", "abc", 0)
33	      && n ("d*/*1", "d/s/1", FNM_PATHNAME)
34	      && y ("a\\\\bc", "abc", 0)
35	      && n ("a\\\\bc", "abc", FNM_NOESCAPE)
36	      && y ("*x", ".x", 0)
37	      && n ("*x", ".x", FNM_PERIOD)
38	      && m4_if([$1], [GNU],
39		   [y ("xxXX", "xXxX", FNM_CASEFOLD)
40		    && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
41		    && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
42		    && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
43		    && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
44		    && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
45		   1)));])],
46      [$2=yes],
47      [$2=no],
48      [$2=cross])])
49AS_IF([test $$2 = yes], [$3], [$4])
50])# _AC_FUNC_FNMATCH_IF
51
52
53# _AC_LIBOBJ_FNMATCH
54# ------------------
55# Prepare the replacement of fnmatch.
56AC_DEFUN([_AC_LIBOBJ_FNMATCH],
57[AC_REQUIRE([AC_C_CONST])dnl
58AC_REQUIRE([AC_FUNC_ALLOCA])dnl
59AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
60AC_CHECK_DECLS([getenv])
61AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
62AC_CHECK_HEADERS([wchar.h wctype.h])
63AC_LIBOBJ([fnmatch])
64FNMATCH_H=fnmatch.h
65])# _AC_LIBOBJ_FNMATCH
66
67
68AC_DEFUN([gl_FUNC_FNMATCH_POSIX],
69[
70  FNMATCH_H=
71  _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix],
72                      [rm -f lib/fnmatch.h],
73                      [_AC_LIBOBJ_FNMATCH])
74  if test $ac_cv_func_fnmatch_posix != yes; then
75    dnl We must choose a different name for our function, since on ELF systems
76    dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
77    dnl compiled into a shared library.
78    AC_DEFINE([fnmatch], [posix_fnmatch],
79      [Define to a replacement function name for fnmatch().])
80  fi
81  AC_SUBST([FNMATCH_H])
82])
83
84
85AC_DEFUN([gl_FUNC_FNMATCH_GNU],
86[
87  dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc.
88  AC_REQUIRE([AC_GNU_SOURCE])
89
90  FNMATCH_H=
91  _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
92                      [rm -f lib/fnmatch.h],
93                      [_AC_LIBOBJ_FNMATCH])
94  if test $ac_cv_func_fnmatch_gnu != yes; then
95    dnl We must choose a different name for our function, since on ELF systems
96    dnl a broken fnmatch() in libc.so would override our fnmatch() if it is
97    dnl compiled into a shared library.
98    AC_DEFINE([fnmatch], [gnu_fnmatch],
99      [Define to a replacement function name for fnmatch().])
100  fi
101  AC_SUBST([FNMATCH_H])
102])
103