1PCRE2BUILD(3)              Library Functions Manual              PCRE2BUILD(3)
2
3
4

NAME

6       PCRE2 - Perl-compatible regular expressions (revised API)
7

BUILDING PCRE2

9
10       PCRE2  is distributed with a configure script that can be used to build
11       the library in Unix-like environments using the applications  known  as
12       Autotools. Also in the distribution are files to support building using
13       CMake instead of configure. The text file README contains  general  in‐
14       formation  about building with Autotools (some of which is repeated be‐
15       low), and also has some comments about building  on  various  operating
16       systems.  There  is a lot more information about building PCRE2 without
17       using Autotools (including information about using CMake  and  building
18       "by  hand")  in  the  text file called NON-AUTOTOOLS-BUILD.  You should
19       consult this file as well as the README file if you are building  in  a
20       non-Unix-like environment.
21

PCRE2 BUILD-TIME OPTIONS

23
24       The rest of this document describes the optional features of PCRE2 that
25       can be selected when the library is compiled. It  assumes  use  of  the
26       configure  script,  where  the  optional features are selected or dese‐
27       lected by providing options to configure before running the  make  com‐
28       mand.  However,  the same options can be selected in both Unix-like and
29       non-Unix-like environments if you are using CMake instead of  configure
30       to build PCRE2.
31
32       If  you  are not using Autotools or CMake, option selection can be done
33       by editing the config.h file, or by passing parameter settings  to  the
34       compiler, as described in NON-AUTOTOOLS-BUILD.
35
36       The complete list of options for configure (which includes the standard
37       ones such as the selection of the installation directory)  can  be  ob‐
38       tained by running
39
40         ./configure --help
41
42       The  following  sections include descriptions of "on/off" options whose
43       names begin with --enable or --disable. Because of the way that config‐
44       ure  works, --enable and --disable always come in pairs, so the comple‐
45       mentary option always exists as well, but as it specifies the  default,
46       it is not described.  Options that specify values have names that start
47       with --with. At the end of a configure run, a summary of the configura‐
48       tion is output.
49

BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES

51
52       By  default, a library called libpcre2-8 is built, containing functions
53       that take string arguments contained in arrays  of  bytes,  interpreted
54       either  as single-byte characters, or UTF-8 strings. You can also build
55       two other libraries, called libpcre2-16 and libpcre2-32, which  process
56       strings  that  are contained in arrays of 16-bit and 32-bit code units,
57       respectively. These can be interpreted either as single-unit characters
58       or  UTF-16/UTF-32 strings. To build these additional libraries, add one
59       or both of the following to the configure command:
60
61         --enable-pcre2-16
62         --enable-pcre2-32
63
64       If you do not want the 8-bit library, add
65
66         --disable-pcre2-8
67
68       as well. At least one of the three libraries must be built.  Note  that
69       the  POSIX wrapper is for the 8-bit library only, and that pcre2grep is
70       an 8-bit program. Neither of these are built if  you  select  only  the
71       16-bit or 32-bit libraries.
72

BUILDING SHARED AND STATIC LIBRARIES

74
75       The  Autotools PCRE2 building process uses libtool to build both shared
76       and static libraries by default. You can suppress an  unwanted  library
77       by adding one of
78
79         --disable-shared
80         --disable-static
81
82       to the configure command.
83

UNICODE AND UTF SUPPORT

85
86       By  default,  PCRE2 is built with support for Unicode and UTF character
87       strings.  To build it without Unicode support, add
88
89         --disable-unicode
90
91       to the configure command. This setting applies to all three  libraries.
92       It  is  not  possible to build one library with Unicode support and an‐
93       other without in the same configuration.
94
95       Of itself, Unicode support does not make PCRE2 treat strings as  UTF-8,
96       UTF-16 or UTF-32. To do that, applications that use the library can set
97       the PCRE2_UTF option when they call pcre2_compile() to compile  a  pat‐
98       tern.   Alternatively,  patterns  may be started with (*UTF) unless the
99       application has locked this out by setting PCRE2_NEVER_UTF.
100
101       UTF support allows the libraries to process character code points up to
102       0x10ffff  in  the  strings that they handle. Unicode support also gives
103       access to the Unicode properties of characters, using  pattern  escapes
104       such as \P, \p, and \X. Only the general category properties such as Lu
105       and Nd, script names, and some bi-directional properties are supported.
106       Details are given in the pcre2pattern documentation.
107
108       Pattern escapes such as \d and \w do not by default make use of Unicode
109       properties. The application can request that they  do  by  setting  the
110       PCRE2_UCP  option.  Unless  the  application has set PCRE2_NEVER_UCP, a
111       pattern may also request this by starting with (*UCP).
112

