1# Check for fnmatch. 2 3# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software 4# Foundation, Inc. 5# This file is free software; the Free Software Foundation 6# gives unlimited permission to copy and/or distribute it, 7# with or without modifications, as long as this notice is preserved. 8 9# Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent. 10# New applications should use the macros below instead. 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. 16AC_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 [[#include <fnmatch.h> 27 static int 28 y (char const *pattern, char const *string, int flags) 29 { 30 return fnmatch (pattern, string, flags) == 0; 31 } 32 static int 33 n (char const *pattern, char const *string, int flags) 34 { 35 return fnmatch (pattern, string, flags) == FNM_NOMATCH; 36 } 37 ]], 38 [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]"; 39 char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]"; 40 static char const A_1[] = { 'A' - 1, 0 }; 41 static char const A01[] = { 'A' + 1, 0 }; 42 static char const a_1[] = { 'a' - 1, 0 }; 43 static char const a01[] = { 'a' + 1, 0 }; 44 static char const bs_1[] = { '\\\\' - 1, 0 }; 45 static char const bs01[] = { '\\\\' + 1, 0 }; 46 return 47 !(n ("a*", "", 0) 48 && y ("a*", "abc", 0) 49 && n ("d*/*1", "d/s/1", FNM_PATHNAME) 50 && y ("a\\\\bc", "abc", 0) 51 && n ("a\\\\bc", "abc", FNM_NOESCAPE) 52 && y ("*x", ".x", 0) 53 && n ("*x", ".x", FNM_PERIOD) 54 && y (Apat, "\\\\", 0) && y (Apat, "A", 0) 55 && y (apat, "\\\\", 0) && y (apat, "a", 0) 56 && n (Apat, A_1, 0) == ('A' < '\\\\') 57 && n (apat, a_1, 0) == ('a' < '\\\\') 58 && y (Apat, A01, 0) == ('A' < '\\\\') 59 && y (apat, a01, 0) == ('a' < '\\\\') 60 && y (Apat, bs_1, 0) == ('A' < '\\\\') 61 && y (apat, bs_1, 0) == ('a' < '\\\\') 62 && n (Apat, bs01, 0) == ('A' < '\\\\') 63 && n (apat, bs01, 0) == ('a' < '\\\\') 64 && ]m4_if([$1], [GNU], 65 [y ("xxXX", "xXxX", FNM_CASEFOLD) 66 && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH) 67 && n ("d*/*1", "d/s/1", FNM_FILE_NAME) 68 && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR) 69 && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR) 70 && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)], 71 1))[;]])], 72 [$2=yes], 73 [$2=no], 74 [$2=cross])]) 75AS_IF([test $$2 = yes], [$3], [$4]) 76])# _AC_FUNC_FNMATCH_IF 77 78 79# _AC_LIBOBJ_FNMATCH 80# ------------------ 81# Prepare the replacement of fnmatch. 82AC_DEFUN([_AC_LIBOBJ_FNMATCH], 83[AC_REQUIRE([AC_FUNC_ALLOCA])dnl 84AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl 85AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>]) 86AC_CHECK_FUNCS_ONCE([btowc iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy]) 87AC_CHECK_HEADERS_ONCE([wctype.h]) 88AC_LIBOBJ([fnmatch]) 89FNMATCH_H=fnmatch.h 90])# _AC_LIBOBJ_FNMATCH 91 92 93AC_DEFUN([gl_FUNC_FNMATCH_POSIX], 94[ 95 FNMATCH_H= 96 _AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_posix], 97 [rm -f lib/fnmatch.h], 98 [_AC_LIBOBJ_FNMATCH]) 99 if test $ac_cv_func_fnmatch_posix != yes; then 100 dnl We must choose a different name for our function, since on ELF systems 101 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is 102 dnl compiled into a shared library. 103 AC_DEFINE([fnmatch], [posix_fnmatch], 104 [Define to a replacement function name for fnmatch().]) 105 fi 106 AC_SUBST([FNMATCH_H]) 107]) 108 109 110AC_DEFUN([gl_FUNC_FNMATCH_GNU], 111[ 112 dnl Persuade glibc <fnmatch.h> to declare FNM_CASEFOLD etc. 113 AC_REQUIRE([AC_GNU_SOURCE]) 114 115 FNMATCH_H= 116 _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu], 117 [rm -f lib/fnmatch.h], 118 [_AC_LIBOBJ_FNMATCH]) 119 if test $ac_cv_func_fnmatch_gnu != yes; then 120 dnl We must choose a different name for our function, since on ELF systems 121 dnl a broken fnmatch() in libc.so would override our fnmatch() if it is 122 dnl compiled into a shared library. 123 AC_DEFINE([fnmatch], [gnu_fnmatch], 124 [Define to a replacement function name for fnmatch().]) 125 fi 126 AC_SUBST([FNMATCH_H]) 127]) 128