]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add support for PCRE2 (#2031)
authorMostyn Bramley-Moore <mostyn@antipode.se>
Sat, 9 Dec 2023 22:56:53 +0000 (23:56 +0100)
committerGitHub <noreply@github.com>
Sat, 9 Dec 2023 22:56:53 +0000 (23:56 +0100)
The original PCRE is now end-of-life, and no longer actively maintained.

Implements #2013.

CMakeLists.txt
build/cmake/FindPCRE2POSIX.cmake [new file with mode: 0644]
build/cmake/config.h.in
configure.ac
contrib/android/config/windows_host.h
tar/bsdtar.c
tar/subst.c

index 9cd8ac0f382630f1d751fe5ac9150ef5ea9ddce1..c982af9ac0a24cd804c8669d91037c58c4890b62 100644 (file)
@@ -217,6 +217,7 @@ OPTION(ENABLE_BZip2 "Enable the use of the system BZip2 library if found" ON)
 OPTION(ENABLE_LIBXML2 "Enable the use of the system libxml2 library if found" ON)
 OPTION(ENABLE_EXPAT "Enable the use of the system EXPAT library if found" ON)
 OPTION(ENABLE_PCREPOSIX "Enable the use of the system PCREPOSIX library if found" ON)
+OPTION(ENABLE_PCRE2POSIX "Enable the use of the system PCRE2POSIX library if found" ON)
 OPTION(ENABLE_LIBGCC "Enable the use of the system LibGCC library if found" ON)
 # CNG is used for encrypt/decrypt Zip archives on Windows.
 OPTION(ENABLE_CNG "Enable the use of CNG(Crypto Next Generation)" ON)
@@ -1349,6 +1350,68 @@ IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$"
   MARK_AS_ADVANCED(CLEAR LIBGCC_LIBRARIES)
 ENDIF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$")
 
+IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCRE2POSIX)$")
+  #
+  # If requested, try finding library for PCRE2POSIX
+  #
+  IF(ENABLE_LIBGCC)
+    FIND_PACKAGE(LIBGCC)
+  ELSE()
+    MESSAGE(FATAL_ERROR "libgcc not found.")
+    SET(LIBGCC_FOUND FALSE) # Override cached value
+  ENDIF()
+  IF(ENABLE_PCRE2POSIX)
+    FIND_PACKAGE(PCRE2POSIX)
+  ELSE()
+    SET(PCRE2POSIX_FOUND FALSE) # Override cached value
+  ENDIF()
+  IF(PCRE2POSIX_FOUND)
+    INCLUDE_DIRECTORIES(${PCRE2_INCLUDE_DIR})
+    LIST(APPEND ADDITIONAL_LIBS ${PCRE2POSIX_LIBRARIES})
+    # Test if a macro is needed for the library.
+    TRY_MACRO_FOR_LIBRARY(
+      "${PCRE2_INCLUDE_DIR}" "${PCRE2POSIX_LIBRARIES}"
+      COMPILES
+      "#include <pcre2posix.h>\nint main() {regex_t r;return pcre2_regcomp(&r, \"\", 0);}"
+      "WITHOUT_PCRE2_STATIC;PCRE2_STATIC")
+    IF(NOT WITHOUT_PCRE2_STATIC AND PCRE2_STATIC)
+      ADD_DEFINITIONS(-DPCRE2_STATIC)
+       ELSEIF(NOT WITHOUT_PCRE2_STATIC AND NOT PCRE2_STATIC AND PCRE2_FOUND)
+         # Determine if pcre2 static libraries are to be used.
+      LIST(APPEND ADDITIONAL_LIBS ${PCRE2_LIBRARIES})
+      SET(TMP_LIBRARIES ${PCRE2POSIX_LIBRARIES} ${PCRE2_LIBRARIES})
+      MESSAGE(STATUS "trying again with -lpcre2-8 included")
+      TRY_MACRO_FOR_LIBRARY(
+        "${PCRE2_INCLUDE_DIR}" "${TMP_LIBRARIES}"
+        COMPILES
+        "#include <pcre2posix.h>\nint main() {regex_t r;return pcre2_regcomp(&r, \"\", 0);}"
+        "WITHOUT_PCRE2_STATIC;PCRE2_STATIC")
+      IF(NOT WITHOUT_PCRE2_STATIC AND PCRE2_STATIC)
+        ADD_DEFINITIONS(-DPCRE2_STATIC)
+      ELSEIF(NOT WITHOUT_PCRE2_STATIC AND NOT PCRE2_STATIC AND MSVC AND LIBGCC_FOUND)
+        # When doing a Visual Studio build using pcre2 static libraries
+        # built using the mingw toolchain, -lgcc is needed to resolve
+        # ___chkstk_ms.
+        MESSAGE(STATUS "Visual Studio build detected, trying again with -lgcc included")
+        LIST(APPEND ADDITIONAL_LIBS ${LIBGCC_LIBRARIES})
+        SET(TMP_LIBRARIES ${PCRE2POSIX_LIBRARIES} ${PCRE2_LIBRARIES} ${LIBGCC_LIBRARIES})
+          TRY_MACRO_FOR_LIBRARY(
+            "${PCRE2_INCLUDE_DIR}" "${TMP_LIBRARIES}"
+            COMPILES
+            "#include <pcre2posix.h>\nint main() {regex_t r;return pcre2_regcomp(&r, \"\", 0);}"
+            "WITHOUT_PCRE2_STATIC;PCRE2_STATIC")
+          IF(NOT WITHOUT_PCRE2_STATIC AND PCRE2_STATIC)
+            ADD_DEFINITIONS(-DPCRE2_STATIC)
+          ENDIF(NOT WITHOUT_PCRE2_STATIC AND PCRE2_STATIC)
+      ENDIF(NOT WITHOUT_PCRE2_STATIC AND PCRE2_STATIC)
+    ENDIF(NOT WITHOUT_PCRE2_STATIC AND PCRE2_STATIC)
+  ENDIF(PCRE2POSIX_FOUND)
+  MARK_AS_ADVANCED(CLEAR PCRE2_INCLUDE_DIR)
+  MARK_AS_ADVANCED(CLEAR PCRE2POSIX_LIBRARIES)
+  MARK_AS_ADVANCED(CLEAR PCRE2_LIBRARIES)
+  MARK_AS_ADVANCED(CLEAR LIBGCC_LIBRARIES)
+ENDIF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCRE2POSIX)$")
+
 #
 # Check functions
 #