DISABLING THE USE OF \C

114
115       The \C escape sequence, which matches a single code unit, even in a UTF
116       mode,  can  cause unpredictable behaviour because it may leave the cur‐
117       rent matching point in the middle of a multi-code-unit  character.  The
118       application  can lock it out by setting the PCRE2_NEVER_BACKSLASH_C op‐
119       tion when calling pcre2_compile(). There is also a build-time option
120
121         --enable-never-backslash-C
122
123       (note the upper case C) which locks out the use of \C entirely.
124

JUST-IN-TIME COMPILER SUPPORT

126
127       Just-in-time (JIT) compiler support is included in the build by  speci‐
128       fying
129
130         --enable-jit
131
132       This  support  is available only for certain hardware architectures. If
133       this option is set for an unsupported architecture,  a  building  error
134       occurs.  If in doubt, use
135
136         --enable-jit=auto
137
138       which  enables  JIT  only if the current hardware is supported. You can
139       check if JIT is enabled in the configuration summary that is output  at
140       the  end  of a configure run. If you are enabling JIT under SELinux you
141       may also want to add
142
143         --enable-jit-sealloc
144
145       which enables the use of an execmem allocator in JIT that is compatible
146       with  SELinux.  This  has  no  effect  if  JIT  is not enabled. See the
147       pcre2jit documentation for a discussion of JIT usage. When JIT  support
148       is enabled, pcre2grep automatically makes use of it, unless you add
149
150         --disable-pcre2grep-jit
151
152       to the configure command.
153

NEWLINE RECOGNITION

155
156       By  default, PCRE2 interprets the linefeed (LF) character as indicating
157       the end of a line. This is the normal newline  character  on  Unix-like
158       systems.  You can compile PCRE2 to use carriage return (CR) instead, by
159       adding
160
161         --enable-newline-is-cr
162
163       to the configure command. There is also an  --enable-newline-is-lf  op‐
164       tion, which explicitly specifies linefeed as the newline character.
165
166       Alternatively, you can specify that line endings are to be indicated by
167       the two-character sequence CRLF (CR immediately followed by LF). If you
168       want this, add
169
170         --enable-newline-is-crlf
171
172       to the configure command. There is a fourth option, specified by
173
174         --enable-newline-is-anycrlf
175
176       which  causes  PCRE2 to recognize any of the three sequences CR, LF, or
177       CRLF as indicating a line ending. A fifth option, specified by
178
179         --enable-newline-is-any
180
181       causes PCRE2 to recognize any Unicode  newline  sequence.  The  Unicode
182       newline sequences are the three just mentioned, plus the single charac‐
183       ters VT (vertical tab, U+000B), FF (form feed, U+000C), NEL (next line,
184       U+0085),  LS  (line  separator,  U+2028),  and PS (paragraph separator,
185       U+2029). The final option is
186
187         --enable-newline-is-nul
188
189       which causes NUL (binary zero) to be set  as  the  default  line-ending
190       character.
191
192       Whatever default line ending convention is selected when PCRE2 is built
193       can be overridden by applications that use the library. At  build  time
194       it is recommended to use the standard for your operating system.
195

WHAT \R MATCHES

197
198       By  default,  the  sequence \R in a pattern matches any Unicode newline
199       sequence, independently of what has been selected as  the  line  ending
200       sequence. If you specify
201
202         --enable-bsr-anycrlf
203
204       the  default  is changed so that \R matches only CR, LF, or CRLF. What‐
205       ever is selected when PCRE2 is built can be overridden by  applications
206       that use the library.
207

HANDLING VERY LARGE PATTERNS

209
210       Within  a  compiled  pattern,  offset values are used to point from one
211       part to another (for example, from an opening parenthesis to an  alter‐
212       nation  metacharacter).  By default, in the 8-bit and 16-bit libraries,
213       two-byte values are used for these offsets, leading to a  maximum  size
214       for a compiled pattern of around 64 thousand code units. This is suffi‐
215       cient to handle all but the most gigantic patterns. Nevertheless,  some
216       people do want to process truly enormous patterns, so it is possible to
217       compile PCRE2 to use three-byte or four-byte offsets by adding  a  set‐
218       ting such as
219
220         --with-link-size=3
221
222       to  the  configure command. The value given must be 2, 3, or 4. For the
223       16-bit library, a value of 3 is rounded up to 4.  In  these  libraries,
224       using  longer  offsets slows down the operation of PCRE2 because it has
225       to load additional data when handling them. For the 32-bit library  the
226       value  is  always 4 and cannot be overridden; the value of --with-link-
227       size is ignored.
228

