diff --git a/configure.ac b/configure.ac
index 8d3c2f13..09027f4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,20 +56,48 @@ dnl gnulib will handle getopt and error functions
dnl Check pcre2 availability
AC_MSG_CHECKING([whether PCRE2 support is requested])
AC_ARG_WITH([pcre2],
- [AS_HELP_STRING([--with-pcre2],
- [use pcre2 regex library @<:@default=check@:>@])],
+ [AS_HELP_STRING([--with-pcre2@<:@=PATH@:>@],
+ [use pcre2 regex library, optionally from PATH @<:@default=check@:>@])],
[], [with_pcre2=check])
LIBPCRE2=
AS_IF([test "x$with_pcre2" != xno],
[
AC_MSG_RESULT($with_pcre2)
+ dnl Handle custom path for PCRE2
+ AS_IF([test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck],
+ [
+ dnl Custom path specified
+ PCRE2_CPPFLAGS="-I$with_pcre2/include"
+ PCRE2_LDFLAGS="-L$with_pcre2/lib"
+ save_CPPFLAGS="$CPPFLAGS"
+ save_LDFLAGS="$LDFLAGS"
+ CPPFLAGS="$CPPFLAGS $PCRE2_CPPFLAGS"
+ LDFLAGS="$LDFLAGS $PCRE2_LDFLAGS"
+ ])
AC_CHECK_HEADERS([pcre2posix.h], [], [LIBPCRE2=_missing_header])
AC_CHECK_LIB([pcre2-posix${LIBPCRE2}], [regexec],
- [],
- [if test "x$with_pcre2" != xcheck; then
- AC_MSG_FAILURE(
- [--with-pcre2 was given, but test for pcre2-posix failed])
- fi]
+ [
+ dnl Success - add the flags permanently if custom path was used
+ AS_IF([test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck],
+ [
+ CPPFLAGS="$save_CPPFLAGS $PCRE2_CPPFLAGS"
+ LDFLAGS="$save_LDFLAGS $PCRE2_LDFLAGS"
+ ])
+ dnl Add the library to LIBS
+ LIBS="$LIBS -lpcre2-posix${LIBPCRE2}"
+ ],
+ [
+ dnl Failure - restore original flags if custom path was used
+ AS_IF([test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck],
+ [
+ CPPFLAGS="$save_CPPFLAGS"
+ LDFLAGS="$save_LDFLAGS"
+ ])
+ if test "x$with_pcre2" != xcheck; then
+ AC_MSG_FAILURE(
+ [--with-pcre2 was given, but test for pcre2-posix failed])
+ fi
+ ]
)
],
AC_MSG_RESULT(no)
diff --git a/doc/patchutils.xml b/doc/patchutils.xml
index 9af56e41..6a47e59d 100644
--- a/doc/patchutils.xml
+++ b/doc/patchutils.xml
@@ -2266,7 +2266,10 @@ will pipe patch of file #2 to vim - -R
The regular expression is treated as POSIX Basic Regular
Expression syntax, unless the option is
given in which case POSIX Extended Regular Expression syntax
- is used.
+ is used. When compiled with PCRE2 support, PCRE regular expressions
+ are used instead of POSIX regular expressions, and the
+ option has no effect since PCRE already supports extended regular
+ expression features by default.
For example, to see the patches in
my.patch which contain the regular
@@ -2497,7 +2500,9 @@ will pipe patch of file #2 to vim - -R
Use POSIX Extended Regular Expression
- syntax.
+ syntax. Note: when compiled with PCRE2 support, this option
+ has no effect as PCRE regular expressions are used by default
+ and already support extended regular expression features.
diff --git a/lib/Makefile b/lib/Makefile
index deda49d0..910f638b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -966,7 +966,7 @@ LIBGNU_LIBDEPS =
LIBGNU_LTLIBDEPS =
LIBINTL =
LIBOBJS =
-LIBS = -lpcre2-posix
+LIBS = -lpcre2-posix
LIMITS_H = limits.h
LN_S = ln -s
LOCALENAME_ENHANCE_LOCALE_FUNCS = 0
diff --git a/src/filterdiff.c b/src/filterdiff.c
index 3ac66ca5..ddb4472d 100644
--- a/src/filterdiff.c
+++ b/src/filterdiff.c
@@ -1257,7 +1257,11 @@ const char * syntax_str =
" -v, --verbose\n"
" verbose output -- use more than once for extra verbosity\n"
" -E, --extended-regexp (grepdiff)\n"
+#ifdef HAVE_PCRE2POSIX_H
+" this option has no effect as PCRE regexes are used by default (grepdiff)\n"
+#else
" use extended regexps, like egrep (grepdiff)\n"
+#endif
" -E, --empty-files-as-absent (lsdiff)\n"
" treat empty files as absent (lsdiff)\n"
" -f FILE, --file=FILE (grepdiff)\n"
diff --git a/tests/grepdiff-pcre2-extended/run-test b/tests/grepdiff-pcre2-extended/run-test
new file mode 100755
index 00000000..594e8ec5
--- /dev/null
+++ b/tests/grepdiff-pcre2-extended/run-test
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Test for PCRE2 extended regexp functionality (GitHub issue #60)
+
+. ${top_srcdir-.}/tests/common.sh
+
+# Create a simple test diff with both patterns
+cat << EOF > diff
+--- file1
++++ file1
+@@ -1,2 +1,3 @@
+ context
+-old
++landblockelim
++blockall
+EOF
+
+# Test extended regexp pattern with -E flag
+${GREPDIFF} -E 'landblockelim|blockall' diff 2>errors >output || exit 1
+
+[ -s errors ] && exit 1
+
+# Verify both patterns are found
+if ! grep -q "file1" output; then
+ echo "ERROR: Extended regexp pattern failed to match"
+ exit 1
+fi