new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / external / pcre2-10.32 / doc / pcre2build.3
1 .TH PCRE2BUILD 3 "26 April 2018" "PCRE2 10.32"
2 .SH NAME
3 PCRE2 - Perl-compatible regular expressions (revised API)
4 .
5 .
6 .SH "BUILDING PCRE2"
7 .rs
8 .sp
9 PCRE2 is distributed with a \fBconfigure\fP script that can be used to build
10 the library in Unix-like environments using the applications known as
11 Autotools. Also in the distribution are files to support building using
12 \fBCMake\fP instead of \fBconfigure\fP. The text file
13 .\" HTML <a href="README.txt">
14 .\" </a>
15 \fBREADME\fP
16 .\"
17 contains general information about building with Autotools (some of which is
18 repeated below), and also has some comments about building on various operating
19 systems. There is a lot more information about building PCRE2 without using
20 Autotools (including information about using \fBCMake\fP and building "by
21 hand") in the text file called
22 .\" HTML <a href="NON-AUTOTOOLS-BUILD.txt">
23 .\" </a>
24 \fBNON-AUTOTOOLS-BUILD\fP.
25 .\"
26 You should consult this file as well as the
27 .\" HTML <a href="README.txt">
28 .\" </a>
29 \fBREADME\fP
30 .\"
31 file if you are building in a non-Unix-like environment.
32 .
33 .
34 .SH "PCRE2 BUILD-TIME OPTIONS"
35 .rs
36 .sp
37 The rest of this document describes the optional features of PCRE2 that can be
38 selected when the library is compiled. It assumes use of the \fBconfigure\fP
39 script, where the optional features are selected or deselected by providing
40 options to \fBconfigure\fP before running the \fBmake\fP command. However, the
41 same options can be selected in both Unix-like and non-Unix-like environments
42 if you are using \fBCMake\fP instead of \fBconfigure\fP to build PCRE2.
43 .P
44 If you are not using Autotools or \fBCMake\fP, option selection can be done by
45 editing the \fBconfig.h\fP file, or by passing parameter settings to the
46 compiler, as described in
47 .\" HTML <a href="NON-AUTOTOOLS-BUILD.txt">
48 .\" </a>
49 \fBNON-AUTOTOOLS-BUILD\fP.
50 .\"
51 .P
52 The complete list of options for \fBconfigure\fP (which includes the standard
53 ones such as the selection of the installation directory) can be obtained by
54 running
55 .sp
56   ./configure --help
57 .sp
58 The following sections include descriptions of "on/off" options whose names
59 begin with --enable or --disable. Because of the way that \fBconfigure\fP
60 works, --enable and --disable always come in pairs, so the complementary option
61 always exists as well, but as it specifies the default, it is not described.
62 Options that specify values have names that start with --with. At the end of a
63 \fBconfigure\fP run, a summary of the configuration is output.
64 .
65 .
66 .SH "BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES"
67 .rs
68 .sp
69 By default, a library called \fBlibpcre2-8\fP is built, containing functions
70 that take string arguments contained in arrays of bytes, interpreted either as
71 single-byte characters, or UTF-8 strings. You can also build two other
72 libraries, called \fBlibpcre2-16\fP and \fBlibpcre2-32\fP, which process
73 strings that are contained in arrays of 16-bit and 32-bit code units,
74 respectively. These can be interpreted either as single-unit characters or
75 UTF-16/UTF-32 strings. To build these additional libraries, add one or both of
76 the following to the \fBconfigure\fP command:
77 .sp
78   --enable-pcre2-16
79   --enable-pcre2-32
80 .sp
81 If you do not want the 8-bit library, add
82 .sp
83   --disable-pcre2-8
84 .sp
85 as well. At least one of the three libraries must be built. Note that the POSIX
86 wrapper is for the 8-bit library only, and that \fBpcre2grep\fP is an 8-bit
87 program. Neither of these are built if you select only the 16-bit or 32-bit
88 libraries.
89 .
90 .
91 .SH "BUILDING SHARED AND STATIC LIBRARIES"
92 .rs
93 .sp
94 The Autotools PCRE2 building process uses \fBlibtool\fP to build both shared
95 and static libraries by default. You can suppress an unwanted library by adding
96 one of
97 .sp
98   --disable-shared
99   --disable-static
100 .sp
101 to the \fBconfigure\fP command.
102 .
103 .
104 .SH "UNICODE AND UTF SUPPORT"
105 .rs
106 .sp
107 By default, PCRE2 is built with support for Unicode and UTF character strings.
108 To build it without Unicode support, add
109 .sp
110   --disable-unicode
111 .sp
112 to the \fBconfigure\fP command. This setting applies to all three libraries. It
113 is not possible to build one library with Unicode support, and another without,
114 in the same configuration.
115 .P
116 Of itself, Unicode support does not make PCRE2 treat strings as UTF-8, UTF-16
117 or UTF-32. To do that, applications that use the library can set the PCRE2_UTF
118 option when they call \fBpcre2_compile()\fP to compile a pattern.
119 Alternatively, patterns may be started with (*UTF) unless the application has
120 locked this out by setting PCRE2_NEVER_UTF.
121 .P
122 UTF support allows the libraries to process character code points up to
123 0x10ffff in the strings that they handle. Unicode support also gives access to
124 the Unicode properties of characters, using pattern escapes such as \eP, \ep,
125 and \eX. Only the general category properties such as \fILu\fP and \fINd\fP are
126 supported. Details are given in the
127 .\" HREF
128 \fBpcre2pattern\fP
129 .\"
130 documentation.
131 .P
132 Pattern escapes such as \ed and \ew do not by default make use of Unicode
133 properties. The application can request that they do by setting the PCRE2_UCP
134 option. Unless the application has set PCRE2_NEVER_UCP, a pattern may also
135 request this by starting with (*UCP).
136 .
137 .
138 .SH "DISABLING THE USE OF \eC"
139 .rs
140 .sp
141 The \eC escape sequence, which matches a single code unit, even in a UTF mode,
142 can cause unpredictable behaviour because it may leave the current matching
143 point in the middle of a multi-code-unit character. The application can lock it
144 out by setting the PCRE2_NEVER_BACKSLASH_C option when calling
145 \fBpcre2_compile()\fP. There is also a build-time option
146 .sp
147   --enable-never-backslash-C
148 .sp
149 (note the upper case C) which locks out the use of \eC entirely.
150 .
151 .
152 .SH "JUST-IN-TIME COMPILER SUPPORT"
153 .rs
154 .sp
155 Just-in-time (JIT) compiler support is included in the build by specifying
156 .sp
157   --enable-jit
158 .sp
159 This support is available only for certain hardware architectures. If this
160 option is set for an unsupported architecture, a building error occurs.
161 If in doubt, use
162 .sp
163   --enable-jit=auto
164 .sp
165 which enables JIT only if the current hardware is supported. You can check
166 if JIT is enabled in the configuration summary that is output at the end of a
167 \fBconfigure\fP run. If you are enabling JIT under SELinux you may also want to
168 add
169 .sp
170   --enable-jit-sealloc
171 .sp
172 which enables the use of an execmem allocator in JIT that is compatible with
173 SELinux. This has no effect if JIT is not enabled. See the
174 .\" HREF
175 \fBpcre2jit\fP
176 .\"
177 documentation for a discussion of JIT usage. When JIT support is enabled,
178 pcre2grep automatically makes use of it, unless you add
179 .sp
180   --disable-pcre2grep-jit
181 .sp
182 to the "configure" command.
183 .
184 .
185 .SH "NEWLINE RECOGNITION"
186 .rs
187 .sp
188 By default, PCRE2 interprets the linefeed (LF) character as indicating the end
189 of a line. This is the normal newline character on Unix-like systems. You can
190 compile PCRE2 to use carriage return (CR) instead, by adding
191 .sp
192   --enable-newline-is-cr
193 .sp
194 to the \fBconfigure\fP command. There is also an --enable-newline-is-lf option,
195 which explicitly specifies linefeed as the newline character.
196 .P
197 Alternatively, you can specify that line endings are to be indicated by the
198 two-character sequence CRLF (CR immediately followed by LF). If you want this,
199 add
200 .sp
201   --enable-newline-is-crlf
202 .sp
203 to the \fBconfigure\fP command. There is a fourth option, specified by
204 .sp
205   --enable-newline-is-anycrlf
206 .sp
207 which causes PCRE2 to recognize any of the three sequences CR, LF, or CRLF as
208 indicating a line ending. A fifth option, specified by
209 .sp
210   --enable-newline-is-any
211 .sp
212 causes PCRE2 to recognize any Unicode newline sequence. The Unicode newline
213 sequences are the three just mentioned, plus the single characters VT (vertical
214 tab, U+000B), FF (form feed, U+000C), NEL (next line, U+0085), LS (line
215 separator, U+2028), and PS (paragraph separator, U+2029). The final option is
216 .sp
217   --enable-newline-is-nul
218 .sp
219 which causes NUL (binary zero) to be set as the default line-ending character.
220 .P
221 Whatever default line ending convention is selected when PCRE2 is built can be
222 overridden by applications that use the library. At build time it is
223 recommended to use the standard for your operating system.
224 .
225 .
226 .SH "WHAT \eR MATCHES"
227 .rs
228 .sp
229 By default, the sequence \eR in a pattern matches any Unicode newline sequence,
230 independently of what has been selected as the line ending sequence. If you
231 specify
232 .sp
233   --enable-bsr-anycrlf
234 .sp
235 the default is changed so that \eR matches only CR, LF, or CRLF. Whatever is
236 selected when PCRE2 is built can be overridden by applications that use the
237 library.
238 .
239 .
240 .SH "HANDLING VERY LARGE PATTERNS"
241 .rs
242 .sp
243 Within a compiled pattern, offset values are used to point from one part to
244 another (for example, from an opening parenthesis to an alternation
245 metacharacter). By default, in the 8-bit and 16-bit libraries, two-byte values
246 are used for these offsets, leading to a maximum size for a compiled pattern of
247 around 64 thousand code units. This is sufficient to handle all but the most
248 gigantic patterns. Nevertheless, some people do want to process truly enormous
249 patterns, so it is possible to compile PCRE2 to use three-byte or four-byte
250 offsets by adding a setting such as
251 .sp
252   --with-link-size=3
253 .sp
254 to the \fBconfigure\fP command. The value given must be 2, 3, or 4. For the
255 16-bit library, a value of 3 is rounded up to 4. In these libraries, using
256 longer offsets slows down the operation of PCRE2 because it has to load
257 additional data when handling them. For the 32-bit library the value is always
258 4 and cannot be overridden; the value of --with-link-size is ignored.
259 .
260 .
261 .SH "LIMITING PCRE2 RESOURCE USAGE"
262 .rs
263 .sp
264 The \fBpcre2_match()\fP function increments a counter each time it goes round
265 its main loop. Putting a limit on this counter controls the amount of computing
266 resource used by a single call to \fBpcre2_match()\fP. The limit can be changed
267 at run time, as described in the
268 .\" HREF
269 \fBpcre2api\fP
270 .\"
271 documentation. The default is 10 million, but this can be changed by adding a
272 setting such as
273 .sp
274   --with-match-limit=500000
275 .sp
276 to the \fBconfigure\fP command. This setting also applies to the
277 \fBpcre2_dfa_match()\fP matching function, and to JIT matching (though the
278 counting is done differently).
279 .P
280 The \fBpcre2_match()\fP function starts out using a 20KiB vector on the system
281 stack to record backtracking points. The more nested backtracking points there
282 are (that is, the deeper the search tree), the more memory is needed. If the
283 initial vector is not large enough, heap memory is used, up to a certain limit,
284 which is specified in kibibytes (units of 1024 bytes). The limit can be changed
285 at run time, as described in the
286 .\" HREF
287 \fBpcre2api\fP
288 .\"
289 documentation. The default limit (in effect unlimited) is 20 million. You can
290 change this by a setting such as
291 .sp
292   --with-heap-limit=500
293 .sp
294 which limits the amount of heap to 500 KiB. This limit applies only to
295 interpretive matching in \fBpcre2_match()\fP and \fBpcre2_dfa_match()\fP, which
296 may also use the heap for internal workspace when processing complicated
297 patterns. This limit does not apply when JIT (which has its own memory
298 arrangements) is used.
299 .P
300 You can also explicitly limit the depth of nested backtracking in the
301 \fBpcre2_match()\fP interpreter. This limit defaults to the value that is set
302 for --with-match-limit. You can set a lower default limit by adding, for
303 example,
304 .sp
305   --with-match-limit_depth=10000
306 .sp
307 to the \fBconfigure\fP command. This value can be overridden at run time. This
308 depth limit indirectly limits the amount of heap memory that is used, but
309 because the size of each backtracking "frame" depends on the number of
310 capturing parentheses in a pattern, the amount of heap that is used before the
311 limit is reached varies from pattern to pattern. This limit was more useful in
312 versions before 10.30, where function recursion was used for backtracking.
313 .P
314 As well as applying to \fBpcre2_match()\fP, the depth limit also controls
315 the depth of recursive function calls in \fBpcre2_dfa_match()\fP. These are
316 used for lookaround assertions, atomic groups, and recursion within patterns.
317 The limit does not apply to JIT matching.
318 .
319 .
320 .SH "CREATING CHARACTER TABLES AT BUILD TIME"
321 .rs
322 .sp
323 PCRE2 uses fixed tables for processing characters whose code points are less
324 than 256. By default, PCRE2 is built with a set of tables that are distributed
325 in the file \fIsrc/pcre2_chartables.c.dist\fP. These tables are for ASCII codes
326 only. If you add
327 .sp
328   --enable-rebuild-chartables
329 .sp
330 to the \fBconfigure\fP command, the distributed tables are no longer used.
331 Instead, a program called \fBdftables\fP is compiled and run. This outputs the
332 source for new set of tables, created in the default locale of your C run-time
333 system. This method of replacing the tables does not work if you are cross
334 compiling, because \fBdftables\fP is run on the local host. If you need to
335 create alternative tables when cross compiling, you will have to do so "by
336 hand".
337 .
338 .
339 .SH "USING EBCDIC CODE"
340 .rs
341 .sp
342 PCRE2 assumes by default that it will run in an environment where the character
343 code is ASCII or Unicode, which is a superset of ASCII. This is the case for
344 most computer operating systems. PCRE2 can, however, be compiled to run in an
345 8-bit EBCDIC environment by adding
346 .sp
347   --enable-ebcdic --disable-unicode
348 .sp
349 to the \fBconfigure\fP command. This setting implies
350 --enable-rebuild-chartables. You should only use it if you know that you are in
351 an EBCDIC environment (for example, an IBM mainframe operating system).
352 .P
353 It is not possible to support both EBCDIC and UTF-8 codes in the same version
354 of the library. Consequently, --enable-unicode and --enable-ebcdic are mutually
355 exclusive.
356 .P
357 The EBCDIC character that corresponds to an ASCII LF is assumed to have the
358 value 0x15 by default. However, in some EBCDIC environments, 0x25 is used. In
359 such an environment you should use
360 .sp
361   --enable-ebcdic-nl25
362 .sp
363 as well as, or instead of, --enable-ebcdic. The EBCDIC character for CR has the
364 same value as in ASCII, namely, 0x0d. Whichever of 0x15 and 0x25 is \fInot\fP
365 chosen as LF is made to correspond to the Unicode NEL character (which, in
366 Unicode, is 0x85).
367 .P
368 The options that select newline behaviour, such as --enable-newline-is-cr,
369 and equivalent run-time options, refer to these character values in an EBCDIC
370 environment.
371 .
372 .
373 .SH "PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS"
374 .rs
375 .sp
376 By default, on non-Windows systems, \fBpcre2grep\fP supports the use of
377 callouts with string arguments within the patterns it is matching, in order to
378 run external scripts. For details, see the
379 .\" HREF
380 \fBpcre2grep\fP
381 .\"
382 documentation. This support can be disabled by adding
383 --disable-pcre2grep-callout to the \fBconfigure\fP command.
384 .
385 .
386 .SH "PCRE2GREP OPTIONS FOR COMPRESSED FILE SUPPORT"
387 .rs
388 .sp
389 By default, \fBpcre2grep\fP reads all files as plain text. You can build it so
390 that it recognizes files whose names end in \fB.gz\fP or \fB.bz2\fP, and reads
391 them with \fBlibz\fP or \fBlibbz2\fP, respectively, by adding one or both of
392 .sp
393   --enable-pcre2grep-libz
394   --enable-pcre2grep-libbz2
395 .sp
396 to the \fBconfigure\fP command. These options naturally require that the
397 relevant libraries are installed on your system. Configuration will fail if
398 they are not.
399 .
400 .
401 .SH "PCRE2GREP BUFFER SIZE"
402 .rs
403 .sp
404 \fBpcre2grep\fP uses an internal buffer to hold a "window" on the file it is
405 scanning, in order to be able to output "before" and "after" lines when it
406 finds a match. The default starting size of the buffer is 20KiB. The buffer
407 itself is three times this size, but because of the way it is used for holding
408 "before" lines, the longest line that is guaranteed to be processable is the
409 notional buffer size. If a longer line is encountered, \fBpcre2grep\fP
410 automatically expands the buffer, up to a specified maximum size, whose default
411 is 1MiB or the starting size, whichever is the larger. You can change the
412 default parameter values by adding, for example,
413 .sp
414   --with-pcre2grep-bufsize=51200
415   --with-pcre2grep-max-bufsize=2097152
416 .sp
417 to the \fBconfigure\fP command. The caller of \fPpcre2grep\fP can override
418 these values by using --buffer-size and --max-buffer-size on the command line.
419 .
420 .
421 .SH "PCRE2TEST OPTION FOR LIBREADLINE SUPPORT"
422 .rs
423 .sp
424 If you add one of
425 .sp
426   --enable-pcre2test-libreadline
427   --enable-pcre2test-libedit
428 .sp
429 to the \fBconfigure\fP command, \fBpcre2test\fP is linked with the
430 \fBlibreadline\fP or\fBlibedit\fP library, respectively, and when its input is
431 from a terminal, it reads it using the \fBreadline()\fP function. This provides
432 line-editing and history facilities. Note that \fBlibreadline\fP is
433 GPL-licensed, so if you distribute a binary of \fBpcre2test\fP linked in this
434 way, there may be licensing issues. These can be avoided by linking instead
435 with \fBlibedit\fP, which has a BSD licence.
436 .P
437 Setting --enable-pcre2test-libreadline causes the \fB-lreadline\fP option to be
438 added to the \fBpcre2test\fP build. In many operating environments with a
439 sytem-installed readline library this is sufficient. However, in some
440 environments (e.g. if an unmodified distribution version of readline is in
441 use), some extra configuration may be necessary. The INSTALL file for
442 \fBlibreadline\fP says this:
443 .sp
444   "Readline uses the termcap functions, but does not link with
445   the termcap or curses library itself, allowing applications
446   which link with readline the to choose an appropriate library."
447 .sp
448 If your environment has not been set up so that an appropriate library is
449 automatically included, you may need to add something like
450 .sp
451   LIBS="-ncurses"
452 .sp
453 immediately before the \fBconfigure\fP command.
454 .
455 .
456 .SH "INCLUDING DEBUGGING CODE"
457 .rs
458 .sp
459 If you add
460 .sp
461   --enable-debug
462 .sp
463 to the \fBconfigure\fP command, additional debugging code is included in the
464 build. This feature is intended for use by the PCRE2 maintainers.
465 .
466 .
467 .SH "DEBUGGING WITH VALGRIND SUPPORT"
468 .rs
469 .sp
470 If you add
471 .sp
472   --enable-valgrind
473 .sp
474 to the \fBconfigure\fP command, PCRE2 will use valgrind annotations to mark
475 certain memory regions as unaddressable. This allows it to detect invalid
476 memory accesses, and is mostly useful for debugging PCRE2 itself.
477 .
478 .
479 .SH "CODE COVERAGE REPORTING"
480 .rs
481 .sp
482 If your C compiler is gcc, you can build a version of PCRE2 that can generate a
483 code coverage report for its test suite. To enable this, you must install
484 \fBlcov\fP version 1.6 or above. Then specify
485 .sp
486   --enable-coverage
487 .sp
488 to the \fBconfigure\fP command and build PCRE2 in the usual way.
489 .P
490 Note that using \fBccache\fP (a caching C compiler) is incompatible with code
491 coverage reporting. If you have configured \fBccache\fP to run automatically
492 on your system, you must set the environment variable
493 .sp
494   CCACHE_DISABLE=1
495 .sp
496 before running \fBmake\fP to build PCRE2, so that \fBccache\fP is not used.
497 .P
498 When --enable-coverage is used, the following addition targets are added to the
499 \fIMakefile\fP:
500 .sp
501   make coverage
502 .sp
503 This creates a fresh coverage report for the PCRE2 test suite. It is equivalent
504 to running "make coverage-reset", "make coverage-baseline", "make check", and
505 then "make coverage-report".
506 .sp
507   make coverage-reset
508 .sp
509 This zeroes the coverage counters, but does nothing else.
510 .sp
511   make coverage-baseline
512 .sp
513 This captures baseline coverage information.
514 .sp
515   make coverage-report
516 .sp
517 This creates the coverage report.
518 .sp
519   make coverage-clean-report
520 .sp
521 This removes the generated coverage report without cleaning the coverage data
522 itself.
523 .sp
524   make coverage-clean-data
525 .sp
526 This removes the captured coverage data without removing the coverage files
527 created at compile time (*.gcno).
528 .sp
529   make coverage-clean
530 .sp
531 This cleans all coverage data including the generated coverage report. For more
532 information about code coverage, see the \fBgcov\fP and \fBlcov\fP
533 documentation.
534 .
535 .
536 .SH "SUPPORT FOR FUZZERS"
537 .rs
538 .sp
539 There is a special option for use by people who want to run fuzzing tests on
540 PCRE2:
541 .sp
542   --enable-fuzz-support
543 .sp
544 At present this applies only to the 8-bit library. If set, it causes an extra
545 library called libpcre2-fuzzsupport.a to be built, but not installed. This
546 contains a single function called LLVMFuzzerTestOneInput() whose arguments are
547 a pointer to a string and the length of the string. When called, this function
548 tries to compile the string as a pattern, and if that succeeds, to match it.
549 This is done both with no options and with some random options bits that are
550 generated from the string.
551 .P
552 Setting --enable-fuzz-support also causes a binary called \fBpcre2fuzzcheck\fP
553 to be created. This is normally run under valgrind or used when PCRE2 is
554 compiled with address sanitizing enabled. It calls the fuzzing function and
555 outputs information about what it is doing. The input strings are specified by
556 arguments: if an argument starts with "=" the rest of it is a literal input
557 string. Otherwise, it is assumed to be a file name, and the contents of the
558 file are the test string.
559 .
560 .
561 .SH "OBSOLETE OPTION"
562 .rs
563 .sp
564 In versions of PCRE2 prior to 10.30, there were two ways of handling
565 backtracking in the \fBpcre2_match()\fP function. The default was to use the
566 system stack, but if
567 .sp
568   --disable-stack-for-recursion
569 .sp
570 was set, memory on the heap was used. From release 10.30 onwards this has
571 changed (the stack is no longer used) and this option now does nothing except
572 give a warning.
573 .
574 .SH "SEE ALSO"
575 .rs
576 .sp
577 \fBpcre2api\fP(3), \fBpcre2-config\fP(3).
578 .
579 .
580 .SH AUTHOR
581 .rs
582 .sp
583 .nf
584 Philip Hazel
585 University Computing Service
586 Cambridge, England.
587 .fi
588 .
589 .
590 .SH REVISION
591 .rs
592 .sp
593 .nf
594 Last updated: 26 April 2018
595 Copyright (c) 1997-2018 University of Cambridge.
596 .fi