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.
... | ... |
@@ -6,44 +6,81 @@ AC_ARG_WITH([pcre],[AS_HELP_STRING([--with-pcre@<:@=DIR@:>@], |
6 | 6 |
@<:@default=search PATH environment variable@:>@])], |
7 | 7 |
[pcreser=$withval],[pcreser="yes"]) |
8 | 8 |
|
9 |
-dnl determine if specified (or default) is valid |
|
10 |
-case "$pcreser" in |
|
11 |
-no) |
|
12 |
- pcreconfig="" |
|
13 |
- ;; |
|
14 |
-yes) |
|
15 |
- dnl default - search PATH |
|
16 |
- AC_PATH_PROG([pcreconfig], [pcre2-config]) |
|
17 |
- if test "x$pcreconfig" = "x"; then |
|
18 |
- AC_PATH_PROG([pcreconfig], [pcre-config]) |
|
19 |
- if test "x$pcreconfig" = "x"; then |
|
20 |
- AC_MSG_NOTICE([cannot locate libpcre2 or libpcre within PATH]) |
|
21 |
- else |
|
22 |
- pcrelib="pcre" |
|
23 |
- fi |
|
24 |
- else |
|
9 |
+dnl Look for pcre-config or pcre2-config within the specified path, |
|
10 |
+dnl or (by default) in the system's default search path. This is |
|
11 |
+dnl the only place the value of --with-pcre is used. |
|
12 |
+AS_CASE([$pcreser], |
|
13 |
+ [no], |
|
14 |
+ [pcreconfig=""], |
|
15 |
+dnl |
|
16 |
+ [yes], |
|
17 |
+ [ dnl No path was specified, so we execute the default action, which is |
|
18 |
+ dnl to search for PCRE on the system. First, we try pkg-config; if that |
|
19 |
+ dnl doesn't work, we search for the pcre-config or pcre2-config programs |
|
20 |
+ dnl in the system's search path. We look for the 8-bit library because |
|
21 |
+ dnl that's what the fallback check did when pkg-config was introduced |
|
22 |
+ dnl here. The name "PCRE" was chosen to match e.g. PCRE_CPPFLAGS from |
|
23 |
+ dnl the non-pkgconfig branch. |
|
24 |
+ PKG_CHECK_MODULES([PCRE], [libpcre2-8 >= 10.30], [ |
|
25 |
+ dnl We found libpcre2 with pkg-config. We leave $pcreconfig empty, |
|
26 |
+ dnl so that the next big "if" branch below is skipped, and we |
|
27 |
+ dnl therefore don't try to do anything further with pcre-config. |
|
28 |
+ dnl The subsequent "if" block that tests $found_pcre is also |
|
29 |
+ dnl skipped, leaving us at the very last conditional for $have_pcre |
|
30 |
+ dnl and $pcrelib. We set those variables here so that HAVE_PCRE and |
|
31 |
+ dnl USING_PCRE2 will be defined. Finally, we append the output of |
|
32 |
+ dnl "pkg-config --libs" to the LIBS variable. |
|
33 |
+ have_pcre="yes" |
|
25 | 34 |
pcrelib="pcre2" |
26 |
- fi |
|
27 |
- ;; |
|
28 |
-"") |
|
29 |
- AC_MSG_ERROR([cannot assign blank value to --with-pcre]) |
|
30 |
- ;; |
|
31 |
-*) |
|
32 |
- AC_PATH_PROG([pcreconfig], [pcre2-config], [], [$pcreser/bin]) |
|
33 |
- if test "x$pcreconfig" = "x"; then |
|
34 |
- AC_PATH_PROG([pcreconfig], [pcre-config], [], [$pcreser/bin]) |
|
35 |
+ |
|
36 |
+ # PCRE_LIBS contains the output of "pkg-config --libs" here, |
|
37 |
+ # and likewise for PCRE_CFLAGS which is even more of a misnomer, |
|
38 |
+ # as pkg-config --cflags outputs preprocessor flags. |
|
39 |
+ LIBS="${LIBS} ${PCRE_LIBS}" |
|
40 |
+ PCRE_CPPFLAGS="${PCRE_CPPFLAGS} ${PCRE_CFLAGS}" |
|
41 |
+ |
|
42 |
+ dnl The summary at the end of ./configure checks that this is non-empty. |
|
43 |
+ PCRE_HOME="pkg-config" |
|
44 |
+ if test -n "${PCRE_LIBS}" || test -n "${PCRE_CFLAGS}"; then |
|
45 |
+ PCRE_HOME="${PCRE_HOME} ( ${PCRE_LIBS} ${PCRE_CFLAGS} )" |
|
46 |
+ fi |
|
47 |
+ ], [ |
|
48 |
+ dnl We didn't find libpcre2 with pkg-config, fall back to pcre(2)-config. |
|
49 |
+ AC_PATH_PROG([pcreconfig], [pcre2-config]) |
|
35 | 50 |
if test "x$pcreconfig" = "x"; then |
36 |
- AC_MSG_ERROR([cannot locate libpcre2 or libpcre at $pcreser]) |
|
51 |
+ AC_PATH_PROG([pcreconfig], [pcre-config]) |
|
52 |
+ if test "x$pcreconfig" = "x"; then |
|
53 |
+ AC_MSG_NOTICE([cannot locate libpcre2 or libpcre within PATH]) |
|
54 |
+ else |
|
55 |
+ pcrelib="pcre" |
|
56 |
+ fi |
|
37 | 57 |
else |
38 |
- pcrelib="pcre" |
|
58 |
+ pcrelib="pcre2" |
|
39 | 59 |
fi |
40 |
- else |
|
41 |
- pcrelib="pcre2" |
|
42 |
- fi |
|
43 |
- ;; |
|
44 |
-esac |
|
60 |
+ ]) |
|
61 |
+ ], |
|
62 |
+dnl |
|
63 |
+ [""], |
|
64 |
+ [AC_MSG_ERROR([cannot assign blank value to --with-pcre])], |
|
65 |
+dnl default case: |
|
66 |
+ [ AC_PATH_PROG([pcreconfig], [pcre2-config], [], [$pcreser/bin]) |
|
67 |
+ if test "x$pcreconfig" = "x"; then |
|
68 |
+ AC_PATH_PROG([pcreconfig], [pcre-config], [], [$pcreser/bin]) |
|
69 |
+ if test "x$pcreconfig" = "x"; then |
|
70 |
+ AC_MSG_ERROR([cannot locate libpcre2 or libpcre at $pcreser]) |
|
71 |
+ else |
|
72 |
+ pcrelib="pcre" |
|
73 |
+ fi |
|
74 |
+ else |
|
75 |
+ pcrelib="pcre2" |
|
76 |
+ fi |
|
77 |
+ ]) |
|
45 | 78 |
|
46 |
-dnl use pcre-config to check version, get cflags and libs |
|
79 |
+dnl At this point we have either found pcre(2)-config, or not, and |
|
80 |
+dnl the path to it is stored in $pcreconfig. If we found it, we use |
|
81 |
+dnl it to get the PCRE version, CFLAGS, LIBS, et cetera. Note that |
|
82 |
+dnl this next "if" will always fail if we found libpcre2 with pkg- |
|
83 |
+dnl config. |
|
47 | 84 |
found_pcre="no" |
48 | 85 |
if test "x$pcreconfig" != "x"; then |
49 | 86 |
AC_MSG_CHECKING([pcre-config version]) |
... | ... |
@@ -101,7 +138,12 @@ if test "x$pcreconfig" != "x"; then |
101 | 101 |
AC_MSG_NOTICE([LIBS from pcre-config: $PCRE_LIBS]) |
102 | 102 |
fi |
103 | 103 |
|
104 |
-have_pcre="no" |
|
104 |
+if test "x$have_pcre" != "xyes"; then |
|
105 |
+ dnl default to "no" only if the pkg-config check hasn't already |
|
106 |
+ dnl set it to "yes" |
|
107 |
+ have_pcre="no" |
|
108 |
+fi |
|
109 |
+ |
|
105 | 110 |
if test "x$found_pcre" != "xno"; then |
106 | 111 |
dnl save_LIBS="$LIBS" |
107 | 112 |
save_CPPFLAGS="$CPPFLAGS" |