diff --git a/build/cmake/FindPCRE2POSIX.cmake b/build/cmake/FindPCRE2POSIX.cmake
new file mode 100644 (file)
index 0000000..4104f37
--- /dev/null
@@ -0,0 +1,34 @@
+# - Find pcre2posix\r
+# Find the native PCRE2-8 and PCRE2-POSIX include and libraries\r
+#\r
+#  PCRE2_INCLUDE_DIR    - where to find pcre2posix.h, etc.\r
+#  PCRE2POSIX_LIBRARIES - List of libraries when using libpcre2-posix.\r
+#  PCRE2_LIBRARIES      - List of libraries when using libpcre2-8.\r
+#  PCRE2POSIX_FOUND     - True if libpcre2-posix found.\r
+#  PCRE2_FOUND          - True if libpcre2-8 found.\r
+\r
+IF (PCRE2_INCLUDE_DIR)\r
+  # Already in cache, be silent\r
+  SET(PCRE2_FIND_QUIETLY TRUE)\r
+ENDIF (PCRE2_INCLUDE_DIR)\r
+\r
+FIND_PATH(PCRE2_INCLUDE_DIR pcre2posix.h)\r
+FIND_LIBRARY(PCRE2POSIX_LIBRARY NAMES pcre2-posix libpcre2-posix pcre2-posix-static)\r
+FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8 libpcre2-8 pcre2-8-static)\r
+\r
+# handle the QUIETLY and REQUIRED arguments and set PCRE2POSIX_FOUND to TRUE if \r
+# all listed variables are TRUE\r
+INCLUDE(FindPackageHandleStandardArgs)\r
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2POSIX DEFAULT_MSG PCRE2POSIX_LIBRARY PCRE2_INCLUDE_DIR)\r
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY)\r
+\r
+IF(PCRE2POSIX_FOUND)\r
+  SET(PCRE2POSIX_LIBRARIES ${PCRE2POSIX_LIBRARY})\r
+  SET(HAVE_LIBPCRE2POSIX 1)\r
+  SET(HAVE_PCRE2POSIX_H 1)\r
+ENDIF(PCRE2POSIX_FOUND)\r
+\r
+IF(PCRE2_FOUND)\r
+  SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})\r
+  SET(HAVE_LIBPCRE2 1)\r
+ENDIF(PCRE2_FOUND)\r
index 71d54a4cec71c12a6208aacca8e7f6949367eb66..716657e3fff3c2f8f8628d94978e7b566565ac05 100644 (file)
@@ -753,6 +753,12 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `pcreposix' library (-lpcreposix). */
 #cmakedefine HAVE_LIBPCREPOSIX 1
 
+/* Define to 1 if you have the `pcre2-8' library (-lpcre2-8). */
+#cmakedefine HAVE_LIBPCRE2 1
+
+/* Define to 1 if you have the `pcreposix' library (-lpcre2posix). */
+#cmakedefine HAVE_LIBPCRE2POSIX 1
+
 /* Define to 1 if you have the `xml2' library (-lxml2). */
 #cmakedefine HAVE_LIBXML2 1
 