LIMITING PCRE2 RESOURCE USAGE

230
231       The pcre2_match() function increments a counter each time it goes round
232       its  main  loop. Putting a limit on this counter controls the amount of
233       computing resource used by a single call to  pcre2_match().  The  limit
234       can be changed at run time, as described in the pcre2api documentation.
235       The default is 10 million, but this can be changed by adding a  setting
236       such as
237
238         --with-match-limit=500000
239
240       to   the   configure   command.   This  setting  also  applies  to  the
241       pcre2_dfa_match() matching function, and to JIT  matching  (though  the
242       counting is done differently).
243
244       The  pcre2_match() function starts out using a 20KiB vector on the sys‐
245       tem stack to record backtracking points. The more  nested  backtracking
246       points there are (that is, the deeper the search tree), the more memory
247       is needed. If the initial vector is not large enough,  heap  memory  is
248       used,  up to a certain limit, which is specified in kibibytes (units of
249       1024 bytes). The limit can be changed at run time, as described in  the
250       pcre2api  documentation.  The default limit (in effect unlimited) is 20
251       million. You can change this by a setting such as
252
253         --with-heap-limit=500
254
255       which limits the amount of heap to 500 KiB. This limit applies only  to
256       interpretive matching in pcre2_match() and pcre2_dfa_match(), which may
257       also use the heap for internal workspace  when  processing  complicated
258       patterns.  This limit does not apply when JIT (which has its own memory
259       arrangements) is used.
260
261       You can also explicitly limit the depth of nested backtracking  in  the
262       pcre2_match() interpreter. This limit defaults to the value that is set
263       for --with-match-limit. You can set a lower default  limit  by  adding,
264       for example,
265
266         --with-match-limit-depth=10000
267
268       to  the  configure  command.  This value can be overridden at run time.
269       This depth limit indirectly limits the amount of heap  memory  that  is
270       used,  but because the size of each backtracking "frame" depends on the
271       number of capturing parentheses in a pattern, the amount of  heap  that
272       is  used  before  the  limit is reached varies from pattern to pattern.
273       This limit was more useful in versions before 10.30, where function re‐
274       cursion was used for backtracking.
275
276       As well as applying to pcre2_match(), the depth limit also controls the
277       depth of recursive function calls in pcre2_dfa_match(). These are  used
278       for  lookaround  assertions,  atomic  groups, and recursion within pat‐
279       terns.  The limit does not apply to JIT matching.
280

CREATING CHARACTER TABLES AT BUILD TIME

282
283       PCRE2 uses fixed tables for processing characters whose code points are
284       less than 256. By default, PCRE2 is built with a set of tables that are
285       distributed in the file src/pcre2_chartables.c.dist. These  tables  are
286       for ASCII codes only. If you add
287
288         --enable-rebuild-chartables
289
290       to  the  configure  command, the distributed tables are no longer used.
291       Instead, a program called pcre2_dftables is compiled and run. This out‐
292       puts the source for new set of tables, created in the default locale of
293       your C run-time system. This method of replacing the  tables  does  not
294       work if you are cross compiling, because pcre2_dftables needs to be run
295       on the local host and therefore not compiled with the cross compiler.
296
297       If you need to create alternative tables when cross compiling, you will
298       have  to  do so "by hand". There may also be other reasons for creating
299       tables manually.  To cause pcre2_dftables to  be  built  on  the  local
300       host, run a normal compiling command, and then run the program with the
301       output file as its argument, for example:
302
303         cc src/pcre2_dftables.c -o pcre2_dftables
304         ./pcre2_dftables src/pcre2_chartables.c
305
306       This builds the tables in the default locale of the local host. If  you
307       want to specify a locale, you must use the -L option:
308
309         LC_ALL=fr_FR ./pcre2_dftables -L src/pcre2_chartables.c
310
311       You can also specify -b (with or without -L). This causes the tables to
312       be written in binary instead of as source code. A set of binary  tables
313       can  be  loaded  into memory by an application and passed to pcre2_com‐
314       pile() in the same way as tables created by calling pcre2_maketables().
315       The  tables are just a string of bytes, independent of hardware charac‐
316       teristics such as endianness. This means they can be  bundled  with  an
317       application  that  runs in different environments, to ensure consistent
318       behaviour.
319

USING EBCDIC CODE

