1 # ===========================================================================
2 # https://www.gnu.org/software/autoconf-archive/ax_check_pcre2.html
3 # ===========================================================================
7 # AX_CHECK_PCRE2([bits], [action-if-found], [action-if-not-found])
11 # Search for an installed libpcre2-8 library. If nothing was specified
12 # when calling configure, it searches first in /usr/local and then in
13 # /usr, /opt/local and /sw. If the --with-pcre2=DIR is specified, it will
14 # try to find it in DIR/include/pcre2.h and DIR/lib/libpcre2-8. If
15 # --without-pcre2 is specified, the library is not searched at all.
17 # If 'bits' is empty or '8', PCRE2 8-bit character support is checked
18 # only. If 'bits' contains '16', PCRE2 8-bit and 16-bit character support
19 # are checked. If 'bits' contains '32', PCRE2 8-bit and 32-bit character
20 # support are checked. When 'bits' contains both '16' and '32', PCRE2
21 # 8-bit, 16-bit, and 32-bit character support is checked.
23 # If either the header file (pcre2.h), or the library (libpcre2-8) is not
24 # found, or the specified PCRE2 character bit width is not supported,
25 # shell commands 'action-if-not-found' is run. If 'action-if-not-found' is
26 # not specified, the configuration exits on error, asking for a valid
27 # PCRE2 installation directory or --without-pcre2.
29 # If both header file and library are found, and the specified PCRE2 bit
30 # widths are supported, shell commands 'action-if-found' is run. If
31 # 'action-if-found' is not specified, the default action appends
32 # '-I${PCRE2_HOME}/include' to CPFLAGS, appends '-L$PCRE2_HOME}/lib' to
33 # LDFLAGS, prepends '-lpcre2-8' to LIBS, and calls AC_DEFINE(HAVE_PCRE2).
34 # You should use autoheader to include a definition for this symbol in a
35 # config.h file. Sample usage in a C/C++ source is as follows:
38 # #define PCRE2_CODE_UNIT_WIDTH 8
40 # #endif /* HAVE_PCRE2 */
44 # Copyright (c) 2020 Robert van Engelen <engelen@acm.org>
46 # This program is free software; you can redistribute it and/or modify it
47 # under the terms of the GNU General Public License as published by the
48 # Free Software Foundation; either version 2 of the License, or (at your
49 # option) any later version.
51 # This program is distributed in the hope that it will be useful, but
52 # WITHOUT ANY WARRANTY; without even the implied warranty of
53 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
54 # Public License for more details.
56 # You should have received a copy of the GNU General Public License along
57 # with this program. If not, see <https://www.gnu.org/licenses/>.
59 # As a special exception, the respective Autoconf Macro's copyright owner
60 # gives unlimited permission to copy, distribute and modify the configure
61 # scripts that are the output of Autoconf when processing the Macro. You
62 # need not follow the terms of the GNU General Public License when using
63 # or distributing such scripts, even though portions of the text of the
64 # Macro appear in them. The GNU General Public License (GPL) does govern
65 # all other use of the material that constitutes the Autoconf Macro.
67 # This special exception to the GPL applies to versions of the Autoconf
68 # Macro released by the Autoconf Archive. When you make and distribute a
69 # modified version of the Autoconf Macro, you may extend this special
70 # exception to the GPL to apply to your modified version as well.
74 AC_DEFUN([AX_CHECK_PCRE2],
78 [AC_MSG_CHECKING(if PCRE2 is wanted)
79 pcre2_places="/usr/local /usr /opt/local /sw"
81 [ --with-pcre2=DIR root directory path of PCRE2 installation @<:@defaults to
82 /usr/local or /usr if not found in /usr/local@:>@
83 --without-pcre2 to disable PCRE2 usage completely],
84 [if test "$withval" != "no" ; then
88 pcre2_places="$withval $pcre2_places"
90 AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
98 # Locate PCRE2, if wanted
100 if test -n "${pcre2_places}"
102 # check the user supplied or any other more or less 'standard' place:
103 # Most UNIX systems : /usr/local and /usr
104 # MacPorts / Fink on OSX : /opt/local respectively /sw
105 for PCRE2_HOME in ${pcre2_places} ; do
106 if test -f "${PCRE2_HOME}/include/pcre2.h"; then break; fi
110 PCRE2_OLD_LDFLAGS=$LDFLAGS
111 PCRE2_OLD_CPPFLAGS=$CPPFLAGS
112 if test -n "${PCRE2_HOME}"; then
113 LDFLAGS="$LDFLAGS -L${PCRE2_HOME}/lib"
114 CPPFLAGS="$CPPFLAGS -I${PCRE2_HOME}/include"
117 AC_CHECK_LIB([pcre2-8], [pcre2_compile_8], [pcre2_cv_libpcre2=yes], [pcre2_cv_libpcre2=no])
118 AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_h=yes], [pcre2_cv_pcre2_h=no], [#define PCRE2_CODE_UNIT_WIDTH 8])
121 AC_CHECK_LIB([pcre2-16], [pcre2_compile_16], [pcre2_cv_libpcre2_16=yes], [pcre2_cv_libpcre2_16=no])
122 AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_16_h=yes], [pcre2_cv_pcre2_16_h=no], [#define PCRE2_CODE_UNIT_WIDTH 16])
123 if test "$pcre2_cv_libpcre2_16" = "no" || test "$pcre2_cv_pcre2_16_h" = "no"; then
130 AC_CHECK_LIB([pcre2-32], [pcre2_compile_32], [pcre2_cv_libpcre2_32=yes], [pcre2_cv_libpcre2_32=no])
131 AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_32_h=yes], [pcre2_cv_pcre2_32_h=no], [#define PCRE2_CODE_UNIT_WIDTH 32])
132 if test "$pcre2_cv_libpcre2_32" = "no" || test "$pcre2_cv_pcre2_32_h" = "no"; then
137 if test "$pcre2_cv_libpcre2" = "yes" && test "$pcre2_cv_pcre2_h" = "yes"
140 # If both library and header were found, action-if-found
143 CPPFLAGS="$CPPFLAGS -I${PCRE2_HOME}/include"
144 LDFLAGS="$LDFLAGS -L${PCRE2_HOME}/lib"
145 LIBS="-lpcre2-8 $LIBS"
146 AC_DEFINE([HAVE_PCRE2], [1],
147 [Define to 1 if you have `PCRE2' library (-lpcre2-$1)])
150 LDFLAGS="$PCRE2_OLD_LDFLAGS"
151 CPPFLAGS="$PCRE2_OLD_CPPFLAGS"
156 # If either header or library was not found, action-if-not-found
159 AC_MSG_ERROR([either specify a valid PCRE2 installation with --with-pcre2=DIR or disable PCRE2 usage with --without-pcre2])