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  uses  heap  memory to record backtracking
245       points. The more nested backtracking points there  are  (that  is,  the
246       deeper  the  search tree), the more memory is needed. There is an upper
247       limit, specified in kibibytes (units of 1024 bytes). This limit can  be
248       changed  at  run  time, as described in the pcre2api documentation. The
249       default limit (in effect unlimited) is 20 million. You can change  this
250       by a setting such as
251
252         --with-heap-limit=500
253
254       which  limits the amount of heap to 500 KiB. This limit applies only to
255       interpretive matching in pcre2_match() and pcre2_dfa_match(), which may
256       also  use  the  heap for internal workspace when processing complicated
257       patterns. This limit does not apply when JIT (which has its own  memory
258       arrangements) is used.
259
260       You  can  also explicitly limit the depth of nested backtracking in the
261       pcre2_match() interpreter. This limit defaults to the value that is set
262       for  --with-match-limit.  You  can set a lower default limit by adding,
263       for example,
264
265         --with-match-limit-depth=10000
266
267       to the configure command. This value can be  overridden  at  run  time.
268       This  depth  limit  indirectly limits the amount of heap memory that is
269       used, but because the size of each backtracking "frame" depends on  the
270       number  of  capturing parentheses in a pattern, the amount of heap that
271       is used before the limit is reached varies  from  pattern  to  pattern.
272       This limit was more useful in versions before 10.30, where function re‐
273       cursion was used for backtracking.
274
275       As well as applying to pcre2_match(), the depth limit also controls the
276       depth  of recursive function calls in pcre2_dfa_match(). These are used
277       for lookaround assertions, atomic groups,  and  recursion  within  pat‐
278       terns.  The limit does not apply to JIT matching.
279

CREATING CHARACTER TABLES AT BUILD TIME

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

USING EBCDIC CODE

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

PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS

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

PCRE2GREP OPTIONS FOR COMPRESSED FILE SUPPORT

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

PCRE2GREP BUFFER SIZE

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

PCRE2TEST OPTION FOR LIBREADLINE SUPPORT

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

INCLUDING DEBUGGING CODE

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

DEBUGGING WITH VALGRIND SUPPORT

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

CODE COVERAGE REPORTING

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

DISABLING THE Z AND T FORMATTING MODIFIERS

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

SUPPORT FOR FUZZERS

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

OBSOLETE OPTION

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

SEE ALSO

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

AUTHOR

559
560       Philip Hazel
561       Retired from University Computing Service
562       Cambridge, England.
563

REVISION

565
566       Last updated: 27 July 2022
567       Copyright (c) 1997-2022 University of Cambridge.
568
569
570
571PCRE2 10.41                      27 July 2022                    PCRE2BUILD(3)
Impressum