321
322       PCRE2 assumes by default that it will run in an environment  where  the
323       character  code is ASCII or Unicode, which is a superset of ASCII. This
324       is the case for most computer operating systems. PCRE2 can, however, be
325       compiled to run in an 8-bit EBCDIC environment by adding
326
327         --enable-ebcdic --disable-unicode
328
329       to the configure command. This setting implies --enable-rebuild-charta‐
330       bles. You should only use it if you know that you are in an EBCDIC  en‐
331       vironment (for example, an IBM mainframe operating system).
332
333       It  is  not possible to support both EBCDIC and UTF-8 codes in the same
334       version of the library. Consequently,  --enable-unicode  and  --enable-
335       ebcdic are mutually exclusive.
336
337       The EBCDIC character that corresponds to an ASCII LF is assumed to have
338       the value 0x15 by default. However, in some EBCDIC  environments,  0x25
339       is used. In such an environment you should use
340
341         --enable-ebcdic-nl25
342
343       as well as, or instead of, --enable-ebcdic. The EBCDIC character for CR
344       has the same value as in ASCII, namely, 0x0d.  Whichever  of  0x15  and
345       0x25 is not chosen as LF is made to correspond to the Unicode NEL char‐
346       acter (which, in Unicode, is 0x85).
347
348       The options that select newline behaviour, such as --enable-newline-is-
349       cr, and equivalent run-time options, refer to these character values in
350       an EBCDIC environment.
351

PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS

353
354       By default pcre2grep supports the use of callouts with string arguments
355       within  the patterns it is matching. There are two kinds: one that gen‐
356       erates output using local code, and another that calls an external pro‐
357       gram  or  script.   If --disable-pcre2grep-callout-fork is added to the
358       configure command, only the first kind  of  callout  is  supported;  if
359       --disable-pcre2grep-callout  is  used,  all callouts are completely ig‐
360       nored. For more details of pcre2grep callouts, see the pcre2grep  docu‐
361       mentation.
362

PCRE2GREP OPTIONS FOR COMPRESSED FILE SUPPORT

364
365       By  default,  pcre2grep reads all files as plain text. You can build it
366       so that it recognizes files whose names end in .gz or .bz2,  and  reads
367       them with libz or libbz2, respectively, by adding one or both of
368
369         --enable-pcre2grep-libz
370         --enable-pcre2grep-libbz2
371
372       to the configure command. These options naturally require that the rel‐
373       evant libraries are installed on your system. Configuration  will  fail
374       if they are not.
375

PCRE2GREP BUFFER SIZE

377
378       pcre2grep  uses an internal buffer to hold a "window" on the file it is
379       scanning, in order to be able to output "before" and "after" lines when
380       it finds a match. The default starting size of the buffer is 20KiB. The
381       buffer itself is three times this size, but because of the  way  it  is
382       used for holding "before" lines, the longest line that is guaranteed to
383       be processable is the notional buffer size. If a longer line is encoun‐
384       tered,  pcre2grep  automatically  expands the buffer, up to a specified
385       maximum size, whose default is 1MiB or the starting size, whichever  is
386       the  larger. You can change the default parameter values by adding, for
387       example,
388
389         --with-pcre2grep-bufsize=51200
390         --with-pcre2grep-max-bufsize=2097152
391
392       to the configure command. The caller of pcre2grep  can  override  these
393       values  by  using  --buffer-size  and  --max-buffer-size on the command
394       line.
395

PCRE2TEST OPTION FOR LIBREADLINE SUPPORT

397
398       If you add one of
399
400         --enable-pcre2test-libreadline
401         --enable-pcre2test-libedit
402
403       to the configure command, pcre2test is linked with the libreadline  or‐
404       libedit  library,  respectively, and when its input is from a terminal,
405       it reads it using the readline() function. This  provides  line-editing
406       and  history  facilities.  Note that libreadline is GPL-licensed, so if
407       you distribute a binary of pcre2test linked in this way, there  may  be
408       licensing issues. These can be avoided by linking instead with libedit,
409       which has a BSD licence.
410
411       Setting --enable-pcre2test-libreadline causes the -lreadline option  to
412       be  added to the pcre2test build. In many operating environments with a
413       sytem-installed readline library this is sufficient. However,  in  some
414       environments (e.g. if an unmodified distribution version of readline is
415       in use), some extra configuration may be necessary.  The  INSTALL  file
416       for libreadline says this:
417
418         "Readline uses the termcap functions, but does not link with
419         the termcap or curses library itself, allowing applications
420         which link with readline the to choose an appropriate library."
421
422       If  your environment has not been set up so that an appropriate library
423       is automatically included, you may need to add something like
424
425         LIBS="-ncurses"
426
427       immediately before the configure command.
428

INCLUDING DEBUGGING CODE

430
431       If you add
432
433         --enable-debug
434
435       to the configure command, additional debugging code is included in  the
436       build. This feature is intended for use by the PCRE2 maintainers.
437