@@ -926,6 +932,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <pcreposix.h> header file. */
 #cmakedefine HAVE_PCREPOSIX_H 1
 
+/* Define to 1 if you have the <pcre2posix.h> header file. */
+#cmakedefine HAVE_PCRE2POSIX_H 1
+
 /* Define to 1 if you have the `pipe' function. */
 #cmakedefine HAVE_PIPE 1
 
index 3f063c1520d3f99aa1e17ba1755dd8258731d411..93f7af94afaad68c9a404d810da176341f9b2aa6 100644 (file)
@@ -552,6 +552,7 @@ AC_ARG_ENABLE([posix-regex-lib],
   AS_HELP_STRING([--enable-posix-regex-lib=libc], [use libc POSIX regular expression support])
   AS_HELP_STRING([--enable-posix-regex-lib=libregex], [use libregex POSIX regular expression support])
   AS_HELP_STRING([--enable-posix-regex-lib=libpcreposix], [use libpcreposix POSIX regular expression support])
+  AS_HELP_STRING([--enable-posix-regex-lib=libpcre2posix], [use libpcre2-posix POSIX regular expression support])
   AS_HELP_STRING([--disable-posix-regex-lib], [don't enable POSIX regular expression support])],
   [], [enable_posix_regex_lib=auto])
 
@@ -603,6 +604,39 @@ if test -z $posix_regex_lib_found && (test "$enable_posix_regex_lib" = "auto" ||
     posix_regex_lib_found=1
   fi
 fi
+if test -z $posix_regex_lib_found && (test "$enable_posix_regex_lib" = "auto" || test "$enable_posix_regex_lib" = "libpcre2posix"); then
+  AC_CHECK_HEADERS([pcre2posix.h])
+  AC_CHECK_LIB(pcre2-posix,regcomp)
+  if test "x$ac_cv_lib_pcre2posix_regcomp" != xyes; then
+    AC_MSG_NOTICE(trying libpcre2posix check again with libpcre2-8)
+       unset ac_cv_lib_pcre2posix_regcomp
+       AC_CHECK_LIB(pcre2,pcre2_regexec)
+    AC_CHECK_LIB(pcre2-posix,pcre2_regcomp)
+    if test "x$ac_cv_lib_pcre2_pcre_exec" = xyes && test "x$ac_cv_lib_pcre2posix_regcomp" = xyes; then
+      AC_MSG_CHECKING(if PCRE2_STATIC needs to be defined)
+      AC_LINK_IFELSE(
+        [AC_LANG_SOURCE(#include <pcre2posix.h>
+          int main() { return pcre2_regcomp(NULL, NULL, 0); })],
+        [without_pcre2_static=yes],
+        [without_pcre2_static=no])
+      AC_LINK_IFELSE(
+        [AC_LANG_SOURCE(#define PCRE2_STATIC
+          #include <pcre2posix.h>
+          int main() { return pcre2_regcomp(NULL, NULL, 0); })],
+        [with_pcre2_static=yes],
+        [with_pcre2_static=no])
+      if test "x$without_pcre2_static" != xyes && test "x$with_pcre2_static" = xyes; then
+        AC_MSG_RESULT(yes)
+        AC_DEFINE([PCRE2_STATIC], [1], [Define to 1 if PCRE2_STATIC needs to be defined.])
+      elif test "x$without_pcre2_static" = xyes || test "x$with_pcre2_static" = xyes; then
+        AC_MSG_RESULT(no)
+      fi
+      posix_regex_lib_found=1
+    fi
+  else
+    posix_regex_lib_found=1
+  fi
+fi
 
 # TODO: Give the user the option of using a pre-existing system
 # libarchive.  This will define HAVE_LIBARCHIVE which will cause
index 6550e5e82e2a0ffe4519e210aaf16288cee8ddff..5210a4db5c7fd0081e3acc16e9b01a67ff1fc710 100644 (file)
 /* Define to 1 if you have the `pcreposix' library (-lpcreposix). */
 /* #undef HAVE_LIBPCREPOSIX */
 
+/* Define to 1 if you have the `pcre2-8' library (-lpcre2-8). */
+/* #undef HAVE_LIBPCRE2 */
+
+/* Define to 1 if you have the `pcre2-posix' library (-lpcre2-posix). */
+/* #undef HAVE_LIBPCRE2POSIX */
+
 /* Define to 1 if you have the `regex' library (-lregex). */
 /* #undef HAVE_LIBREGEX */
 
 /* Define to 1 if you have the <pcreposix.h> header file. */
 /* #undef HAVE_PCREPOSIX_H */
 
+/* Define to 1 if you have the <pcre2posix.h> header file. */
+/* #undef HAVE_PCRE2POSIX_H */
+
 /* Define to 1 if you have the `pipe' function. */
 /* #undef HAVE_PIPE */
 
index d50ebd20bd1c71a32fd222293b8f23ad3c92504a..2834a6063266189f93774a33ba072a23452e7e7f 100644 (file)
@@ -668,7 +668,7 @@ main(int argc, char **argv)
                        bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE;
                        break;
                case 's': /* NetBSD pax-as-tar */
-#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H)
                        add_substitution(bsdtar, bsdtar->argument);
 #else
                        lafe_warnc(0,
@@ -947,7 +947,7 @@ main(int argc, char **argv)
        }
 
        archive_match_free(bsdtar->matching);
-#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H)
        cleanup_substitution(bsdtar);
 #endif
        cset_free(bsdtar->cset);
index 6152f8672d9d3bdcca9f811e262cfa816b5eeebc..659c0b88f9b11796077c40fff66c117d3321fd34 100644 (file)
 
 #include "bsdtar_platform.h"
 
-#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H)
 #include "bsdtar.h"
 
 #include <errno.h>
-#ifdef HAVE_PCREPOSIX_H
+#if defined(HAVE_PCREPOSIX_H)
 #include <pcreposix.h>
+#elif defined(HAVE_PCRE2POSIX_H)
+#include <pcre2posix.h>
 #else
 #include <regex.h>
 #endif
@@ -325,4 +327,4 @@ cleanup_substitution(struct bsdtar *bsdtar)
        }
        free(subst);
 }
-#endif /* defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) */
+#endif /* defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H) */