From 3c2c435d6fce92e051fa7ee4a0a784e124660499 Mon Sep 17 00:00:00 2001
From: Jakub Kulik <kulikjak@gmail.com>
Date: Thu, 26 Jun 2025 12:39:32 +0200
Subject: [PATCH] Fix detection and use of pcre2.h from a subdirectory

SF bug #946.
---
 configure.in | 4 ++--
 pcrs.h       | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/configure.in b/configure.in
index 094ccaa6..a363a601 100644
--- a/configure.in
+++ b/configure.in
@@ -887,8 +887,8 @@ AC_CHECK_LIB(pcre2-8, pcre2_compile_8, [
       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])
+         AC_EGREP_HEADER(pcre2_pattern_info, pcre2/pcre2.h, [have_pcre2=yes; AC_DEFINE(HAVE_PCRE2) 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])
    ], [#define PCRE2_CODE_UNIT_WIDTH 8])
 ], [have_pcre2=no])
 
diff --git a/pcrs.h b/pcrs.h
index 8e2fb968..507d6970 100644
--- a/pcrs.h
+++ b/pcrs.h
@@ -36,7 +36,11 @@
 #define PCRE2_CODE_UNIT_WIDTH 8
 #define PCREn(x) PCRE2_ ## x
 #ifndef _PCRE2_H
-#include <pcre2.h>
+#  ifdef PCRE2_H_IN_SUBDIR
+#    include <pcre2/pcre2.h>
+#  else
+#    include <pcre2.h>
+#  endif
 #endif
 
 /*
-- 
2.49.0