>From 8ee4b29ceec2d5029ab47752e59f46b6d24c5cfb Mon Sep 17 00:00:00 2001
From: Rich Megginson <rmeggins@redhat.com>
Date: Wed, 12 Aug 2009 09:03:32 -0600
Subject: [PATCH] fix pcre build issues

---
 Makefile.am                |    4 +-
 Makefile.in                |    4 +-
 configure                  |   45 ++++++++++++++++++++++++-------------------
 ldap/servers/slapd/regex.c |    3 ++
 ldap/servers/slapd/slap.h  |    3 --
 m4/pcre.m4                 |   37 ++++++++++++++++++++---------------
 6 files changed, 53 insertions(+), 43 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index c49162b..6bfad08 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -558,7 +558,7 @@ libslapd_la_SOURCES = ldap/servers/slapd/add.c \
 	ldap/servers/slapd/vattr.c \
 	$(libavl_a_SOURCES)
 
-libslapd_la_CPPFLAGS = $(PLUGIN_CPPFLAGS) @sasl_inc@ @db_inc@ @svrcore_inc@ @kerberos_inc@
+libslapd_la_CPPFLAGS = $(PLUGIN_CPPFLAGS) @sasl_inc@ @db_inc@ @svrcore_inc@ @kerberos_inc@ @pcre_inc@
 if SOLARIS
 libslapd_la_SOURCES += ldap/servers/slapd/slapi_counter_sunos_sparcv9.S
 endif
@@ -1132,7 +1132,7 @@ ns_slapd_SOURCES = ldap/servers/slapd/abandon.c \
 	$(GETSOCKETPEER)
 
 ns_slapd_CPPFLAGS = $(AM_CPPFLAGS) @sasl_inc@ @openldap_inc@ @ldapsdk_inc@ @nss_inc@ \
-	@nspr_inc@ @svrcore_inc@ @pcre_inc@
+	@nspr_inc@ @svrcore_inc@
 ns_slapd_LDADD = libslapd.la libldaputil.a $(LDAPSDK_LINK) $(NSS_LINK) \
 	$(NSPR_LINK) $(SASL_LINK) $(SVRCORE_LINK) $(LIBNSL) $(LIBSOCKET)
 # We need to link ns-slapd with the C++ compiler on HP-UX since we load
diff --git a/ldap/servers/slapd/regex.c b/ldap/servers/slapd/regex.c
index 24e7b86..6eb682a 100644
--- a/ldap/servers/slapd/regex.c
+++ b/ldap/servers/slapd/regex.c
@@ -45,6 +45,9 @@
 #include "slap.h"
 #include "slapi-plugin.h"
 
+/* Perl Compatible Regular Expression */
+#include <pcre.h>
+
 struct slapi_regex_handle {
     pcre *re_pcre;            /* contains the compiled pattern */
     int  *re_ovector;        /* output vector */
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index 55184a3..ceb46b2 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -167,9 +167,6 @@ typedef struct symbol_t {
 #include "csngen.h"
 #include "uuid.h"
 
-/* Perl Compatible Regular Expression */
-#include <pcre.h>
-
 #if defined(OS_solaris)
 #  include <thread.h>
 #  define GET_THREAD_ID() thr_self()
diff --git a/m4/pcre.m4 b/m4/pcre.m4
index f60123e..6096108 100644
--- a/m4/pcre.m4
+++ b/m4/pcre.m4
@@ -53,24 +53,8 @@ AC_ARG_WITH(pcre, [  --with-pcre=PATH   Perl Compatible Regular Expression direc
 ],
 AC_MSG_RESULT(no))
 
-dnl - check in system locations
-if test -z "$pcre_inc"; then
-  AC_MSG_CHECKING(for pcre.h)
-  if test -f "/usr/include/pcre.h"; then
-    AC_MSG_RESULT([using /usr/include/pcre.h])
-    pcre_incdir="/usr/include"
-    pcre_inc="-I/usr/include"
-    pcre_lib='-L$(libdir)'
-    pcre_libdir='$(libdir)'
-  else
-    AC_MSG_RESULT(no)
-    AC_MSG_ERROR([pcre not found, specify with --with-pcre.])
-  fi
-fi
 #
 # if PCRE is not found yet, try pkg-config
-
-# last resort
 if test -z "$pcre_inc" -o -z "$pcre_lib" -o -z "$pcre_libdir"; then
   AC_PATH_PROG(PKG_CONFIG, pkg-config)
   AC_MSG_CHECKING(for pcre with pkg-config)
@@ -80,8 +64,29 @@ if test -z "$pcre_inc" -o -z "$pcre_lib" -o -z "$pcre_libdir"; then
       pcre_lib=`$PKG_CONFIG --libs-only-L pcre`
       pcre_libdir=`$PKG_CONFIG --libs-only-L pcre | sed -e s/-L// | sed -e s/\ .*$//`
       AC_MSG_RESULT([using system PCRE])
+    elif $PKG_CONFIG --exists libpcre; then
+      pcre_inc=`$PKG_CONFIG --cflags-only-I libpcre`
+      pcre_lib=`$PKG_CONFIG --libs-only-L libpcre`
+      pcre_libdir=`$PKG_CONFIG --libs-only-L libpcre | sed -e s/-L// | sed -e s/\ .*$//`
+      AC_MSG_RESULT([using system PCRE])
     else
       AC_MSG_ERROR([PCRE not found, specify with --with-pcre.])
     fi
   fi
 fi
+
+dnl last resort
+dnl - check in system locations
+if test -z "$pcre_inc"; then
+  AC_MSG_CHECKING(for pcre.h)
+  if test -f "/usr/include/pcre.h"; then
+    AC_MSG_RESULT([using /usr/include/pcre.h])
+    pcre_incdir="/usr/include"
+    pcre_inc="-I/usr/include"
+    pcre_lib='-L$(libdir)'
+    pcre_libdir='$(libdir)'
+  else
+    AC_MSG_RESULT(no)
+    AC_MSG_ERROR([pcre not found, specify with --with-pcre.])
+  fi
+fi
-- 
1.5.5.6

