From: Mostyn Bramley-Moore Date: Sat, 9 Dec 2023 22:56:53 +0000 (+0100) Subject: Add support for PCRE2 (#2031) X-Git-Tag: v3.7.3~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1231a7ea7df4db6ddba73f06df67dbab0174a5c;p=thirdparty%2Flibarchive.git Add support for PCRE2 (#2031) The original PCRE is now end-of-life, and no longer actively maintained. Implements #2013. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cd8ac0f3..c982af9ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 \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 \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 \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 index 000000000..4104f3791 --- /dev/null +++ b/build/cmake/FindPCRE2POSIX.cmake @@ -0,0 +1,34 @@ +# - Find pcre2posix +# Find the native PCRE2-8 and PCRE2-POSIX include and libraries +# +# PCRE2_INCLUDE_DIR - where to find pcre2posix.h, etc. +# PCRE2POSIX_LIBRARIES - List of libraries when using libpcre2-posix. +# PCRE2_LIBRARIES - List of libraries when using libpcre2-8. +# PCRE2POSIX_FOUND - True if libpcre2-posix found. +# PCRE2_FOUND - True if libpcre2-8 found. + +IF (PCRE2_INCLUDE_DIR) + # Already in cache, be silent + SET(PCRE2_FIND_QUIETLY TRUE) +ENDIF (PCRE2_INCLUDE_DIR) + +FIND_PATH(PCRE2_INCLUDE_DIR pcre2posix.h) +FIND_LIBRARY(PCRE2POSIX_LIBRARY NAMES pcre2-posix libpcre2-posix pcre2-posix-static) +FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8 libpcre2-8 pcre2-8-static) + +# handle the QUIETLY and REQUIRED arguments and set PCRE2POSIX_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2POSIX DEFAULT_MSG PCRE2POSIX_LIBRARY PCRE2_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY) + +IF(PCRE2POSIX_FOUND) + SET(PCRE2POSIX_LIBRARIES ${PCRE2POSIX_LIBRARY}) + SET(HAVE_LIBPCRE2POSIX 1) + SET(HAVE_PCRE2POSIX_H 1) +ENDIF(PCRE2POSIX_FOUND) + +IF(PCRE2_FOUND) + SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) + SET(HAVE_LIBPCRE2 1) +ENDIF(PCRE2_FOUND) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 71d54a4ce..716657e3f 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -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 header file. */ #cmakedefine HAVE_PCREPOSIX_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PCRE2POSIX_H 1 + /* Define to 1 if you have the `pipe' function. */ #cmakedefine HAVE_PIPE 1 diff --git a/configure.ac b/configure.ac index 3f063c152..93f7af94a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 + 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 + 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 diff --git a/contrib/android/config/windows_host.h b/contrib/android/config/windows_host.h index 6550e5e82..5210a4db5 100644 --- a/contrib/android/config/windows_host.h +++ b/contrib/android/config/windows_host.h @@ -442,6 +442,12 @@ /* 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 */ @@ -593,6 +599,9 @@ /* Define to 1 if you have the header file. */ /* #undef HAVE_PCREPOSIX_H */ +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PCRE2POSIX_H */ + /* Define to 1 if you have the `pipe' function. */ /* #undef HAVE_PIPE */ diff --git a/tar/bsdtar.c b/tar/bsdtar.c index d50ebd20b..2834a6063 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -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); diff --git a/tar/subst.c b/tar/subst.c index 6152f8672..659c0b88f 100644 --- a/tar/subst.c +++ b/tar/subst.c @@ -25,12 +25,14 @@ #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 -#ifdef HAVE_PCREPOSIX_H +#if defined(HAVE_PCREPOSIX_H) #include +#elif defined(HAVE_PCRE2POSIX_H) +#include #else #include #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) */