• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl Process this file with autoconf to produce a configure script.
2
3dnl NOTE FOR MAINTAINERS: Do not use minor version numbers 08 or 09 because
4dnl the leading zeros may cause them to be treated as invalid octal constants
5dnl if a PCRE2 user writes code that uses PCRE2_MINOR as a number. There is now
6dnl a check further down that throws an error if 08 or 09 are used.
7
8dnl The PCRE2_PRERELEASE feature is for identifying release candidates. It might
9dnl be defined as -RC2, for example. For real releases, it should be empty.
10
11m4_define(pcre2_major, [10])
12m4_define(pcre2_minor, [32])
13m4_define(pcre2_prerelease, [])
14m4_define(pcre2_date, [2018-09-10])
15
16# NOTE: The CMakeLists.txt file searches for the above variables in the first
17# 50 lines of this file. Please update that if the variables above are moved.
18
19# Libtool shared library interface versions (current:revision:age)
20m4_define(libpcre2_8_version,     [7:1:7])
21m4_define(libpcre2_16_version,    [7:1:7])
22m4_define(libpcre2_32_version,    [7:1:7])
23m4_define(libpcre2_posix_version, [2:1:0])
24
25AC_PREREQ(2.57)
26AC_INIT(PCRE2, pcre2_major.pcre2_minor[]pcre2_prerelease, , pcre2)
27AC_CONFIG_SRCDIR([src/pcre2.h.in])
28AM_INIT_AUTOMAKE([dist-bzip2 dist-zip])
29m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
30AC_CONFIG_HEADERS(src/config.h)
31
32# This was added at the suggestion of libtoolize (03-Jan-10)
33AC_CONFIG_MACRO_DIR([m4])
34
35# The default CFLAGS in Autoconf are "-g -O2" for gcc and just "-g" for any
36# other compiler. There doesn't seem to be a standard way of getting rid of the
37# -g (which I don't think is needed for a production library). This fudge seems
38# to achieve the necessary. First, we remember the externally set values of
39# CFLAGS. Then call the AC_PROG_CC macro to find the compiler - if CFLAGS is
40# not set, it will be set to Autoconf's defaults. Afterwards, if the original
41# values were not set, remove the -g from the Autoconf defaults.
42
43remember_set_CFLAGS="$CFLAGS"
44
45AC_PROG_CC
46AM_PROG_CC_C_O
47AC_USE_SYSTEM_EXTENSIONS
48
49if test "x$remember_set_CFLAGS" = "x"
50then
51  if test "$CFLAGS" = "-g -O2"
52  then
53    CFLAGS="-O2"
54  elif test "$CFLAGS" = "-g"
55  then
56    CFLAGS=""
57  fi
58fi
59
60# This is a new thing required to stop a warning from automake 1.12
61m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
62
63# Check for a 64-bit integer type
64AC_TYPE_INT64_T
65
66AC_PROG_INSTALL
67AC_LIBTOOL_WIN32_DLL
68LT_INIT
69AC_PROG_LN_S
70
71# Check for GCC visibility feature
72
73PCRE2_VISIBILITY
74
75# Versioning
76
77PCRE2_MAJOR="pcre2_major"
78PCRE2_MINOR="pcre2_minor"
79PCRE2_PRERELEASE="pcre2_prerelease"
80PCRE2_DATE="pcre2_date"
81
82if test "$PCRE2_MINOR" = "08" -o "$PCRE2_MINOR" = "09"
83then
84  echo "***"
85  echo "*** Minor version number $PCRE2_MINOR must not be used. ***"
86  echo "*** Use only 00 to 07 or 10 onwards, to avoid octal issues. ***"
87  echo "***"
88  exit 1
89fi
90
91AC_SUBST(PCRE2_MAJOR)
92AC_SUBST(PCRE2_MINOR)
93AC_SUBST(PCRE2_PRERELEASE)
94AC_SUBST(PCRE2_DATE)
95
96# Set a more sensible default value for $(htmldir).
97if test "x$htmldir" = 'x${docdir}'
98then
99  htmldir='${docdir}/html'
100fi
101
102# Force an error for PCRE1 size options
103AC_ARG_ENABLE(pcre8,,,enable_pcre8=no)
104AC_ARG_ENABLE(pcre16,,,enable_pcre16=no)
105AC_ARG_ENABLE(pcre32,,,enable_pcre32=no)
106
107if test "$enable_pcre8$enable_pcre16$enable_pcre32" != "nonono"
108then
109  echo "** ERROR: Use --[[en|dis]]able-pcre2-[[8|16|32]], not --[[en|dis]]able-pcre[[8|16|32]]"
110  exit 1
111fi
112
113# Handle --disable-pcre2-8 (enabled by default)
114AC_ARG_ENABLE(pcre2-8,
115              AS_HELP_STRING([--disable-pcre2-8],
116                             [disable 8 bit character support]),
117              , enable_pcre2_8=unset)
118AC_SUBST(enable_pcre2_8)
119
120# Handle --enable-pcre2-16 (disabled by default)
121AC_ARG_ENABLE(pcre2-16,
122              AS_HELP_STRING([--enable-pcre2-16],
123                             [enable 16 bit character support]),
124              , enable_pcre2_16=unset)
125AC_SUBST(enable_pcre2_16)
126
127# Handle --enable-pcre2-32 (disabled by default)
128AC_ARG_ENABLE(pcre2-32,
129              AS_HELP_STRING([--enable-pcre2-32],
130                             [enable 32 bit character support]),
131              , enable_pcre2_32=unset)
132AC_SUBST(enable_pcre2_32)
133
134# Handle --dnable-debug (disabled by default)
135AC_ARG_ENABLE(debug,
136              AS_HELP_STRING([--enable-debug],
137                             [enable debugging code]),
138              , enable_debug=no)
139
140# Handle --enable-jit (disabled by default)
141AC_ARG_ENABLE(jit,
142              AS_HELP_STRING([--enable-jit],
143                             [enable Just-In-Time compiling support]),
144              , enable_jit=no)
145
146# This code enables JIT if the hardware supports it.
147if test "$enable_jit" = "auto"; then
148  AC_LANG(C)
149  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
150  #define SLJIT_CONFIG_AUTO 1
151  #include "src/sljit/sljitConfigInternal.h"
152  #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
153  #error unsupported
154  #endif]])], enable_jit=yes, enable_jit=no)
155  echo checking for JIT support on this hardware... $enable_jit
156fi
157
158# Handle --enable-jit-sealloc (disabled by default)
159AC_ARG_ENABLE(jit-sealloc,
160              AS_HELP_STRING([--enable-jit-sealloc],
161                             [enable SELinux compatible execmem allocator in JIT]),
162              , enable_jit_sealloc=no)
163
164# Handle --disable-pcre2grep-jit (enabled by default)
165AC_ARG_ENABLE(pcre2grep-jit,
166              AS_HELP_STRING([--disable-pcre2grep-jit],
167                             [disable JIT support in pcre2grep]),
168              , enable_pcre2grep_jit=yes)
169
170# Handle --disable-pcre2grep-callout (enabled by default)
171AC_ARG_ENABLE(pcre2grep-callout,
172              AS_HELP_STRING([--disable-pcre2grep-callout],
173                             [disable callout script support in pcre2grep]),
174              , enable_pcre2grep_callout=yes)
175
176# Handle --enable-rebuild-chartables
177AC_ARG_ENABLE(rebuild-chartables,
178              AS_HELP_STRING([--enable-rebuild-chartables],
179                             [rebuild character tables in current locale]),
180              , enable_rebuild_chartables=no)
181
182# Handle --disable-unicode (enabled by default)
183AC_ARG_ENABLE(unicode,
184              AS_HELP_STRING([--disable-unicode],
185                             [disable Unicode support]),
186              , enable_unicode=unset)
187
188# Handle newline options
189ac_pcre2_newline=lf
190AC_ARG_ENABLE(newline-is-cr,
191              AS_HELP_STRING([--enable-newline-is-cr],
192                             [use CR as newline character]),
193              ac_pcre2_newline=cr)
194AC_ARG_ENABLE(newline-is-lf,
195              AS_HELP_STRING([--enable-newline-is-lf],
196                             [use LF as newline character (default)]),
197              ac_pcre2_newline=lf)
198AC_ARG_ENABLE(newline-is-crlf,
199              AS_HELP_STRING([--enable-newline-is-crlf],
200                             [use CRLF as newline sequence]),
201              ac_pcre2_newline=crlf)
202AC_ARG_ENABLE(newline-is-anycrlf,
203              AS_HELP_STRING([--enable-newline-is-anycrlf],
204                             [use CR, LF, or CRLF as newline sequence]),
205              ac_pcre2_newline=anycrlf)
206AC_ARG_ENABLE(newline-is-any,
207              AS_HELP_STRING([--enable-newline-is-any],
208                             [use any valid Unicode newline sequence]),
209              ac_pcre2_newline=any)
210AC_ARG_ENABLE(newline-is-nul,
211              AS_HELP_STRING([--enable-newline-is-nul],
212                             [use NUL (binary zero) as newline character]),
213              ac_pcre2_newline=nul)
214enable_newline="$ac_pcre2_newline"
215
216# Handle --enable-bsr-anycrlf
217AC_ARG_ENABLE(bsr-anycrlf,
218              AS_HELP_STRING([--enable-bsr-anycrlf],
219                             [\R matches only CR, LF, CRLF by default]),
220              , enable_bsr_anycrlf=no)
221
222# Handle --enable-never-backslash-C
223AC_ARG_ENABLE(never-backslash-C,
224              AS_HELP_STRING([--enable-never-backslash-C],
225                             [use of \C causes an error]),
226              , enable_never_backslash_C=no)
227
228# Handle --enable-ebcdic
229AC_ARG_ENABLE(ebcdic,
230              AS_HELP_STRING([--enable-ebcdic],
231                             [assume EBCDIC coding rather than ASCII; incompatible with --enable-utf; use only in (uncommon) EBCDIC environments; it implies --enable-rebuild-chartables]),
232              , enable_ebcdic=no)
233
234# Handle --enable-ebcdic-nl25
235AC_ARG_ENABLE(ebcdic-nl25,
236              AS_HELP_STRING([--enable-ebcdic-nl25],
237                             [set EBCDIC code for NL to 0x25 instead of 0x15; it implies --enable-ebcdic]),
238              , enable_ebcdic_nl25=no)
239
240# Handle --enable-pcre2grep-libz
241AC_ARG_ENABLE(pcre2grep-libz,
242              AS_HELP_STRING([--enable-pcre2grep-libz],
243                             [link pcre2grep with libz to handle .gz files]),
244              , enable_pcre2grep_libz=no)
245
246# Handle --enable-pcre2grep-libbz2
247AC_ARG_ENABLE(pcre2grep-libbz2,
248              AS_HELP_STRING([--enable-pcre2grep-libbz2],
249                             [link pcre2grep with libbz2 to handle .bz2 files]),
250              , enable_pcre2grep_libbz2=no)
251
252# Handle --with-pcre2grep-bufsize=N
253AC_ARG_WITH(pcre2grep-bufsize,
254              AS_HELP_STRING([--with-pcre2grep-bufsize=N],
255                             [pcre2grep initial buffer size (default=20480, minimum=8192)]),
256              , with_pcre2grep_bufsize=20480)
257
258# Handle --with-pcre2grep-max-bufsize=N
259AC_ARG_WITH(pcre2grep-max-bufsize,
260              AS_HELP_STRING([--with-pcre2grep-max-bufsize=N],
261                             [pcre2grep maximum buffer size (default=1048576, minimum=8192)]),
262              , with_pcre2grep_max_bufsize=1048576)
263
264# Handle --enable-pcre2test-libedit
265AC_ARG_ENABLE(pcre2test-libedit,
266              AS_HELP_STRING([--enable-pcre2test-libedit],
267                             [link pcre2test with libedit]),
268              , enable_pcre2test_libedit=no)
269
270# Handle --enable-pcre2test-libreadline
271AC_ARG_ENABLE(pcre2test-libreadline,
272              AS_HELP_STRING([--enable-pcre2test-libreadline],
273                             [link pcre2test with libreadline]),
274              , enable_pcre2test_libreadline=no)
275
276# Handle --with-link-size=N
277AC_ARG_WITH(link-size,
278            AS_HELP_STRING([--with-link-size=N],
279                           [internal link size (2, 3, or 4 allowed; default=2)]),
280            , with_link_size=2)
281
282# Handle --with-parens-nest-limit=N
283AC_ARG_WITH(parens-nest-limit,
284            AS_HELP_STRING([--with-parens-nest-limit=N],
285                           [nested parentheses limit (default=250)]),
286            , with_parens_nest_limit=250)
287
288# Handle --with-heap-limit
289AC_ARG_WITH(heap-limit,
290            AS_HELP_STRING([--with-heap-limit=N],
291                           [default limit on heap memory (kibibytes, default=20000000)]),
292            , with_heap_limit=20000000)
293
294# Handle --with-match-limit=N
295AC_ARG_WITH(match-limit,
296            AS_HELP_STRING([--with-match-limit=N],
297                           [default limit on internal looping (default=10000000)]),
298            , with_match_limit=10000000)
299
300# Handle --with-match-limit-depth=N
301# Recognize old synonym --with-match-limit-recursion
302#
303# Note: In config.h, the default is to define MATCH_LIMIT_DEPTH symbolically as
304# MATCH_LIMIT, which in turn is defined to be some numeric value (e.g.
305# 10000000). MATCH_LIMIT_DEPTH can otherwise be set to some different numeric
306# value (or even the same numeric value as MATCH_LIMIT, though no longer
307# defined in terms of the latter).
308#
309AC_ARG_WITH(match-limit-depth,
310            AS_HELP_STRING([--with-match-limit-depth=N],
311                           [default limit on match tree depth (default=MATCH_LIMIT)]),
312            , with_match_limit_depth=MATCH_LIMIT)
313
314AC_ARG_WITH(match-limit-recursion,,
315            , with_match_limit_recursion=UNSET)
316
317# Handle --enable-valgrind
318AC_ARG_ENABLE(valgrind,
319              AS_HELP_STRING([--enable-valgrind],
320                             [enable valgrind support]),
321              , enable_valgrind=no)
322
323# Enable code coverage reports using gcov
324AC_ARG_ENABLE(coverage,
325              AS_HELP_STRING([--enable-coverage],
326                             [enable code coverage reports using gcov]),
327              , enable_coverage=no)
328
329# Handle --enable-fuzz-support
330AC_ARG_ENABLE(fuzz_support,
331              AS_HELP_STRING([--enable-fuzz-support],
332                             [enable fuzzer support]),
333              , enable_fuzz_support=no)
334
335# Handle --disable-stack-for-recursion
336# This option became obsolete at release 10.30.
337AC_ARG_ENABLE(stack-for-recursion,,
338              , enable_stack_for_recursion=yes)
339
340# Original code
341# AC_ARG_ENABLE(stack-for-recursion,
342#               AS_HELP_STRING([--disable-stack-for-recursion],
343#                              [don't use stack recursion when matching]),
344#               , enable_stack_for_recursion=yes)
345
346# Set the default value for pcre2-8
347if test "x$enable_pcre2_8" = "xunset"
348then
349  enable_pcre2_8=yes
350fi
351
352# Set the default value for pcre2-16
353if test "x$enable_pcre2_16" = "xunset"
354then
355  enable_pcre2_16=no
356fi
357
358# Set the default value for pcre2-32
359if test "x$enable_pcre2_32" = "xunset"
360then
361  enable_pcre2_32=no
362fi
363
364# Make sure at least one library is selected
365if test "x$enable_pcre2_8$enable_pcre2_16$enable_pcre2_32" = "xnonono"
366then
367  AC_MSG_ERROR([At least one of the 8, 16 or 32 bit libraries must be enabled])
368fi
369
370# Unicode is enabled by default.
371if test "x$enable_unicode" = "xunset"
372then
373  enable_unicode=yes
374fi
375
376# Convert the newline identifier into the appropriate integer value. These must
377# agree with the PCRE2_NEWLINE_xxx values in pcre2.h.
378
379case "$enable_newline" in
380  cr)      ac_pcre2_newline_value=1 ;;
381  lf)      ac_pcre2_newline_value=2 ;;
382  crlf)    ac_pcre2_newline_value=3 ;;
383  any)     ac_pcre2_newline_value=4 ;;
384  anycrlf) ac_pcre2_newline_value=5 ;;
385  nul)     ac_pcre2_newline_value=6 ;;
386  *)
387  AC_MSG_ERROR([invalid argument \"$enable_newline\" to --enable-newline option])
388  ;;
389esac
390
391# --enable-ebcdic-nl25 implies --enable-ebcdic
392if test "x$enable_ebcdic_nl25" = "xyes"; then
393  enable_ebcdic=yes
394fi
395
396# Make sure that if enable_ebcdic is set, rebuild_chartables is also enabled.
397# Also check that UTF support is not requested, because PCRE2 cannot handle
398# EBCDIC and UTF in the same build. To do so it would need to use different
399# character constants depending on the mode. Also, EBCDIC cannot be used with
400# 16-bit and 32-bit libraries.
401#
402if test "x$enable_ebcdic" = "xyes"; then
403  enable_rebuild_chartables=yes
404  if test "x$enable_unicode" = "xyes"; then
405    AC_MSG_ERROR([support for EBCDIC and Unicode cannot be enabled at the same time])
406  fi
407  if test "x$enable_pcre2_16" = "xyes" -o "x$enable_pcre2_32" = "xyes"; then
408    AC_MSG_ERROR([EBCDIC support is available only for the 8-bit library])
409  fi
410fi
411
412# Check argument to --with-link-size
413case "$with_link_size" in
414  2|3|4) ;;
415  *)
416  AC_MSG_ERROR([invalid argument \"$with_link_size\" to --with-link-size option])
417  ;;
418esac
419
420AH_TOP([
421/* PCRE2 is written in Standard C, but there are a few non-standard things it
422can cope with, allowing it to run on SunOS4 and other "close to standard"
423systems.
424
425In environments that support the GNU autotools, config.h.in is converted into
426config.h by the "configure" script. In environments that use CMake,
427config-cmake.in is converted into config.h. If you are going to build PCRE2 "by
428hand" without using "configure" or CMake, you should copy the distributed
429config.h.generic to config.h, and edit the macro definitions to be the way you
430need them. You must then add -DHAVE_CONFIG_H to all of your compile commands,
431so that config.h is included at the start of every source.
432
433Alternatively, you can avoid editing by using -D on the compiler command line
434to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H,
435but if you do, default values will be taken from config.h for non-boolean
436macros that are not defined on the command line.
437
438Boolean macros such as HAVE_STDLIB_H and SUPPORT_PCRE2_8 should either be
439defined (conventionally to 1) for TRUE, and not defined at all for FALSE. All
440such macros are listed as a commented #undef in config.h.generic. Macros such
441as MATCH_LIMIT, whose actual value is relevant, have defaults defined, but are
442surrounded by #ifndef/#endif lines so that the value can be overridden by -D.
443
444PCRE2 uses memmove() if HAVE_MEMMOVE is defined; otherwise it uses bcopy() if
445HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make
446sure both macros are undefined; an emulation function will then be used. */])
447
448# Checks for header files.
449AC_HEADER_STDC
450AC_CHECK_HEADERS(limits.h sys/types.h sys/stat.h dirent.h)
451AC_CHECK_HEADERS([windows.h], [HAVE_WINDOWS_H=1])
452AC_CHECK_HEADERS([sys/wait.h], [HAVE_SYS_WAIT_H=1])
453
454AC_CHECK_HEADERS([stdint.h], [PCRE2_HAVE_STDINT_H=1], [PCRE2_HAVE_STDINT_H=0])
455AC_CHECK_HEADERS([inttypes.h], [PCRE2_HAVE_INTTYPES_H=1], [PCRE2_HAVE_INTTYPES_H=0])
456AC_SUBST([PCRE2_HAVE_STDINT_H])
457AC_SUBST([PCRE2_HAVE_INTTYPES_H])
458
459# Conditional compilation
460AM_CONDITIONAL(WITH_PCRE2_8, test "x$enable_pcre2_8" = "xyes")
461AM_CONDITIONAL(WITH_PCRE2_16, test "x$enable_pcre2_16" = "xyes")
462AM_CONDITIONAL(WITH_PCRE2_32, test "x$enable_pcre2_32" = "xyes")
463AM_CONDITIONAL(WITH_DEBUG, test "x$enable_debug" = "xyes")
464AM_CONDITIONAL(WITH_REBUILD_CHARTABLES, test "x$enable_rebuild_chartables" = "xyes")
465AM_CONDITIONAL(WITH_JIT, test "x$enable_jit" = "xyes")
466AM_CONDITIONAL(WITH_UNICODE, test "x$enable_unicode" = "xyes")
467AM_CONDITIONAL(WITH_VALGRIND, test "x$enable_valgrind" = "xyes")
468AM_CONDITIONAL(WITH_FUZZ_SUPPORT, test "x$enable_fuzz_support" = "xyes")
469
470if test "$enable_fuzz_support" = "yes" -a "$enable_pcre2_8" = "no"; then
471  echo "** ERROR: Fuzzer support requires the 8-bit library"
472  exit 1
473fi
474
475# Checks for typedefs, structures, and compiler characteristics.
476
477AC_C_CONST
478AC_TYPE_SIZE_T
479
480# Checks for library functions.
481
482AC_CHECK_FUNCS(bcopy memmove strerror mkostemp secure_getenv)
483
484# Check for the availability of libz (aka zlib)
485
486AC_CHECK_HEADERS([zlib.h], [HAVE_ZLIB_H=1])
487AC_CHECK_LIB([z], [gzopen], [HAVE_LIBZ=1])
488
489# Check for the availability of libbz2. Originally we just used AC_CHECK_LIB,
490# as for libz. However, this had the following problem, diagnosed and fixed by
491# a user:
492#
493#   - libbz2 uses the Pascal calling convention (WINAPI) for the functions
494#     under Win32.
495#   - The standard autoconf AC_CHECK_LIB fails to include "bzlib.h",
496#     therefore missing the function definition.
497#   - The compiler thus generates a "C" signature for the test function.
498#   - The linker fails to find the "C" function.
499#   - PCRE2 fails to configure if asked to do so against libbz2.
500#
501# Solution:
502#
503#   - Replace the AC_CHECK_LIB test with a custom test.
504
505AC_CHECK_HEADERS([bzlib.h], [HAVE_BZLIB_H=1])
506# Original test
507# AC_CHECK_LIB([bz2], [BZ2_bzopen], [HAVE_LIBBZ2=1])
508#
509# Custom test follows
510
511AC_MSG_CHECKING([for libbz2])
512OLD_LIBS="$LIBS"
513LIBS="$LIBS -lbz2"
514AC_LINK_IFELSE([AC_LANG_PROGRAM([[
515#ifdef HAVE_BZLIB_H
516#include <bzlib.h>
517#endif]],
518[[return (int)BZ2_bzopen("conftest", "rb");]])],
519[AC_MSG_RESULT([yes]);HAVE_LIBBZ2=1; break;],
520AC_MSG_RESULT([no]))
521LIBS="$OLD_LIBS"
522
523# Check for the availabiity of libreadline
524
525if test "$enable_pcre2test_libreadline" = "yes"; then
526 AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_H=1])
527 AC_CHECK_HEADERS([readline/history.h], [HAVE_HISTORY_H=1])
528 AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lreadline"],
529   [unset ac_cv_lib_readline_readline;
530    AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-ltinfo"],
531     [unset ac_cv_lib_readline_readline;
532      AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lcurses"],
533       [unset ac_cv_lib_readline_readline;
534        AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lncurses"],
535         [unset ac_cv_lib_readline_readline;
536	  AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lncursesw"],
537           [unset ac_cv_lib_readline_readline;
538	    AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-ltermcap"],
539             [LIBREADLINE=""],
540             [-ltermcap])],
541           [-lncursesw])],
542         [-lncurses])],
543       [-lcurses])],
544     [-ltinfo])])
545 AC_SUBST(LIBREADLINE)
546 if test -n "$LIBREADLINE"; then
547   if test "$LIBREADLINE" != "-lreadline"; then
548     echo "-lreadline needs $LIBREADLINE"
549     LIBREADLINE="-lreadline $LIBREADLINE"
550   fi
551 fi
552fi
553
554
555# Check for the availability of libedit. Different distributions put its
556# headers in different places. Try to cover the most common ones.
557
558if test "$enable_pcre2test_libedit" = "yes"; then
559  AC_CHECK_HEADERS([editline/readline.h], [HAVE_EDITLINE_READLINE_H=1],
560    [AC_CHECK_HEADERS([edit/readline/readline.h], [HAVE_READLINE_READLINE_H=1],
561      [AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_READLINE_H=1])])])
562  AC_CHECK_LIB([edit], [readline], [LIBEDIT="-ledit"])
563fi
564
565PCRE2_STATIC_CFLAG=""
566if test "x$enable_shared" = "xno" ; then
567  AC_DEFINE([PCRE2_STATIC], [1], [
568    Define to any value if linking statically (TODO: make nice with Libtool)])
569  PCRE2_STATIC_CFLAG="-DPCRE2_STATIC"
570fi
571AC_SUBST(PCRE2_STATIC_CFLAG)
572
573# Here is where PCRE2-specific defines are handled
574
575if test "$enable_pcre2_8" = "yes"; then
576  AC_DEFINE([SUPPORT_PCRE2_8], [], [
577    Define to any value to enable the 8 bit PCRE2 library.])
578fi
579
580if test "$enable_pcre2_16" = "yes"; then
581  AC_DEFINE([SUPPORT_PCRE2_16], [], [
582    Define to any value to enable the 16 bit PCRE2 library.])
583fi
584
585if test "$enable_pcre2_32" = "yes"; then
586  AC_DEFINE([SUPPORT_PCRE2_32], [], [
587    Define to any value to enable the 32 bit PCRE2 library.])
588fi
589
590if test "$enable_debug" = "yes"; then
591  AC_DEFINE([PCRE2_DEBUG], [], [
592    Define to any value to include debugging code.])
593fi
594
595# Unless running under Windows, JIT support requires pthreads.
596
597if test "$enable_jit" = "yes"; then
598  if test "$HAVE_WINDOWS_H" != "1"; then
599    AX_PTHREAD([], [AC_MSG_ERROR([JIT support requires pthreads])])
600    CC="$PTHREAD_CC"
601    CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
602    LIBS="$PTHREAD_LIBS $LIBS"
603  fi
604  AC_DEFINE([SUPPORT_JIT], [], [
605    Define to any value to enable support for Just-In-Time compiling.])
606else
607  enable_pcre2grep_jit="no"
608fi
609
610if test "$enable_jit_sealloc" = "yes"; then
611  AC_DEFINE([SLJIT_PROT_EXECUTABLE_ALLOCATOR], [1], [
612    Define to any non-zero number to enable support for SELinux
613    compatible executable memory allocator in JIT. Note that this
614    will have no effect unless SUPPORT_JIT is also defined.])
615fi
616
617if test "$enable_pcre2grep_jit" = "yes"; then
618  AC_DEFINE([SUPPORT_PCRE2GREP_JIT], [], [
619    Define to any value to enable JIT support in pcre2grep. Note that this will
620    have no effect unless SUPPORT_JIT is also defined.])
621fi
622
623if test "$enable_pcre2grep_callout" = "yes"; then
624  if test "$HAVE_WINDOWS_H" != "1"; then
625    if test "$HAVE_SYS_WAIT_H" != "1"; then
626      AC_MSG_ERROR([Callout script support needs sys/wait.h.])
627    fi
628  fi
629  AC_DEFINE([SUPPORT_PCRE2GREP_CALLOUT], [], [
630    Define to any value to enable callout script support in pcre2grep.])
631fi
632
633if test "$enable_unicode" = "yes"; then
634  AC_DEFINE([SUPPORT_UNICODE], [], [
635    Define to any value to enable support for Unicode and UTF encoding.
636    This will work even in an EBCDIC environment, but it is incompatible
637    with the EBCDIC macro. That is, PCRE2 can support *either* EBCDIC
638    code *or* ASCII/Unicode, but not both at once.])
639fi
640
641if test "$enable_pcre2grep_libz" = "yes"; then
642  AC_DEFINE([SUPPORT_LIBZ], [], [
643    Define to any value to allow pcre2grep to be linked with libz, so that it is
644    able to handle .gz files.])
645fi
646
647if test "$enable_pcre2grep_libbz2" = "yes"; then
648  AC_DEFINE([SUPPORT_LIBBZ2], [], [
649    Define to any value to allow pcre2grep to be linked with libbz2, so that it
650    is able to handle .bz2 files.])
651fi
652
653if test $with_pcre2grep_bufsize -lt 8192 ; then
654  AC_MSG_WARN([$with_pcre2grep_bufsize is too small for --with-pcre2grep-bufsize; using 8192])
655  with_pcre2grep_bufsize="8192"
656else
657  if test $? -gt 1 ; then
658  AC_MSG_ERROR([Bad value for --with-pcre2grep-bufsize])
659  fi
660fi
661
662if test $with_pcre2grep_max_bufsize -lt $with_pcre2grep_bufsize ; then
663  with_pcre2grep_max_bufsize="$with_pcre2grep_bufsize"
664else
665  if test $? -gt 1 ; then
666  AC_MSG_ERROR([Bad value for --with-pcre2grep-max-bufsize])
667  fi
668fi
669
670AC_DEFINE_UNQUOTED([PCRE2GREP_BUFSIZE], [$with_pcre2grep_bufsize], [
671  The value of PCRE2GREP_BUFSIZE is the starting size of the buffer used by
672  pcre2grep to hold parts of the file it is searching. The buffer will be
673  expanded up to PCRE2GREP_MAX_BUFSIZE if necessary, for files containing very
674  long lines. The actual amount of memory used by pcre2grep is three times this
675  number, because it allows for the buffering of "before" and "after" lines.])
676
677AC_DEFINE_UNQUOTED([PCRE2GREP_MAX_BUFSIZE], [$with_pcre2grep_max_bufsize], [
678  The value of PCRE2GREP_MAX_BUFSIZE specifies the maximum size of the buffer
679  used by pcre2grep to hold parts of the file it is searching. The actual
680  amount of memory used by pcre2grep is three times this number, because it
681  allows for the buffering of "before" and "after" lines.])
682
683if test "$enable_pcre2test_libedit" = "yes"; then
684  AC_DEFINE([SUPPORT_LIBEDIT], [], [
685    Define to any value to allow pcre2test to be linked with libedit.])
686  LIBREADLINE="$LIBEDIT"
687elif test "$enable_pcre2test_libreadline" = "yes"; then
688  AC_DEFINE([SUPPORT_LIBREADLINE], [], [
689    Define to any value to allow pcre2test to be linked with libreadline.])
690fi
691
692AC_DEFINE_UNQUOTED([NEWLINE_DEFAULT], [$ac_pcre2_newline_value], [
693  The value of NEWLINE_DEFAULT determines the default newline character
694  sequence. PCRE2 client programs can override this by selecting other values
695  at run time. The valid values are 1 (CR), 2 (LF), 3 (CRLF), 4 (ANY),
696  5 (ANYCRLF), and 6 (NUL).])
697
698if test "$enable_bsr_anycrlf" = "yes"; then
699  AC_DEFINE([BSR_ANYCRLF], [], [
700    By default, the \R escape sequence matches any Unicode line ending
701    character or sequence of characters. If BSR_ANYCRLF is defined (to any
702    value), this is changed so that backslash-R matches only CR, LF, or CRLF.
703    The build-time default can be overridden by the user of PCRE2 at runtime.])
704fi
705
706if test "$enable_never_backslash_C" = "yes"; then
707  AC_DEFINE([NEVER_BACKSLASH_C], [], [
708    Defining NEVER_BACKSLASH_C locks out the use of \C in all patterns.])
709fi
710
711AC_DEFINE_UNQUOTED([LINK_SIZE], [$with_link_size], [
712  The value of LINK_SIZE determines the number of bytes used to store
713  links as offsets within the compiled regex. The default is 2, which
714  allows for compiled patterns up to 65535 code units long. This covers the
715  vast majority of cases. However, PCRE2 can also be compiled to use 3 or 4
716  bytes instead. This allows for longer patterns in extreme cases.])
717
718AC_DEFINE_UNQUOTED([PARENS_NEST_LIMIT], [$with_parens_nest_limit], [
719  The value of PARENS_NEST_LIMIT specifies the maximum depth of nested
720  parentheses (of any kind) in a pattern. This limits the amount of system
721  stack that is used while compiling a pattern.])
722
723AC_DEFINE_UNQUOTED([MATCH_LIMIT], [$with_match_limit], [
724  The value of MATCH_LIMIT determines the default number of times the
725  pcre2_match() function can record a backtrack position during a single
726  matching attempt. The value is also used to limit a loop counter in
727  pcre2_dfa_match(). There is a runtime interface for setting a different
728  limit. The limit exists in order to catch runaway regular expressions that
729  take for ever to determine that they do not match. The default is set very
730  large so that it does not accidentally catch legitimate cases.])
731
732# --with-match-limit-recursion is an obsolete synonym for --with-match-limit-depth
733
734if test "$with_match_limit_recursion" != "UNSET"; then
735cat <<EOF
736
737WARNING: --with-match-limit-recursion is an obsolete option. Please use
738  --with-match-limit-depth in future. If both are set, --with-match-limit-depth
739  will be used. See also --with-heap-limit.
740
741EOF
742if test "$with_match_limit_depth" = "MATCH_LIMIT"; then
743  with_match_limit_depth=$with_match_limit_recursion
744fi
745fi
746
747AC_DEFINE_UNQUOTED([MATCH_LIMIT_DEPTH], [$with_match_limit_depth], [
748  The above limit applies to all backtracks, whether or not they are nested. In
749  some environments it is desirable to limit the nesting of backtracking (that
750  is, the depth of tree that is searched) more strictly, in order to restrict
751  the maximum amount of heap memory that is used. The value of
752  MATCH_LIMIT_DEPTH provides this facility. To have any useful effect, it must
753  be less than the value of MATCH_LIMIT. The default is to use the same value
754  as MATCH_LIMIT. There is a runtime method for setting a different limit. In
755  the case of pcre2_dfa_match(), this limit controls the depth of the internal
756  nested function calls that are used for pattern recursions, lookarounds, and
757  atomic groups.])
758
759AC_DEFINE_UNQUOTED([HEAP_LIMIT], [$with_heap_limit], [
760  This limits the amount of memory that may be used while matching
761  a pattern. It applies to both pcre2_match() and pcre2_dfa_match(). It does
762  not apply to JIT matching. The value is in kibibytes (units of 1024 bytes).])
763
764AC_DEFINE([MAX_NAME_SIZE], [32], [
765  This limit is parameterized just in case anybody ever wants to
766  change it. Care must be taken if it is increased, because it guards
767  against integer overflow caused by enormously large patterns.])
768
769AC_DEFINE([MAX_NAME_COUNT], [10000], [
770  This limit is parameterized just in case anybody ever wants to
771  change it. Care must be taken if it is increased, because it guards
772  against integer overflow caused by enormously large patterns.])
773
774AH_VERBATIM([PCRE2_EXP_DEFN], [
775/* If you are compiling for a system other than a Unix-like system or
776   Win32, and it needs some magic to be inserted before the definition
777   of a function that is exported by the library, define this macro to
778   contain the relevant magic. If you do not define this macro, a suitable
779    __declspec value is used for Windows systems; in other environments
780   "extern" is used for a C compiler and "extern C" for a C++ compiler.
781   This macro apears at the start of every exported function that is part
782   of the external API. It does not appear on functions that are "external"
783   in the C sense, but which are internal to the library. */
784#undef PCRE2_EXP_DEFN])
785
786if test "$enable_ebcdic" = "yes"; then
787  AC_DEFINE_UNQUOTED([EBCDIC], [], [
788    If you are compiling for a system that uses EBCDIC instead of ASCII
789    character codes, define this macro to any value. When EBCDIC is set, PCRE2
790    assumes that all input strings are in EBCDIC. If you do not define this
791    macro, PCRE2 will assume input strings are ASCII or UTF-8/16/32 Unicode. It
792    is not possible to build a version of PCRE2 that supports both EBCDIC and
793    UTF-8/16/32.])
794fi
795
796if test "$enable_ebcdic_nl25" = "yes"; then
797  AC_DEFINE_UNQUOTED([EBCDIC_NL25], [], [
798    In an EBCDIC environment, define this macro to any value to arrange for
799    the NL character to be 0x25 instead of the default 0x15. NL plays the role
800    that LF does in an ASCII/Unicode environment.])
801fi
802
803if test "$enable_valgrind" = "yes"; then
804  AC_DEFINE_UNQUOTED([SUPPORT_VALGRIND], [], [
805     Define to any value for valgrind support to find invalid memory reads.])
806fi
807
808# Platform specific issues
809NO_UNDEFINED=
810EXPORT_ALL_SYMBOLS=
811case $host_os in
812  cygwin* | mingw* )
813    if test X"$enable_shared" = Xyes; then
814      NO_UNDEFINED="-no-undefined"
815      EXPORT_ALL_SYMBOLS="-Wl,--export-all-symbols"
816    fi
817    ;;
818esac
819
820# The extra LDFLAGS for each particular library. The libpcre2*_version values
821# are m4 variables, assigned above.
822
823EXTRA_LIBPCRE2_8_LDFLAGS="$EXTRA_LIBPCRE2_8_LDFLAGS \
824  $NO_UNDEFINED -version-info libpcre2_8_version"
825
826EXTRA_LIBPCRE2_16_LDFLAGS="$EXTRA_LIBPCRE2_16_LDFLAGS \
827  $NO_UNDEFINED -version-info libpcre2_16_version"
828
829EXTRA_LIBPCRE2_32_LDFLAGS="$EXTRA_LIBPCRE2_32_LDFLAGS \
830  $NO_UNDEFINED -version-info libpcre2_32_version"
831
832EXTRA_LIBPCRE2_POSIX_LDFLAGS="$EXTRA_LIBPCRE2_POSIX_LDFLAGS \
833  $NO_UNDEFINED -version-info libpcre2_posix_version"
834
835AC_SUBST(EXTRA_LIBPCRE2_8_LDFLAGS)
836AC_SUBST(EXTRA_LIBPCRE2_16_LDFLAGS)
837AC_SUBST(EXTRA_LIBPCRE2_32_LDFLAGS)
838AC_SUBST(EXTRA_LIBPCRE2_POSIX_LDFLAGS)
839
840# When we run 'make distcheck', use these arguments. Turning off compiler
841# optimization makes it run faster.
842DISTCHECK_CONFIGURE_FLAGS="CFLAGS='' CXXFLAGS='' --enable-pcre2-16 --enable-pcre2-32 --enable-jit"
843AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
844
845# Check that, if --enable-pcre2grep-libz or --enable-pcre2grep-libbz2 is
846# specified, the relevant library is available.
847
848if test "$enable_pcre2grep_libz" = "yes"; then
849  if test "$HAVE_ZLIB_H" != "1"; then
850    echo "** Cannot --enable-pcre2grep-libz because zlib.h was not found"
851    exit 1
852  fi
853  if test "$HAVE_LIBZ" != "1"; then
854    echo "** Cannot --enable-pcre2grep-libz because libz was not found"
855    exit 1
856  fi
857  LIBZ="-lz"
858fi
859AC_SUBST(LIBZ)
860
861if test "$enable_pcre2grep_libbz2" = "yes"; then
862  if test "$HAVE_BZLIB_H" != "1"; then
863    echo "** Cannot --enable-pcre2grep-libbz2 because bzlib.h was not found"
864    exit 1
865  fi
866  if test "$HAVE_LIBBZ2" != "1"; then
867    echo "** Cannot --enable-pcre2grep-libbz2 because libbz2 was not found"
868    exit 1
869  fi
870  LIBBZ2="-lbz2"
871fi
872AC_SUBST(LIBBZ2)
873
874# Similarly for --enable-pcre2test-readline
875
876if test "$enable_pcre2test_libedit" = "yes"; then
877  if test "$enable_pcre2test_libreadline" = "yes"; then
878    echo "** Cannot use both --enable-pcre2test-libedit and --enable-pcre2test-readline"
879    exit 1
880  fi
881  if test "$HAVE_EDITLINE_READLINE_H" != "1" -a \
882          "$HAVE_READLINE_READLINE_H" != "1"; then
883    echo "** Cannot --enable-pcre2test-libedit because neither editline/readline.h"
884    echo "** nor readline/readline.h was found."
885    exit 1
886  fi
887  if test -z "$LIBEDIT"; then
888    echo "** Cannot --enable-pcre2test-libedit because libedit library was not found."
889    exit 1
890  fi
891fi
892
893if test "$enable_pcre2test_libreadline" = "yes"; then
894  if test "$HAVE_READLINE_H" != "1"; then
895    echo "** Cannot --enable-pcre2test-readline because readline/readline.h was not found."
896    exit 1
897  fi
898  if test "$HAVE_HISTORY_H" != "1"; then
899    echo "** Cannot --enable-pcre2test-readline because readline/history.h was not found."
900    exit 1
901  fi
902  if test -z "$LIBREADLINE"; then
903    echo "** Cannot --enable-pcre2test-readline because readline library was not found."
904    exit 1
905  fi
906fi
907
908# Handle valgrind support
909
910if test "$enable_valgrind" = "yes"; then
911  m4_ifdef([PKG_CHECK_MODULES],
912           [PKG_CHECK_MODULES([VALGRIND],[valgrind])],
913           [AC_MSG_ERROR([pkg-config not supported])])
914fi
915
916# Handle code coverage reporting support
917if test "$enable_coverage" = "yes"; then
918  if test "x$GCC" != "xyes"; then
919    AC_MSG_ERROR([Code coverage reports can only be generated when using GCC])
920  fi
921
922  # ccache is incompatible with gcov
923  AC_PATH_PROG([SHTOOL],[shtool],[false])
924  case `$SHTOOL path $CC` in
925    *ccache*) cc_ccache=yes;;
926    *) cc_ccache=no;;
927  esac
928
929  if test "$cc_ccache" = "yes"; then
930    if test -z "$CCACHE_DISABLE" -o "$CCACHE_DISABLE" != "1"; then
931      AC_MSG_ERROR([must export CCACHE_DISABLE=1 to disable ccache for code coverage])
932    fi
933  fi
934
935  AC_ARG_VAR([LCOV],[the ltp lcov program])
936  AC_PATH_PROG([LCOV],[lcov],[false])
937  if test "x$LCOV" = "xfalse"; then
938    AC_MSG_ERROR([lcov not found])
939  fi
940
941  AC_ARG_VAR([GENHTML],[the ltp genhtml program])
942  AC_PATH_PROG([GENHTML],[genhtml],[false])
943  if test "x$GENHTML" = "xfalse"; then
944    AC_MSG_ERROR([genhtml not found])
945  fi
946
947  # Set flags needed for gcov
948  GCOV_CFLAGS="-O0 -ggdb3 -fprofile-arcs -ftest-coverage"
949  GCOV_CXXFLAGS="-O0 -ggdb3 -fprofile-arcs -ftest-coverage"
950  GCOV_LIBS="-lgcov"
951  AC_SUBST([GCOV_CFLAGS])
952  AC_SUBST([GCOV_CXXFLAGS])
953  AC_SUBST([GCOV_LIBS])
954fi # enable_coverage
955
956AM_CONDITIONAL([WITH_GCOV],[test "x$enable_coverage" = "xyes"])
957
958# Produce these files, in addition to config.h.
959AC_CONFIG_FILES(
960	Makefile
961	libpcre2-8.pc
962	libpcre2-16.pc
963	libpcre2-32.pc
964	libpcre2-posix.pc
965	pcre2-config
966	src/pcre2.h
967)
968
969# Make the generated script files executable.
970AC_CONFIG_COMMANDS([script-chmod], [chmod a+x pcre2-config])
971
972# Make sure that pcre2_chartables.c is removed in case the method for
973# creating it was changed by reconfiguration.
974AC_CONFIG_COMMANDS([delete-old-chartables], [rm -f pcre2_chartables.c])
975
976AC_OUTPUT
977
978# --disable-stack-for-recursion is obsolete and has no effect.
979
980if test "$enable_stack_for_recursion" = "no"; then
981cat <<EOF
982
983WARNING: --disable-stack-for-recursion is obsolete and has no effect.
984EOF
985fi
986
987# Print out a nice little message after configure is run displaying the
988# chosen options.
989
990ebcdic_nl_code=n/a
991if test "$enable_ebcdic_nl25" = "yes"; then
992  ebcdic_nl_code=0x25
993elif test "$enable_ebcdic" = "yes"; then
994  ebcdic_nl_code=0x15
995fi
996
997cat <<EOF
998
999$PACKAGE-$VERSION configuration summary:
1000
1001    Install prefix ..................... : ${prefix}
1002    C preprocessor ..................... : ${CPP}
1003    C compiler ......................... : ${CC}
1004    Linker ............................. : ${LD}
1005    C preprocessor flags ............... : ${CPPFLAGS}
1006    C compiler flags ................... : ${CFLAGS} ${VISIBILITY_CFLAGS}
1007    Linker flags ....................... : ${LDFLAGS}
1008    Extra libraries .................... : ${LIBS}
1009
1010    Build 8-bit pcre2 library .......... : ${enable_pcre2_8}
1011    Build 16-bit pcre2 library ......... : ${enable_pcre2_16}
1012    Build 32-bit pcre2 library ......... : ${enable_pcre2_32}
1013    Include debugging code ............. : ${enable_debug}
1014    Enable JIT compiling support ....... : ${enable_jit}
1015    Use SELinux allocator in JIT ....... : ${enable_jit_sealloc}
1016    Enable Unicode support ............. : ${enable_unicode}
1017    Newline char/sequence .............. : ${enable_newline}
1018    \R matches only ANYCRLF ............ : ${enable_bsr_anycrlf}
1019    \C is disabled ..................... : ${enable_never_backslash_C}
1020    EBCDIC coding ...................... : ${enable_ebcdic}
1021    EBCDIC code for NL ................. : ${ebcdic_nl_code}
1022    Rebuild char tables ................ : ${enable_rebuild_chartables}
1023    Internal link size ................. : ${with_link_size}
1024    Nested parentheses limit ........... : ${with_parens_nest_limit}
1025    Heap limit ......................... : ${with_heap_limit} kibibytes
1026    Match limit ........................ : ${with_match_limit}
1027    Match depth limit .................. : ${with_match_limit_depth}
1028    Build shared libs .................. : ${enable_shared}
1029    Build static libs .................. : ${enable_static}
1030    Use JIT in pcre2grep ............... : ${enable_pcre2grep_jit}
1031    Enable callouts in pcre2grep ....... : ${enable_pcre2grep_callout}
1032    Initial buffer size for pcre2grep .. : ${with_pcre2grep_bufsize}
1033    Maximum buffer size for pcre2grep .. : ${with_pcre2grep_max_bufsize}
1034    Link pcre2grep with libz ........... : ${enable_pcre2grep_libz}
1035    Link pcre2grep with libbz2 ......... : ${enable_pcre2grep_libbz2}
1036    Link pcre2test with libedit ........ : ${enable_pcre2test_libedit}
1037    Link pcre2test with libreadline .... : ${enable_pcre2test_libreadline}
1038    Valgrind support ................... : ${enable_valgrind}
1039    Code coverage ...................... : ${enable_coverage}
1040    Fuzzer support ..................... : ${enable_fuzz_support}
1041
1042EOF
1043
1044dnl end configure.ac
1045