* regex.m4 (gl_INCLUDED_REGEX): Remove; no longer used.
[gnulib.git] / m4 / regex.m4
1 #serial 26
2
3 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
4 # Software Foundation, Inc.
5 #
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 dnl Initially derived from code in GNU grep.
11 dnl Mostly written by Jim Meyering.
12
13 AC_DEFUN([gl_REGEX],
14 [
15   AC_LIBSOURCES(
16     [regcomp.c, regex.c, regex.h,
17      regex_internal.c, regex_internal.h, regexec.c])
18
19   dnl Even packages that don't use regex.c can use this macro.
20   dnl Of course, for them it doesn't do anything.
21
22   # Assume we'll default to using the included regex.c.
23   ac_use_included_regex=yes
24
25   # However, if the system regex support is good enough that it passes the
26   # the following run test, then default to *not* using the included regex.c.
27   # If cross compiling, assume the test would fail and use the included
28   # regex.c.  The first failing regular expression is from `Spencer ere
29   # test #75' in grep-2.3.
30   AC_CACHE_CHECK([for working re_compile_pattern],
31                  [gl_cv_func_working_re_compile_pattern],
32     [AC_RUN_IFELSE(
33        [AC_LANG_PROGRAM(
34           [AC_INCLUDES_DEFAULT
35            #include <regex.h>],
36           [[static struct re_pattern_buffer regex;
37             const char *s;
38             struct re_registers regs;
39             re_set_syntax (RE_SYNTAX_POSIX_EGREP);
40             memset (&regex, 0, sizeof (regex));
41             s = re_compile_pattern ("a[:@:>@:]b\n", 9, &regex);
42             /* This should fail with _Invalid character class name_ error.  */
43             if (!s)
44               exit (1);
45
46             /* This should succeed, but does not for e.g. glibc-2.1.3.  */
47             memset (&regex, 0, sizeof (regex));
48             s = re_compile_pattern ("{1", 2, &regex);
49
50             if (s)
51               exit (1);
52
53             /* The following example is derived from a problem report
54                against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
55             memset (&regex, 0, sizeof (regex));
56             s = re_compile_pattern ("[an\371]*n", 7, &regex);
57             if (s)
58               exit (1);
59
60             /* This should match, but does not for e.g. glibc-2.2.1.  */
61             if (re_match (&regex, "an", 2, 0, &regs) != 2)
62               exit (1);
63
64             memset (&regex, 0, sizeof (regex));
65             s = re_compile_pattern ("x", 1, &regex);
66             if (s)
67               exit (1);
68
69             /* The version of regex.c in e.g. GNU libc-2.2.93 did not
70                work with a negative RANGE argument.  */
71             if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
72               exit (1);
73
74             /* The version of regex.c in older versions of gnulib
75              * ignored RE_ICASE.  Detect that problem too. */
76             memset (&regex, 0, sizeof (regex));
77             re_set_syntax(RE_SYNTAX_EMACS|RE_ICASE);
78             s = re_compile_pattern ("x", 1, &regex);
79             if (s)
80               exit (1);
81
82             if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
83               exit (1);
84
85             /* REG_STARTEND was added to glibc on 2004-01-15.
86                Reject older versions.  */
87             if (! REG_STARTEND)
88               exit (1);
89
90             exit (0);]])],
91        [gl_cv_func_working_re_compile_pattern=yes],
92        [gl_cv_func_working_re_compile_pattern=no],
93        dnl When crosscompiling, assume it is broken.
94        [gl_cv_func_working_re_compile_pattern=no])])
95   if test $gl_cv_func_working_re_compile_pattern = yes; then
96     ac_use_included_regex=no
97   fi
98
99   AC_ARG_WITH([included-regex],
100     [  --without-included-regex don't compile regex; this is the default on
101                         systems with recent-enough versions of the GNU C
102                         Library (use with caution on other systems)],
103     [gl_with_regex=$withval],
104     [gl_with_regex=$ac_use_included_regex])
105   if test "X$gl_with_regex" = Xyes; then
106     AC_LIBOBJ([regex])
107     gl_PREREQ_REGEX
108   fi
109 ])
110
111 # Prerequisites of lib/regex.c and lib/regex_internal.c.
112 AC_DEFUN([gl_PREREQ_REGEX],
113 [
114   AC_REQUIRE([AC_GNU_SOURCE])
115   AC_REQUIRE([gl_C_RESTRICT])
116   AC_REQUIRE([AM_LANGINFO_CODESET])
117   AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
118   AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])
119 ])