* config/srclist.txt: Add glibc bug 1237.
[gnulib.git] / m4 / regex.m4
1 #serial 27
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             /* Use the POSIX-compliant spelling with leading REG_,
40                rather than the traditional GNU spelling with leading RE_,
41                so that we reject older libc implementations.  */
42             re_set_syntax (REG_SYNTAX_POSIX_EGREP);
43             memset (&regex, 0, sizeof (regex));
44             s = re_compile_pattern ("a[:@:>@:]b\n", 9, &regex);
45             /* This should fail with _Invalid character class name_ error.  */
46             if (!s)
47               exit (1);
48
49             /* This should succeed, but does not for e.g. glibc-2.1.3.  */
50             memset (&regex, 0, sizeof (regex));
51             s = re_compile_pattern ("{1", 2, &regex);
52
53             if (s)
54               exit (1);
55
56             /* The following example is derived from a problem report
57                against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
58             memset (&regex, 0, sizeof (regex));
59             s = re_compile_pattern ("[an\371]*n", 7, &regex);
60             if (s)
61               exit (1);
62
63             /* This should match, but does not for e.g. glibc-2.2.1.  */
64             if (re_match (&regex, "an", 2, 0, &regs) != 2)
65               exit (1);
66
67             memset (&regex, 0, sizeof (regex));
68             s = re_compile_pattern ("x", 1, &regex);
69             if (s)
70               exit (1);
71
72             /* The version of regex.c in e.g. GNU libc-2.2.93 did not
73                work with a negative RANGE argument.  */
74             if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
75               exit (1);
76
77             /* The version of regex.c in older versions of gnulib
78                ignored REG_IGNORE_CASE (which was then called RE_ICASE).
79                Detect that problem too.  */
80             memset (&regex, 0, sizeof (regex));
81             re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE);
82             s = re_compile_pattern ("x", 1, &regex);
83             if (s)
84               exit (1);
85
86             if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
87               exit (1);
88
89             /* REG_STARTEND was added to glibc on 2004-01-15.
90                Reject older versions.  */
91             if (! REG_STARTEND)
92               exit (1);
93
94             exit (0);]])],
95        [gl_cv_func_working_re_compile_pattern=yes],
96        [gl_cv_func_working_re_compile_pattern=no],
97        dnl When crosscompiling, assume it is broken.
98        [gl_cv_func_working_re_compile_pattern=no])])
99   if test $gl_cv_func_working_re_compile_pattern = yes; then
100     ac_use_included_regex=no
101   fi
102
103   AC_ARG_WITH([included-regex],
104     [  --without-included-regex don't compile regex; this is the default on
105                         systems with recent-enough versions of the GNU C
106                         Library (use with caution on other systems)],
107     [gl_with_regex=$withval],
108     [gl_with_regex=$ac_use_included_regex])
109   if test "X$gl_with_regex" = Xyes; then
110     AC_LIBOBJ([regex])
111     gl_PREREQ_REGEX
112   fi
113 ])
114
115 # Prerequisites of lib/regex.c and lib/regex_internal.c.
116 AC_DEFUN([gl_PREREQ_REGEX],
117 [
118   AC_REQUIRE([AC_GNU_SOURCE])
119   AC_REQUIRE([gl_C_RESTRICT])
120   AC_REQUIRE([AM_LANGINFO_CODESET])
121   AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
122   AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])
123 ])