DEBUGGING WITH VALGRIND SUPPORT

439
440       If you add
441
442         --enable-valgrind
443
444       to  the  configure command, PCRE2 will use valgrind annotations to mark
445       certain memory regions as unaddressable. This allows it to  detect  in‐
446       valid memory accesses, and is mostly useful for debugging PCRE2 itself.
447

CODE COVERAGE REPORTING

449
450       If  your  C  compiler is gcc, you can build a version of PCRE2 that can
451       generate a code coverage report for its test suite. To enable this, you
452       must install lcov version 1.6 or above. Then specify
453
454         --enable-coverage
455
456       to the configure command and build PCRE2 in the usual way.
457
458       Note that using ccache (a caching C compiler) is incompatible with code
459       coverage reporting. If you have configured ccache to run  automatically
460       on your system, you must set the environment variable
461
462         CCACHE_DISABLE=1
463
464       before running make to build PCRE2, so that ccache is not used.
465
466       When  --enable-coverage  is  used,  the  following addition targets are
467       added to the Makefile:
468
469         make coverage
470
471       This creates a fresh coverage report for the PCRE2 test  suite.  It  is
472       equivalent  to running "make coverage-reset", "make coverage-baseline",
473       "make check", and then "make coverage-report".
474
475         make coverage-reset
476
477       This zeroes the coverage counters, but does nothing else.
478
479         make coverage-baseline
480
481       This captures baseline coverage information.
482
483         make coverage-report
484
485       This creates the coverage report.
486
487         make coverage-clean-report
488
489       This removes the generated coverage report without cleaning the  cover‐
490       age data itself.
491
492         make coverage-clean-data
493
494       This  removes  the captured coverage data without removing the coverage
495       files created at compile time (*.gcno).
496
497         make coverage-clean
498
499       This cleans all coverage data including the generated coverage  report.
500       For  more  information about code coverage, see the gcov and lcov docu‐
501       mentation.
502

DISABLING THE Z AND T FORMATTING MODIFIERS

504
505       The C99 standard defines formatting modifiers z and t  for  size_t  and
506       ptrdiff_t  values, respectively. By default, PCRE2 uses these modifiers
507       in environments other than old versions of Microsoft Visual Studio when
508       __STDC_VERSION__  is  defined  and has a value greater than or equal to
509       199901L (indicating support for C99).  However, there is at  least  one
510       environment that claims to be C99 but does not support these modifiers.
511       If
512
513         --disable-percent-zt
514
515       is specified, no use is made of the z or t modifiers. Instead of %td or
516       %zu,  a  suitable  format is used depending in the size of long for the
517       platform.
518

SUPPORT FOR FUZZERS

520
521       There is a special option for use by people who  want  to  run  fuzzing
522       tests on PCRE2:
523
524         --enable-fuzz-support
525
526       At present this applies only to the 8-bit library. If set, it causes an
527       extra library called libpcre2-fuzzsupport.a to be built,  but  not  in‐
528       stalled.  This  contains  a single function called LLVMFuzzerTestOneIn‐
529       put() whose arguments are a pointer to a string and the length  of  the
530       string.  When  called,  this  function tries to compile the string as a
531       pattern, and if that succeeds, to match it.  This is done both with  no
532       options  and  with some random options bits that are generated from the
533       string.
534
535       Setting --enable-fuzz-support also causes  a  binary  called  pcre2fuz‐
536       zcheck  to be created. This is normally run under valgrind or used when
537       PCRE2 is compiled with address sanitizing enabled. It calls the fuzzing
538       function  and  outputs  information  about  what it is doing. The input
539       strings are specified by arguments: if an argument starts with "="  the
540       rest  of it is a literal input string. Otherwise, it is assumed to be a
541       file name, and the contents of the file are the test string.
542

OBSOLETE OPTION

544
545       In versions of PCRE2 prior to 10.30, there were two  ways  of  handling
546       backtracking  in the pcre2_match() function. The default was to use the
547       system stack, but if
548
549         --disable-stack-for-recursion
550
551       was set, memory on the heap was used. From release 10.30  onwards  this
552       has  changed  (the  stack  is  no longer used) and this option now does
553       nothing except give a warning.
554

SEE ALSO

556
557       pcre2api(3), pcre2-config(3).
558

AUTHOR

560
561       Philip Hazel
562       University Computing Service
563       Cambridge, England.
564

REVISION

566
567       Last updated: 08 December 2021
568       Copyright (c) 1997-2021 University of Cambridge.
569
570
571
572PCRE2 10.40                    08 December 2021                  PCRE2BUILD(3)
Impressum