diff configure.ac @ 31424:d1165473e4b0

allow Octave to use PCRE2 (bug #61542) * acinclude.m4 (OCTAVE_CHECK_LIB_PCRE2_OK): New macro. * configure.ac: Check for libpcre2-8 and pcre2.h before checking for libpcre and pcre.h. If PCRE2 is found, also define PCRE_CPPFLAGS, PCRE_LDFLAGS, and PCRE_LIBS. Error if neither library is found. * lo-regexp.h (regexp::match_element::match_element): New constructor that accepts int values for start and end. * lo-regexp.cc: Include either PCRE2 or PCRE headers. Fail if neither HAVE_PCRE2 or HAVE_PCRE is defined. (octave_pcre_code, OCTAVE_PCRE_SIZE): New typedefs. (OCTAVE_PCRE_CASELESS, OCTAVE_PCRE_DOTALL, OCTAVE_PCRE_MULTILINE, OCTAVE_PCRE_EXTENDED, OCTAVE_PCRE_UTF, OCTAVE_PCRE_INFO_CAPTURECOUNT, OCTAVE_PCRE_INFO_NAMECOUNT, OCTAVE_PCRE_INFO_NAMEENTRYSIZE, OCTAVE_PCRE_INFO_NAMETABLE): New macro definitions. (octave_pcre_code_free): Define function pointer that references either pcre2_code_free or pcre_free depending on the library in use. (regexp::free): Call octave_pcre_code_free to free m_code. (octave_pcre_pattern_info): New function. (regexp::compile_internal): Allow use of either PCRE2 or PCRE. Use new macros and functions to hide differences in library interfaces.
author Rafael Laboissiere <rafael@laboissiere.net>
date Sun, 13 Nov 2022 10:17:17 -0500
parents 00e2eafd1c0f
children f990f14d4b0c
line wrap: on
line diff
--- a/configure.ac	Fri Nov 11 15:40:45 2022 -0500
+++ b/configure.ac	Sun Nov 13 10:17:17 2022 -0500
@@ -1375,14 +1375,42 @@
     [Define to 1 to build experimental Virtual Machine evaluator.])
 fi
 
-### Check for PCRE regex library.
-
-OCTAVE_CHECK_LIB(pcre, PCRE,
-  [], [pcre.h pcre/pcre.h], [pcre_compile], [], [],
-  [OCTAVE_CHECK_LIB_PCRE_OK([],
-    [AC_MSG_ERROR([PCRE library must be built with UTF support (--enable-utf)])])
-  ],
-  [libpcre], [REQUIRED])
+### Check for PCRE2 or PCRE regex library, requiring one to exist.
+
+have_pcre2=no
+have_pcre=no
+save_CPPLAGS="$CPPFLAGS"
+CPPFLAGS="-DPCRE2_CODE_UNIT_WIDTH=8 $CPPFLAGS"
+OCTAVE_CHECK_LIB(pcre2, PCRE2,
+  [], [pcre2.h pcre2/pcre2.h], [pcre2_compile_8], [], [],
+  [OCTAVE_CHECK_LIB_PCRE2_OK([have_pcre2=yes],
+    [AC_MSG_ERROR([PCRE2 library must be built with UTF support (--enable-utf)])])],
+  [libpcre2-8])
+CPPFLAGS="$save_CPPFLAGS"
+
+if test $have_pcre2 = no; then
+  OCTAVE_CHECK_LIB(pcre, PCRE,
+    [], [pcre.h pcre/pcre.h], [pcre_compile], [], [],
+    [OCTAVE_CHECK_LIB_PCRE_OK([have_pcre=yes],
+      [AC_MSG_ERROR([PCRE library must be built with UTF support (--enable-utf)])])],
+    [libpcre])
+fi
+
+if test $have_pcre2 = yes; then
+  AC_DEFINE(HAVE_PCRE2, 1, [Define to 1 if PCRE2 is available.])
+
+  ## Only one of PCRE2 or PCRE is used, so avoid having to define and use
+  ## both PCRE2_* and PCRE_* variables everywhere.
+
+  PCRE_CPPFLAGS="$PCRE2_CPPFLAGS"
+  PCRE_LDFLAGS="$PCRE2_LDFLAGS"
+  PCRE_LIBS="$PCRE2_LIBS"
+
+elif test $have_pcre = yes; then
+  AC_DEFINE(HAVE_PCRE, 1, [Define to 1 if PCRE is available.])
+else
+  AC_MSG_ERROR([to build Octave, you must have the PCRE or PCRE2 library and header files installed])
+fi
 
 ### Check for Qhull library.