1#serial 12 2 3dnl Initially derived from code in GNU grep. 4dnl Mostly written by Jim Meyering. 5 6dnl Usage: jm_INCLUDED_REGEX([lib/regex.c]) 7dnl 8AC_DEFUN([jm_INCLUDED_REGEX], 9 [ 10 dnl Even packages that don't use regex.c can use this macro. 11 dnl Of course, for them it doesn't do anything. 12 13 # Assume we'll default to using the included regex.c. 14 ac_use_included_regex=yes 15 16 # However, if the system regex support is good enough that it passes the 17 # the following run test, then default to *not* using the included regex.c. 18 # If cross compiling, assume the test would fail and use the included 19 # regex.c. The first failing regular expression is from `Spencer ere 20 # test #75' in grep-2.3. 21 AC_CACHE_CHECK([for working re_compile_pattern], 22 jm_cv_func_working_re_compile_pattern, 23 AC_TRY_RUN( 24[#include <stdio.h> 25#include <regex.h> 26 int 27 main () 28 { 29 static struct re_pattern_buffer regex; 30 const char *s; 31 struct re_registers regs; 32 re_set_syntax (RE_SYNTAX_POSIX_EGREP); 33 [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, ®ex);] 34 /* This should fail with _Invalid character class name_ error. */ 35 if (!s) 36 exit (1); 37 38 /* This should succeed, but doesn't for e.g. glibc-2.1.3. */ 39 s = re_compile_pattern ("{1", 2, ®ex); 40 41 if (s) 42 exit (1); 43 44 /* The following example is derived from a problem report 45 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ 46 s = re_compile_pattern ("[[an�]]*n", 7, ®ex); 47 if (s) 48 exit (1); 49 50 /* This should match, but doesn't for e.g. glibc-2.2.1. */ 51 if (re_match (®ex, "an", 2, 0, ®s) != 2) 52 exit (1); 53 54 exit (0); 55 } 56 ], 57 jm_cv_func_working_re_compile_pattern=yes, 58 jm_cv_func_working_re_compile_pattern=no, 59 dnl When crosscompiling, assume it's broken. 60 jm_cv_func_working_re_compile_pattern=no)) 61 if test $jm_cv_func_working_re_compile_pattern = yes; then 62 ac_use_included_regex=no 63 fi 64 65 test -n "$1" || AC_MSG_ERROR([missing argument]) 66 m4_syscmd([test -f $1]) 67 ifelse(m4_sysval, 0, 68 [ 69 AC_ARG_WITH(included-regex, 70 [ --without-included-regex don't compile regex; this is the default on 71 systems with version 2 of the GNU C library 72 (use with caution on other system)], 73 jm_with_regex=$withval, 74 jm_with_regex=$ac_use_included_regex) 75 if test "$jm_with_regex" = yes; then 76 AC_LIBOBJ(regex) 77 fi 78 ], 79 ) 80 ] 81) 82