|
| 1 | +# =========================================================================== |
| 2 | +# https://www.gnu.org/software/autoconf-archive/ax_check_pcre2.html |
| 3 | +# =========================================================================== |
| 4 | +# |
| 5 | +# SYNOPSIS |
| 6 | +# |
| 7 | +# AX_CHECK_PCRE2([bits], [action-if-found], [action-if-not-found]) |
| 8 | +# |
| 9 | +# DESCRIPTION |
| 10 | +# |
| 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. |
| 16 | +# |
| 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. |
| 22 | +# |
| 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. |
| 28 | +# |
| 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: |
| 36 | +# |
| 37 | +# #ifdef HAVE_PCRE2 |
| 38 | +# #define PCRE2_CODE_UNIT_WIDTH 8 |
| 39 | +# #include <pcre2.h> |
| 40 | +# #endif /* HAVE_PCRE2 */ |
| 41 | +# |
| 42 | +# LICENSE |
| 43 | +# |
| 44 | +# Copyright (c) 2020 Robert van Engelen <engelen@acm.org> |
| 45 | +# |
| 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. |
| 50 | +# |
| 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. |
| 55 | +# |
| 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/>. |
| 58 | +# |
| 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. |
| 66 | +# |
| 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. |
| 71 | + |
| 72 | +# This is the original upstream check for pcre2 from autoconf-archive website, |
| 73 | +# with these changes: |
| 74 | +# - instead of HAVE_PCRE2 -> WITH_PCRE2 to maintain compatibility |
| 75 | +# - changed CPPFLAGS, LDFLAGS and LIBS to be prefixed with PCRE2_, and do not |
| 76 | +# concat with previous definitions |
| 77 | + |
| 78 | +#serial 2 |
| 79 | + |
| 80 | +AC_DEFUN([AX_CHECK_PCRE2], |
| 81 | +# |
| 82 | +# Handle user hints |
| 83 | +# |
| 84 | +[AC_MSG_CHECKING(if PCRE2 is wanted) |
| 85 | +pcre2_places="/usr/local /usr /opt/local /sw" |
| 86 | +AC_ARG_WITH([pcre2], |
| 87 | +[ --with-pcre2=DIR root directory path of PCRE2 installation @<:@defaults to |
| 88 | + /usr/local or /usr if not found in /usr/local@:>@ |
| 89 | + --without-pcre2 to disable PCRE2 usage completely], |
| 90 | +[if test "$withval" != "no" ; then |
| 91 | + AC_MSG_RESULT(yes) |
| 92 | + if test -d "$withval" |
| 93 | + then |
| 94 | + pcre2_places="$withval $pcre2_places" |
| 95 | + else |
| 96 | + AC_MSG_WARN([Sorry, $withval does not exist, checking usual places]) |
| 97 | + fi |
| 98 | +else |
| 99 | + pcre2_places="" |
| 100 | + AC_MSG_RESULT(no) |
| 101 | +fi], |
| 102 | +[AC_MSG_RESULT(yes)]) |
| 103 | +# |
| 104 | +# Locate PCRE2, if wanted |
| 105 | +# |
| 106 | +if test -n "${pcre2_places}" |
| 107 | +then |
| 108 | + # check the user supplied or any other more or less 'standard' place: |
| 109 | + # Most UNIX systems : /usr/local and /usr |
| 110 | + # MacPorts / Fink on OSX : /opt/local respectively /sw |
| 111 | + for PCRE2_HOME in ${pcre2_places} ; do |
| 112 | + if test -f "${PCRE2_HOME}/include/pcre2.h"; then break; fi |
| 113 | + PCRE2_HOME="" |
| 114 | + done |
| 115 | +
|
| 116 | + PCRE2_OLD_LDFLAGS=$LDFLAGS |
| 117 | + PCRE2_OLD_CPPFLAGS=$CPPFLAGS |
| 118 | + if test -n "${PCRE2_HOME}"; then |
| 119 | + PCRE2_LDFLAGS="-L${PCRE2_HOME}/lib" |
| 120 | + PCRE2_CFLAGS="-I${PCRE2_HOME}/include" |
| 121 | + fi |
| 122 | + AC_LANG_PUSH([C]) |
| 123 | + AC_CHECK_LIB([pcre2-8], [pcre2_compile_8], [pcre2_cv_libpcre2=yes], [pcre2_cv_libpcre2=no]) |
| 124 | + AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_h=yes], [pcre2_cv_pcre2_h=no], [#define PCRE2_CODE_UNIT_WIDTH 8]) |
| 125 | + case "$1" in |
| 126 | + *16*) |
| 127 | + AC_CHECK_LIB([pcre2-16], [pcre2_compile_16], [pcre2_cv_libpcre2_16=yes], [pcre2_cv_libpcre2_16=no]) |
| 128 | + AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_16_h=yes], [pcre2_cv_pcre2_16_h=no], [#define PCRE2_CODE_UNIT_WIDTH 16]) |
| 129 | + if test "$pcre2_cv_libpcre2_16" = "no" || test "$pcre2_cv_pcre2_16_h" = "no"; then |
| 130 | + pcre2_cv_libpcre2=no |
| 131 | + fi |
| 132 | + ;; |
| 133 | + esac |
| 134 | + case "$1" in |
| 135 | + *32*) |
| 136 | + AC_CHECK_LIB([pcre2-32], [pcre2_compile_32], [pcre2_cv_libpcre2_32=yes], [pcre2_cv_libpcre2_32=no]) |
| 137 | + AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_32_h=yes], [pcre2_cv_pcre2_32_h=no], [#define PCRE2_CODE_UNIT_WIDTH 32]) |
| 138 | + if test "$pcre2_cv_libpcre2_32" = "no" || test "$pcre2_cv_pcre2_32_h" = "no"; then |
| 139 | + pcre2_cv_libpcre2=no |
| 140 | + fi |
| 141 | + esac |
| 142 | + AC_LANG_POP([C]) |
| 143 | + if test "$pcre2_cv_libpcre2" = "yes" && test "$pcre2_cv_pcre2_h" = "yes" |
| 144 | + then |
| 145 | + # |
| 146 | + # If both library and header were found, action-if-found |
| 147 | + # |
| 148 | + m4_ifblank([$2],[ |
| 149 | + PCRE2_CFLAGS="-I${PCRE2_HOME}/include" |
| 150 | + PCRE2_LDFLAGS="-L${PCRE2_HOME}/lib" |
| 151 | + PCRE2_LDADD="-lpcre2-8" |
| 152 | + AC_SUBST(PCRE2_CFLAGS) |
| 153 | + AC_SUBST(PCRE2_LDFLAGS) |
| 154 | + AC_SUBST(PCRE2_LDADD) |
| 155 | + AC_DEFINE([WITH_PCRE2], [1], |
| 156 | + [Define to 1 if you have `PCRE2' library (-lpcre2-$1)]) |
| 157 | + ],[ |
| 158 | + # Restore variables |
| 159 | + LDFLAGS="$PCRE2_OLD_LDFLAGS" |
| 160 | + CPPFLAGS="$PCRE2_OLD_CPPFLAGS" |
| 161 | + $2 |
| 162 | + ]) |
| 163 | + else |
| 164 | + # |
| 165 | + # If either header or library was not found, action-if-not-found |
| 166 | + # |
| 167 | + m4_default([$3],[ |
| 168 | + AC_MSG_ERROR([either specify a valid PCRE2 installation with --with-pcre2=DIR or disable PCRE2 usage with --without-pcre2]) |
| 169 | + ]) |
| 170 | + fi |
| 171 | +fi |
| 172 | +]) |
0 commit comments