Holger Bruenjes pointed out a typo in my patch; attached is a fix, and an combined patch incorporating the fix.
From dd4f9d03a889a7c37522268b1c72032ffd8acf6e Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 25 May 2014 13:42:03 -0700
Subject: [PATCH] build: remove typo and don't bother with /usr/include/pcre

Problem reported by Holger Bruenjes.
* m4/pcre.m4: Remove test for /usr/include/libpng (a typo).
Come to think of it, don't bother worrying about
/usr/include/pcre, as hosts with that problem can use pkg-config
or configure with CFLAGS by hand.
---
 m4/pcre.m4 | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/m4/pcre.m4 b/m4/pcre.m4
index b9270ed..66e1c9a 100644
--- a/m4/pcre.m4
+++ b/m4/pcre.m4
@@ -23,13 +23,7 @@ AC_DEFUN([gl_FUNC_PCRE],
   use_pcre=no
 
   if test $test_pcre = yes; then
-    PKG_CHECK_MODULES([PCRE], [libpcre], [],
-      [if test -r /usr/include/pcre/pcre.h &&
-          test ! -r /usr/include/pcre.h
-       then
-         PCRE_CFLAGS=-I/usr/include/libpng
-       fi
-       PCRE_LIBS=-lpcre])
+    PKG_CHECK_MODULES([PCRE], [libpcre], [], [PCRE_LIBS=-lpcre])
 
     AC_CACHE_CHECK([for pcre_compile], [pcre_cv_have_pcre_compile],
       [pcre_saved_CFLAGS=$CFLAGS
-- 
1.9.0

diff --git a/bootstrap.conf b/bootstrap.conf
index 9f3457d..73d00b1 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -131,6 +131,21 @@ bootstrap_post_import_hook ()
 {
   # Automake requires that ChangeLog exist.
   touch ChangeLog || return 1
+
+  # Copy pkg-config's pkg.m4 so that our downstream users don't need to.
+  oIFS=$IFS
+  IFS=:
+  for dir in \
+    $ACLOCAL_PATH $(aclocal --print-ac-dir) /usr/share/aclocal ''
+  do
+    IFS=$oIFS
+    if test -n "$dir" && test -r "$dir/pkg.m4"; then
+      cp "$dir/pkg.m4" m4/pkg.m4
+      return
+    fi
+  done
+  IFS=$oIFS
+  die 'Cannot find pkg.m4; perhaps you need to install pkg-config'
 }
 
 bootstrap_epilogue()
diff --git a/configure.ac b/configure.ac
index 7ac2937..4e1fa37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,7 @@ AC_PROG_INSTALL
 AC_PROG_CC
 gl_EARLY
 AC_PROG_RANLIB
+PKG_PROG_PKG_CONFIG([0.9.0])
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_SIZE_T
diff --git a/m4/pcre.m4 b/m4/pcre.m4
index a0b2b68..66e1c9a 100644
--- a/m4/pcre.m4
+++ b/m4/pcre.m4
@@ -1,5 +1,4 @@
 # pcre.m4 - check for libpcre support
-# serial 1
 
 # Copyright (C) 2010-2014 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -17,32 +16,43 @@ AC_DEFUN([gl_FUNC_PCRE],
      esac],
     [test_pcre=yes])
 
-  LIB_PCRE=
-  AC_SUBST([LIB_PCRE])
+  PCRE_CFLAGS=
+  PCRE_LIBS=
+  AC_SUBST([PCRE_CFLAGS])
+  AC_SUBST([PCRE_LIBS])
   use_pcre=no
 
-  if test x"$test_pcre" = x"yes"; then
-    AC_CHECK_HEADERS([pcre.h])
-    AC_CHECK_HEADERS([pcre/pcre.h])
-    if test $ac_cv_header_pcre_h = yes \
-        || test $ac_cv_header_pcre_pcre_h = yes; then
-      pcre_saved_LIBS=$LIBS
-      AC_SEARCH_LIBS([pcre_compile], [pcre],
-        [test "$ac_cv_search_pcre_compile" = "none required" ||
-         LIB_PCRE=$ac_cv_search_pcre_compile])
-      AC_CHECK_FUNCS([pcre_compile])
-      LIBS=$pcre_saved_LIBS
-      if test $ac_cv_func_pcre_compile = yes; then
-        use_pcre=yes
-      fi
-    fi
-    if test $use_pcre = no; then
-      AC_MSG_WARN([libpcre development library was not found or not usable.])
+  if test $test_pcre = yes; then
+    PKG_CHECK_MODULES([PCRE], [libpcre], [], [PCRE_LIBS=-lpcre])
+
+    AC_CACHE_CHECK([for pcre_compile], [pcre_cv_have_pcre_compile],
+      [pcre_saved_CFLAGS=$CFLAGS
+       pcre_saved_LIBS=$LIBS
+       CFLAGS="$CFLAGS $PCRE_CFLAGS"
+       LIBS="$PCRE_LIBS $LIBS"
+       AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM([[#include <pcre.h>
+                          ]],
+            [[pcre *p = pcre_compile (0, 0, 0, 0, 0);
+              return !p;]])],
+         [pcre_cv_have_pcre_compile=yes],
+         [pcre_cv_have_pcre_compile=no])
+       CFLAGS=$pcre_saved_CFLAGS
+       LIBS=$pcre_saved_LIBS])
+
+    if test "$pcre_cv_have_pcre_compile" = yes; then
+      use_pcre=yes
+    else
       AC_MSG_WARN([AC_PACKAGE_NAME will be built without pcre support.])
     fi
   fi
 
-  AC_DEFINE_UNQUOTED([HAVE_LIBPCRE], [`test $use_pcre != yes; echo $?`],
-    [Define to 1 if you have the Perl Compatible Regular Expressions
-     library (-lpcre).])
+  if test $use_pcre = yes; then
+    AC_DEFINE([HAVE_LIBPCRE], [1],
+      [Define to 1 if you have the Perl Compatible Regular Expressions
+       library (-lpcre).])
+  else
+    PCRE_CFLAGS=
+    PCRE_LIBS=
+  fi
 ])
diff --git a/src/Makefile.am b/src/Makefile.am
index e2c82a4..5208a8b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,7 @@
 
 LN = ln
 
-AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
+AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) $(PCRE_CFLAGS)
 
 # Tell the linker to omit references to unused shared libraries.
 AM_LDFLAGS = $(IGNORE_UNUSED_LIBRARIES_CFLAGS)
@@ -38,7 +38,7 @@ LDADD = \
   ../lib/libgreputils.a $(LIBINTL) ../lib/libgreputils.a $(LIBICONV) \
   $(LIBTHREAD)
 
-grep_LDADD = $(LDADD) $(LIB_PCRE)
+grep_LDADD = $(LDADD) $(PCRE_LIBS)
 localedir = $(datadir)/locale
 AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 
diff --git a/src/pcresearch.c b/src/pcresearch.c
index 820dd00..35bfc4d 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -20,13 +20,10 @@
 
 #include <config.h>
 #include "search.h"
-#if HAVE_PCRE_H
-# include <pcre.h>
-#elif HAVE_PCRE_PCRE_H
-# include <pcre/pcre.h>
-#endif
 
 #if HAVE_LIBPCRE
+# include <pcre.h>
+
 /* Compiled internal form of a Perl regular expression.  */
 static pcre *cre;
 

Reply via email to