Enable use of the PCRE2 library on Windows
authorLee <ler762@users.sourceforge.net>
Fri, 4 Aug 2023 09:41:14 +0000 (05:41 -0400)
committerLee <ler762@users.sourceforge.net>
Fri, 4 Aug 2023 09:41:14 +0000 (05:41 -0400)
- windows/MYconfigure

Use the PCRE2 library for building Privoxy on Windows.

- configure.in

PCRE2_STATIC must be defined if you want to statically link the PCRE2 library.
If it isn't defined you'll get these kind of linker errors:
 undefined reference to `_imp__pcre2_compile_8'
 undefined reference to `_imp__pcre2_jit_compile_8'
 undefined reference to `_imp__pcre2_match_data_create_from_pattern_8'
 undefined reference to `_imp__pcre2_match_8'

configure.in
windows/MYconfigure

index 9189b8a..0181d25 100644 (file)
@@ -1140,16 +1140,18 @@ if test $have_pcre2 = "yes"; then
   LIBS="$LIBS -lpcre2-8 -lpcre2-posix"
   if test "$use_static_pcre" = "yes"; then
     pcre_dyn=no
-    AC_DEFINE(PCRE_STATIC,1,[Define to statically link to pcre library on Windows.])
-#     see /usr/i686-w64-mingw32/sys-root/mingw/include/pcre.h line 54
-#       #if defined(_WIN32) && !defined(PCRE_STATIC)
-#       #  ifndef PCRE_EXP_DECL
-#       #    define PCRE_EXP_DECL  extern __declspec(dllimport)
+    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
-#     If you want to statically link a program against a PCRE library in the form of
-#     a non-dll .a file, you must define PCRE_STATIC before including pcre.h or
-#     pcrecpp.h, otherwise the pcre_malloc() and pcre_free() exported functions will
-#     be declared __declspec(dllimport), with unwanted results.
+#       #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.])
index 204866f..b34c95f 100755 (executable)
@@ -20,6 +20,7 @@ fi
 # --enable-mingw32                Use mingw32 for a Windows GUI
 # --enable-static-linking         Use static linking instead of dynamic linking (and not have
 #                                 to put all the .DLLs in the path or the same dir as Privoxy)
+# --disable-pcre2                 Don't try to use the pcre2 library even if it's available
 # --disable-pthread               Use native threads instead of POSIX pthreads library
 # --disable-dynamic-pcre          Use the built-in, static pcre, even if libpcre is available
 # --with-docbook=yes              Enable docbook documentation creation
@@ -80,7 +81,6 @@ LDFLAGS="${LDFLAGS} -Wl,--nxcompat"
 #   $ peflags -v privoxy.exe
 #   privoxy.exe: coff(0x0106[+executable_image,+line_nums_stripped,+32bit_machine]) pe(0x0140[+dynamicbase,+nxcompat])
 
-
 LDFLAGS="${LDFLAGS} -Wl,--dynamicbase,--export-all-symbols"
 # https://en.wikipedia.org/wiki/Address_space_layout_randomization
 # https://stackoverflow.com/questions/24283918/how-can-i-enable-aslr-dep-and-safeseh-on-an-exe-in-codeblocks-using-mingw
@@ -129,8 +129,24 @@ CFLAGS="${CFLAGS} -Wshadow"
 # *sigh* build my own pcre so I can do static linking
 # Get the 8.x PCRE library from
 #   https://sourceforge.net/projects/pcre/files/pcre/
-inc="/source/pcre-8.45/"
-lib="/source/pcre-8.45/.libs"
+# Get the 10.x PCRE2 library from
+#   https://github.com/PCRE2Project/pcre2/releases
+#
+#
+usepcre2=yes
+#
+#
+if [ "$usepcre2" = "yes" ]; then
+    PCREOPT=""
+    inc="/source/pcre2-10.42/src/"
+      # need pcre2.h
+    lib="/source/pcre2-10.42/.libs"
+      # need libpcre2-8.a & libpcre2-posix.a
+else
+    PCREOPT="--disable-pcre2"
+    inc="/source/pcre-8.45/"
+    lib="/source/pcre-8.45/.libs"
+fi
 CPPFLAGS="${CPPFLAGS} -I${inc}"
 LDFLAGS="${LDFLAGS} -L${lib}"
 
@@ -169,6 +185,7 @@ echo "LDFLAGS=${LDFLAGS}"
 
 ./configure  --host=i686-w64-mingw32  --enable-mingw32  --enable-zlib \
              --enable-extended-statistics \
+             ${PCREOPT} \
              --enable-pcre-host-patterns \
              --enable-static-linking \
              --enable-strptime-sanity-checks \