monotone

monotone Mtn Source Tree

Root/m4/pcre.m4

1# Set up to use either a bundled or a system-provided version of libpcre.
2#
3# If --with-system-pcre is specified and the library cannot be found
4# or is unsuitable, the configure script will error out rather than
5# falling back to the bundled version. This is to avoid surprising a
6# user who expected their system libpcre to be used. "Unsuitable" is
7# defined as "any version older than the bundled one".
8
9AC_DEFUN([MTN_LIB_PCRE],
10[AC_ARG_WITH([system-pcre],
11 AC_HELP_STRING([--with-system-pcre],
12 [use a system-provided copy of libpcre instead of the default bundled
13 copy. (To use a specific installed version, use the environment
14 variables PCRE_CFLAGS and/or PCRE_LIBS.)]),
15 [case "$withval" in
16 ""|yes) with_system_pcre=yes ;;
17 no) with_system_pcre=no ;;
18 *) AC_MSG_ERROR([--with(out)-system-pcre takes no argument]) ;;
19 esac],
20 [with_system_pcre=no])
21 if test "$with_system_pcre" = yes; then
22 MTN_FIND_PCRE
23 else
24 AC_DEFINE([PCRE_STATIC],[1],[Define if using bundled pcre])
25 AC_MSG_NOTICE([using the bundled copy of PCRE])
26 fi
27 AM_CONDITIONAL([INCLUDED_PCRE], [test $with_system_pcre = no])
28 AC_SUBST([PCRE_CFLAGS])
29 AC_SUBST([PCRE_LIBS])
30])
31
32# This is a separate macro primarily to trick autoconf into not looking
33# for pkg-config if we are using the bundled pcre.
34AC_DEFUN([MTN_FIND_PCRE],
35[ PKG_PROG_PKG_CONFIG
36 # We manually test the variables here because we want them to work
37 # even if pkg-config isn't installed. The use of + instead of :+ is
38 # deliberate; the user should be able to tell us that the empty string
39 # is the correct set of flags. (PKG_CHECK_MODULES gets this wrong!)
40 if test -n "${PCRE_CFLAGS+set}" || test -n "${PCRE_LIBS+set}"; then
41 found_libpcre=yes
42 else
43 PKG_CHECK_MODULES([PCRE], [libpcre],
44 [found_libpcre=yes], [found_libpcre=no])
45 fi
46 if test $found_libpcre = no; then
47 # try pcre-config, in case we're on a system with no pkg-config
48 AC_MSG_CHECKING([for PCRE using pcre-config])
49 if test -n "`type -p pcre-config`"; then
50 PCRE_CFLAGS="`pcre-config --cflags`"
51 # pcre-config has the annoying habit of telling us to use
52 # -L switches for directories that the compiler will search
53 # automatically.
54 PCRE_LIBS="`pcre-config --libs | \
55 sed -e 's:-L */usr/lib/*::' -e 's:-R */usr/lib/*::' \
56 -e 's:-L */lib/*::' -e 's:-R */lib/*::'`"
57 found_libpcre=yes
58 AC_MSG_RESULT([yes])
59 fi
60 fi
61 if test $found_libpcre = no; then
62 AC_MSG_RESULT([no; guessing])
63 PCRE_CFLAGS=
64 PCRE_LIBS=-lpcre
65 fi
66
67 # Wherever we got the settings from, make sure they work.
68 PCRE_CFLAGS="`echo :$PCRE_CFLAGS | sed -e 's/^:@<:@ @:>@*//; s/@<:@ @:>@*$//'`"
69 PCRE_LIBS="`echo :$PCRE_LIBS | sed -e 's/^:@<:@ @:>@*//; s/@<:@ @:>@*$//'`"
70 if test x"$PCRE_CFLAGS" != x""; then
71 AC_MSG_NOTICE([using PCRE compile flags: "$PCRE_CFLAGS"])
72 fi
73 if test x"$PCRE_LIBS" != x"-lpcre"; then
74 AC_MSG_NOTICE([using PCRE link flags: "$PCRE_LIBS"])
75 fi
76 AC_CACHE_CHECK([whether the system libpcre is usable], ac_cv_lib_pcre_works,
77 [save_LIBS="$LIBS"
78 save_CFLAGS="$CFLAGS"
79 LIBS="$LIBS $PCRE_LIBS"
80 CFLAGS="$CFLAGS $PCRE_CFLAGS"
81 AC_LINK_IFELSE([AC_LANG_PROGRAM(
82 [#include <pcre.h>],
83 [const char *e;
84 int dummy;
85 int o;
86 /* Make sure some definitions are present. */
87 dummy = PCRE_NEWLINE_CR;
88 dummy = PCRE_DUPNAMES;
89 pcre *re = pcre_compile("foo", 0, &e, &o, 0);])],
90 [ac_cv_lib_pcre_works=yes], [ac_cv_lib_pcre_works=no])
91 LIBS="$save_LIBS"
92 CFLAGS="$save_CFLAGS"])
93 if test $ac_cv_lib_pcre_works = no; then
94 AC_MSG_ERROR([system-provided libpcre is not usable. Correct your settings or use --with-system-pcre=no.])
95 fi
96
97 # This is deliberately not cached.
98 AC_MSG_CHECKING([whether the system libpcre is new enough])
99 sed -n -e 's/#define PCRE_MAJOR[ ]*/#define BUNDLED_PCRE_MAJOR /p' \
100 -e 's/#define PCRE_MINOR[ ]*/#define BUNDLED_PCRE_MINOR /p' \
101 $srcdir/pcre/pcre.h > conftest.h
102 save_CFLAGS="$CFLAGS"
103 CFLAGS="$CFLAGS $PCRE_CFLAGS"
104 AC_PREPROC_IFELSE([
105#include "conftest.h"
106#include "pcre.h"
107#if PCRE_MAJOR < BUNDLED_PCRE_MAJOR || \
108 (PCRE_MAJOR == BUNDLED_PCRE_MAJOR && PCRE_MINOR < BUNDLED_PCRE_MINOR)
109#error out of date
110#endif],
111 [pcre_version_match=yes],
112 [pcre_version_match=no])
113 AC_MSG_RESULT($pcre_version_match)
114 if test $pcre_version_match = no; then
115 AC_MSG_ERROR([system-provided libpcre is too old. Upgrade it, correct your settings, or use --with-system-pcre=no.])
116 fi
117])

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status