configure: Fix --disable-pcre2
[privoxy.git] / configure.in
index c6e916e..f8a23a5 100644 (file)
@@ -863,12 +863,48 @@ else
   ])
 fi
 
+AC_ARG_ENABLE(pcre2,
+[  --disable-pcre2                  Don't try to use pcre2 even if it's available],
+[enableval2=$enableval],
+[enableval2=yes])
+if test $enableval2 = yes; then
+  try_pcre2=yes
+else
+  AC_MSG_WARN([Ignoring pcre2 even if it's available])
+  try_pcre2=no
+  have_pcre2=no
+fi
+
+if test $try_pcre2 != no; then
 dnl =================================================================
 dnl Checks for libraries.
 dnl =================================================================
 dnl Note: Some systems may have the library but not the system header
 dnl       file, so we must check for both.
 dnl       Also check for correct version
+AC_CHECK_LIB(pcre2-8, pcre2_compile_8, [
+   AC_CHECK_HEADER(pcre2.h, [
+      AC_EGREP_HEADER(pcre2_pattern_info, pcre2.h,[have_pcre2=yes; AC_DEFINE(HAVE_PCRE2)], [AC_MSG_WARN([[pcre2 old version installed]]); have_pcre2=no])
+   ], [
+      AC_CHECK_HEADER(pcre2/pcre2.h, [
+         AC_EGREP_HEADER(pcre2_pattern_info, pcre2/pcre2.h, [have_pcre2=yes; AC_DEFINE(PCRE2_H_IN_SUBDIR)], [AC_MSG_WARN([[pcre2 old version installed]]); have_pcre2=no])
+      ], [have_pcre2=no])
+   ], [#define PCRE2_CODE_UNIT_WIDTH 8])
+], [have_pcre2=no])
+
+AC_CHECK_LIB(pcre2-posix, regcomp, [
+   AC_CHECK_HEADER(pcre2posix.h, [
+      AC_EGREP_HEADER(pcre2_regerror, pcre2posix.h, [have_pcre2posix=yes],[AC_MSG_WARN([[pcre2posix old version installed]]); have_pcre2posix=no])
+   ], [
+      AC_CHECK_HEADER(pcre/pcre2posix.h, [
+         AC_EGREP_HEADER(pcre2_regerror, pcre2/pcre2posix.h,  [have_pcre2posix=yes; AC_DEFINE(PCRE2POSIX_H_IN_SUBDIR)],[AC_MSG_WARN([[pcre2posix old version installed]]); have_pcre2posix=no])
+      ], [have_pcre2posix=no])
+   ])
+], [have_pcre2posix=no], -lpcre2-8)
+fi
+
+if test $have_pcre2 = "no"; then
+
 AC_CHECK_LIB(pcre, pcre_compile, [
    AC_CHECK_HEADER(pcre.h, [
       AC_EGREP_HEADER(pcre_fullinfo, pcre.h, [have_pcre=yes], [AC_MSG_WARN([[pcre old version installed]]); have_pcre=no])
@@ -889,6 +925,7 @@ AC_CHECK_LIB(pcreposix, regcomp, [
    ])
 ], [have_pcreposix=no], -lpcre)
 
+fi
 dnl ================================================================
 dnl libpcrs is temporarily disabled.
 dnl
@@ -1095,6 +1132,33 @@ fi
 # we don't need pcreposix, then link pcre dynamically; else
 # build it and link statically
 #
+
+#check for libpcre2 first. then regular pcre
+
+if test $have_pcre2 = "yes"; then
+  echo "using libpcre2"
+  STATIC_PCRE_ONLY=#
+  LIBS="$LIBS -lpcre2-8 -lpcre2-posix"
+  if test "$use_static_pcre" = "yes"; then
+    pcre_dyn=no
+    AC_DEFINE(PCRE2_STATIC,1,[Define to statically link to the pcre2 library on Windows.])
+#     see pcre2-10.42/src/pcre2.h line 54
+#       #if defined(_WIN32) && !defined(PCRE2_STATIC)
+#       #  ifndef PCRE2_EXP_DECL
+#       #    define PCRE2_EXP_DECL  extern __declspec(dllimport)
+#       #  endif
+#       #endif
+#     If you want to statically link a program against a PCRE2 library in the form of
+#     a non-dll .a file, you must define PCRE2_STATIC before including src/pcre2.h.
+#     Otherwise the exported functions will be declared __declspec(dllimport),
+#     with unwanted results.  eg: build failures with error messages like
+#       undefined reference to `_imp__pcre2_compile_8'
+  else
+    pcre_dyn=yes
+    AC_DEFINE(FEATURE_DYNAMIC_PCRE,1,[Define to dynamically link to pcre.])
+  fi
+else
+
 if test $have_pcre = "yes"; then
   echo "using libpcre"
   STATIC_PCRE_ONLY=#
@@ -1116,7 +1180,8 @@ if test $have_pcre = "yes"; then
     AC_DEFINE(FEATURE_DYNAMIC_PCRE,1,[Define to dynamically link to pcre.])
   fi
 else
-  AC_MSG_ERROR(pcre library not detected.)
+  AC_MSG_ERROR(Detected neither pcre2 nor pcre library.)
+fi
 fi
 
 AC_DEFINE(FEATURE_CONNECTION_KEEP_ALIVE)