(tree_move): fix coding style.
[midnight-commander.git] / m4.include / ax_check_pcre2.m4
blob9ae01addf3c1c7dfabfc4da5c51d698dc48358da
1 # ===========================================================================
2 #      https://www.gnu.org/software/autoconf-archive/ax_check_pcre2.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_CHECK_PCRE2([bits], [action-if-found], [action-if-not-found])
9 # DESCRIPTION
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:
37 #     #ifdef HAVE_PCRE2
38 #     #define PCRE2_CODE_UNIT_WIDTH 8
39 #     #include <pcre2.h>
40 #     #endif /* HAVE_PCRE2 */
42 # LICENSE
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.
72 #serial 2
74 AC_DEFUN([AX_CHECK_PCRE2],
76 # Handle user hints
78 [AC_MSG_CHECKING(if PCRE2 is wanted)
79 pcre2_places="/usr/local /usr /opt/local /sw"
80 AC_ARG_WITH([pcre2],
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
85   AC_MSG_RESULT(yes)
86   if test -d "$withval"
87   then
88     pcre2_places="$withval $pcre2_places"
89   else
90     AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
91   fi
92 else
93   pcre2_places=""
94   AC_MSG_RESULT(no)
95 fi],
96 [AC_MSG_RESULT(yes)])
98 # Locate PCRE2, if wanted
100 if test -n "${pcre2_places}"
101 then
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
107     PCRE2_HOME=""
108   done
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"
115   fi
116   AC_LANG_PUSH([C])
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])
119   case "$1" in
120   *16*)
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
124       pcre2_cv_libpcre2=no
125     fi
126     ;;
127   esac
128   case "$1" in
129   *32*)
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
133       pcre2_cv_libpcre2=no
134     fi
135   esac
136   AC_LANG_POP([C])
137   if test "$pcre2_cv_libpcre2" = "yes" && test "$pcre2_cv_pcre2_h" = "yes"
138   then
139     #
140     # If both library and header were found, action-if-found
141     #
142     m4_ifblank([$2],[
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)])
148                ],[
149                 # Restore variables
150                 LDFLAGS="$PCRE2_OLD_LDFLAGS"
151                 CPPFLAGS="$PCRE2_OLD_CPPFLAGS"
152                 $2
153                ])
154   else
155     #
156     # If either header or library was not found, action-if-not-found
157     #
158     m4_default([$3],[
159                 AC_MSG_ERROR([either specify a valid PCRE2 installation with --with-pcre2=DIR or disable PCRE2 usage with --without-pcre2])
160                 ])
161   fi