Autotools: Add pkg-config support for finding pcre2

To fix an old (and probably no longer manifest) build bug, this commit
adds the ability to detect an 8-bit libpcre2 with pkg-config in
addition to the other methods of specifying/detecting it. The
intention is that pkg-config will be used only in the default case,
where pcre support is detected automatically; that is, NOT in either
of these cases:

    * --with-pcre=<path> is given
    * --with-pcre=no is given

The code in pcre.m4 was modified minimally so that --with-pcre=yes
(the default) tries pkg-config first, and then falls back to whatever
it used to do. If pkg-config can find the library, we add PCRE_LIBS
to the LIBS variable and we're done. Otherwise, the old behavior is
retained.

ClamAV-bug: https://bugzilla.clamav.net/show_bug.cgi?id=12484
Gentoo-bug: https://bugs.gentoo.org/567680

This commit also collects the preprocessor flags obtained from
pkg-config.

When libpcre2 is found using pkg-config, we now say that explicitly,
and include its PCRE_LIBS and PCRE_CFLAGS in the output.
pull/136/head
Michael Orlitzky 5 years ago committed by Micah Snyder (micasnyd)
parent a9933ef138
commit c61b684410
  1. 110
      m4/reorganization/libs/pcre.m4

@ -6,44 +6,81 @@ AC_ARG_WITH([pcre],[AS_HELP_STRING([--with-pcre@<:@=DIR@:>@],
@<:@default=search PATH environment variable@:>@])],
[pcreser=$withval],[pcreser="yes"])
dnl determine if specified (or default) is valid
case "$pcreser" in
no)
pcreconfig=""
;;
yes)
dnl default - search PATH
AC_PATH_PROG([pcreconfig], [pcre2-config])
if test "x$pcreconfig" = "x"; then
AC_PATH_PROG([pcreconfig], [pcre-config])
if test "x$pcreconfig" = "x"; then
AC_MSG_NOTICE([cannot locate libpcre2 or libpcre within PATH])
else
pcrelib="pcre"
fi
else
dnl Look for pcre-config or pcre2-config within the specified path,
dnl or (by default) in the system's default search path. This is
dnl the only place the value of --with-pcre is used.
AS_CASE([$pcreser],
[no],
[pcreconfig=""],
dnl
[yes],
[ dnl No path was specified, so we execute the default action, which is
dnl to search for PCRE on the system. First, we try pkg-config; if that
dnl doesn't work, we search for the pcre-config or pcre2-config programs
dnl in the system's search path. We look for the 8-bit library because
dnl that's what the fallback check did when pkg-config was introduced
dnl here. The name "PCRE" was chosen to match e.g. PCRE_CPPFLAGS from
dnl the non-pkgconfig branch.
PKG_CHECK_MODULES([PCRE], [libpcre2-8 >= 10.30], [
dnl We found libpcre2 with pkg-config. We leave $pcreconfig empty,
dnl so that the next big "if" branch below is skipped, and we
dnl therefore don't try to do anything further with pcre-config.
dnl The subsequent "if" block that tests $found_pcre is also
dnl skipped, leaving us at the very last conditional for $have_pcre
dnl and $pcrelib. We set those variables here so that HAVE_PCRE and
dnl USING_PCRE2 will be defined. Finally, we append the output of
dnl "pkg-config --libs" to the LIBS variable.
have_pcre="yes"
pcrelib="pcre2"
fi
;;
"")
AC_MSG_ERROR([cannot assign blank value to --with-pcre])
;;
*)
AC_PATH_PROG([pcreconfig], [pcre2-config], [], [$pcreser/bin])
if test "x$pcreconfig" = "x"; then
AC_PATH_PROG([pcreconfig], [pcre-config], [], [$pcreser/bin])
# PCRE_LIBS contains the output of "pkg-config --libs" here,
# and likewise for PCRE_CFLAGS which is even more of a misnomer,
# as pkg-config --cflags outputs preprocessor flags.
LIBS="${LIBS} ${PCRE_LIBS}"
PCRE_CPPFLAGS="${PCRE_CPPFLAGS} ${PCRE_CFLAGS}"
dnl The summary at the end of ./configure checks that this is non-empty.
PCRE_HOME="pkg-config"
if test -n "${PCRE_LIBS}" || test -n "${PCRE_CFLAGS}"; then
PCRE_HOME="${PCRE_HOME} ( ${PCRE_LIBS} ${PCRE_CFLAGS} )"
fi
], [
dnl We didn't find libpcre2 with pkg-config, fall back to pcre(2)-config.
AC_PATH_PROG([pcreconfig], [pcre2-config])
if test "x$pcreconfig" = "x"; then
AC_MSG_ERROR([cannot locate libpcre2 or libpcre at $pcreser])
AC_PATH_PROG([pcreconfig], [pcre-config])
if test "x$pcreconfig" = "x"; then
AC_MSG_NOTICE([cannot locate libpcre2 or libpcre within PATH])
else
pcrelib="pcre"
fi
else
pcrelib="pcre"
pcrelib="pcre2"
fi
else
pcrelib="pcre2"
fi
;;
esac
])
],
dnl
[""],
[AC_MSG_ERROR([cannot assign blank value to --with-pcre])],
dnl default case:
[ AC_PATH_PROG([pcreconfig], [pcre2-config], [], [$pcreser/bin])
if test "x$pcreconfig" = "x"; then
AC_PATH_PROG([pcreconfig], [pcre-config], [], [$pcreser/bin])
if test "x$pcreconfig" = "x"; then
AC_MSG_ERROR([cannot locate libpcre2 or libpcre at $pcreser])
else
pcrelib="pcre"
fi
else
pcrelib="pcre2"
fi
])
dnl use pcre-config to check version, get cflags and libs
dnl At this point we have either found pcre(2)-config, or not, and
dnl the path to it is stored in $pcreconfig. If we found it, we use
dnl it to get the PCRE version, CFLAGS, LIBS, et cetera. Note that
dnl this next "if" will always fail if we found libpcre2 with pkg-
dnl config.
found_pcre="no"
if test "x$pcreconfig" != "x"; then
AC_MSG_CHECKING([pcre-config version])
@ -101,7 +138,12 @@ if test "x$pcreconfig" != "x"; then
AC_MSG_NOTICE([LIBS from pcre-config: $PCRE_LIBS])
fi
have_pcre="no"
if test "x$have_pcre" != "xyes"; then
dnl default to "no" only if the pkg-config check hasn't already
dnl set it to "yes"
have_pcre="no"
fi
if test "x$found_pcre" != "xno"; then
dnl save_LIBS="$LIBS"
save_CPPFLAGS="$CPPFLAGS"

Loading…
Cancel
Save