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