8000 PCRE2 library support. · nginx/nginx@c6fec0b · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit c6fec0b

Browse files
committed
PCRE2 library support.
The PCRE2 library is now used by default if found, instead of the original PCRE library. If needed for some reason, this can be disabled with the --without-pcre2 configure option. To make it possible to specify paths to the library and include files via --with-cc-opt / --with-ld-opt, the library is first tested without any additional paths and options. If this fails, the pcre2-config script is used. Similarly to the original PCRE library, it is now possible to build PCRE2 from sources with nginx configure, by using the --with-pcre= option. It automatically detects if PCRE or PCRE2 sources are provided. Note that compiling PCRE2 10.33 and later requires inttypes.h. When compiling on Windows with MSVC, inttypes.h is only available starting with MSVC 2013. In older versions some replacement needs to be provided ("echo '#include <stdint.h>' > pcre2-10.xx/src/inttypes.h" is good enough for MSVC 2010). The interface on nginx side remains unchanged.
1 parent cddb22c commit c6fec0b

File tree

6 files changed

+574
-53
lines changed

6 files changed

+574
-53
lines changed

auto/lib/pcre/conf

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,61 @@
55

66
if [ $PCRE != NONE ]; then
77

8-
have=NGX_PCRE . auto/have
8+
if [ -f $PCRE/src/pcre2.h.generic ]; then
99

10-
if [ "$NGX_PLATFORM" = win32 ]; then
11-
have=PCRE_STATIC . auto/have
12-
fi
10+
PCRE_LIBRARY=PCRE2
11+
12+
have=NGX_PCRE . auto/have
13+
have=NGX_PCRE2 . auto/have
14+
15+
if [ "$NGX_PLATFORM" = win32 ]; then
16+
have=PCRE2_STATIC . auto/have
17+
fi
18+
19+
CORE_INCS="$CORE_INCS $PCRE/src/"
20+
CORE_DEPS="$CORE_DEPS $PCRE/src/pcre2.h"
1321

14-
CORE_INCS="$CORE_INCS $PCRE"
15-
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
22+
case "$NGX_CC_NAME" in
1623

17-
case "$NGX_CC_NAME" in
24+
msvc)
25+
LINK_DEPS="$LINK_DEPS $PCRE/src/pcre2-8.lib"
26+
CORE_LIBS="$CORE_LIBS $PCRE/src/pcre2-8.lib"
27+
;;
1828

19-
msvc | owc | bcc)
20-
LINK_DEPS="$LINK_DEPS $PCRE/pcre.lib"
21-
CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib"
22-
;;
29+
*)
30+
LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre2-8.a"
31+
CORE_LIBS="$CORE_LIBS $PCRE/.libs/libpcre2-8.a"
32+
;;
2333

24-
*)
25-
LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre.a"
26-
CORE_LIBS="$CORE_LIBS $PCRE/.libs/libpcre.a"
27-
;;
34+
esac
35+
36+
else
37+
38+
PCRE_LIBRARY=PCRE
39+
40+
have=NGX_PCRE . auto/have
41+
42+
if [ "$NGX_PLATFORM" = win32 ]; then
43+
have=PCRE_STATIC . auto/have
44+
fi
2845

29-
esac
46+
CORE_INCS="$CORE_INCS $PCRE"
47+
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
3048

49+
case "$NGX_CC_NAME" in
50+
51+
msvc | owc | bcc)
52+
LINK_DEPS="$LINK_DEPS $PCRE/pcre.lib"
53+
CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib"
54+
;;
55+
56+
*)
57+
LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre.a"
58+
CORE_LIBS="$CORE_LIBS $PCRE/.libs/libpcre.a"
59+
;;
60+
61+
esac
62+
fi
3163

3264
if [ $PCRE_JIT = YES ]; then
3365
have=NGX_HAVE_PCRE_JIT . auto/have
@@ -37,8 +69,48 @@ if [ $PCRE != NONE ]; then
3769
else
3870

3971
if [ "$NGX_PLATFORM" != win32 ]; then
40-
4172
PCRE=NO
73+
fi
74+
75+
if [ $PCRE = NO -a $PCRE2 != DISABLED ]; then
76+
77+
ngx_feature="PCRE2 library"
78+
ngx_feature_name="NGX_PCRE2"
79+
ngx_feature_run=no
80+
ngx_feature_incs="#define PCRE2_CODE_UNIT_WIDTH 8
81+
#include <pcre2.h>"
82+
ngx_feature_path=
83+
ngx_feature_libs="-lpcre2-8"
84+
ngx_feature_test="pcre2_code *re;
85+
re = pcre2_compile(NULL, 0, 0, NULL, NULL, NULL);
86+
if (re == NULL) return 1"
87+
. auto/feature
88+
89+
if [ $ngx_found = no ]; then
90+
91+
# pcre2-config
92+
93+
ngx_pcre2_prefix=`pcre2-config --prefix 2>/dev/null`
94+
95+
if [ -n "$ngx_pcre2_prefix" ]; then
96+
ngx_feature="PCRE2 library in $ngx_pcre2_prefix"
97+
ngx_feature_path=`pcre2-config --cflags \
98+
| sed -n -e 's/.*-I *\([^ ][^ ]*\).*/\1/p'`
99+
ngx_feature_libs=`pcre2-config --libs8`
100+
. auto/feature
101+
fi
102+
fi
103+
104+
if [ $ngx_found = yes ]; then
105+
have=NGX_PCRE . auto/have
106+
CORE_INCS="$CORE_INCS $ngx_feature_path"
107+
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
108+
PCRE=YES
109+
PCRE_LIBRARY=PCRE2
110+
fi
111+
fi
112+
113+
if [ $PCRE = NO ]; then
42114

43115
ngx_feature="PCRE library"
44116
ngx_feature_name="NGX_PCRE"
@@ -114,6 +186,7 @@ else
114186
CORE_INCS="$CORE_INCS $ngx_feature_path"
115187
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
116188
PCRE=YES
189+
PCRE_LIBRARY=PCRE
117190
fi
118191

119192
if [ $PCRE = YES ]; then

auto/lib/pcre/make

Lines changed: 128 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,138 @@
33
# Copyright (C) Nginx, Inc.
44

55

6-
case "$NGX_CC_NAME" in
6+
if [ $PCRE_LIBRARY = PCRE2 ]; then
7+
8+
# PCRE2
9+
10+
if [ $NGX_CC_NAME = msvc ]; then
11+
12+
# With PCRE2, it is not possible to compile all sources.
13+
# Since list of source files changes between versions, we
14+
# test files which might not be present.
15+
16+
ngx_pcre_srcs="pcre2_auto_possess.c \
17+
pcre2_chartables.c \
18+
pcre2_compile.c \
19+
pcre2_config.c \
20+
pcre2_context.c \
21+
pcre2_dfa_match.c \
22+
pcre2_error.c \
23+
pcre2_jit_compile.c \
24+
pcre2_maketables.c \
25+
pcre2_match.c \
26+
pcre2_match_data.c \
27+
pcre2_newline.c \
28+
pcre2_ord2utf.c \
29+
pcre2_pattern_info.c \
30+
pcre2_string_utils.c \
31+
pcre2_study.c \
32+
pcre2_substitute.c \
33+
pcre2_substring.c \
34+
pcre2_tables.c \
35+
pcre2_ucd.c \
36+
pcre2_valid_utf.c \
37+
pcre2_xclass.c"
38+
39+
ngx_pcre_test="pcre2_convert.c \
40+
pcre2_extuni.c \
41+
pcre2_find_bracket.c \
42+
pcre2_script_run.c \
43+
pcre2_serialize.c"
44+
45+
for ngx_src in $ngx_pcre_test
46+
do
47+
if [ -f $PCRE/src/$ngx_src ]; then
48+
ngx_pcre_srcs="$ngx_pcre_srcs $ngx_src"
49+
fi
50+
done
51+
52+
ngx_pcre_objs=`echo $ngx_pcre_srcs \
53+
| sed -e "s#\([^ ]*\.\)c#\1$ngx_objext#g"`
54+
55+
ngx_pcre_srcs=`echo $ngx_pcre_srcs \
56+
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont\1/g"`
57+
ngx_pcre_objs=`echo $ngx_pcre_objs \
58+
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont\1/g"`
59+
60+
cat << END >> $NGX_MAKEFILE
61+
62+
PCRE_CFLAGS = -O2 -Ob1 -Oi -Gs $LIBC $CPU_OPT
63+
PCRE_FLAGS = -DHAVE_CONFIG_H -DPCRE2_STATIC -DPCRE2_CODE_UNIT_WIDTH=8 \\
64+
-DHAVE_MEMMOVE
65+
66+
PCRE_SRCS = $ngx_pcre_srcs
67+
PCRE_OBJS = $ngx_pcre_objs
68+
69+
$PCRE/src/pcre2.h:
70+
cd $PCRE/src \\
71+
&& copy /y config.h.generic config.h \\
72+
&& copy /y pcre2.h.generic pcre2.h \\
73+
&& copy /y pcre2_chartables.c.dist pcre2_chartables.c
74+
75+
$PCRE/src/pcre2-8.lib: $PCRE/src/pcre2.h $NGX_MAKEFILE
76+
cd $PCRE/src \\
77+
&& cl -nologo -c \$(PCRE_CFLAGS) -I . \$(PCRE_FLAGS) \$(PCRE_SRCS) \\
78+
&& link -lib -out:pcre2-8.lib -verbose:lib \$(PCRE_OBJS)
779

8-
msvc)
9-
ngx_makefile=makefile.msvc
10-
ngx_opt="CPU_OPT=\"$CPU_OPT\" LIBC=$LIBC"
11-
ngx_pcre="PCRE=\"$PCRE\""
12-
;;
80+
END
81+
82+
else
83+
84+
cat << END >> $NGX_MAKEFILE
1385

14-
owc)
15-
ngx_makefile=makefile.owc
16-
ngx_opt="CPU_OPT=\"$CPU_OPT\""
17-
ngx_pcre=`echo PCRE=\"$PCRE\" | sed -e "s/\//$ngx_regex_dirsep/g"`
18-
;;
86+
$PCRE/src/pcre2.h: $PCRE/Makefile
87+
88+
$PCRE/Makefile: $NGX_MAKEFILE
89+
cd $PCRE \\
90+
&& if [ -f Makefile ]; then \$(MAKE) distclean; fi \\
91+
&& CC="\$(CC)" CFLAGS="$PCRE_OPT" \\
92+
./configure --disable-shared $PCRE_CONF_OPT
1993

20-
bcc)
21-
ngx_makefile=makefile.bcc
22-
ngx_opt="-DCPU_OPT=\"$CPU_OPT\""
23-
ngx_pcre=`echo \-DPCRE=\"$PCRE\" | sed -e "s/\//$ngx_regex_dirsep/g"`
24-
;;
94+
$PCRE/.libs/libpcre2-8.a: $PCRE/Makefile
95+
cd $PCRE \\
96+
&& \$(MAKE) libpcre2-8.la
2597

26-
*)
27-
ngx_makefile=
28-
;;
98+
END
2999

30-
esac
100+
fi
31101

32102

33-
if [ -n "$ngx_makefile" ]; then
103+
else
34104

35-
cat << END >> $NGX_MAKEFILE
105+
# PCRE
106+
107+
case "$NGX_CC_NAME" in
108+
109+
msvc)
110+
ngx_makefile=makefile.msvc
111+
ngx_opt="CPU_OPT=\"$CPU_OPT\" LIBC=$LIBC"
112+
ngx_pcre="PCRE=\"$PCRE\""
113+
;;
114+
115+
owc)
116+
ngx_makefile=makefile.owc
117+
ngx_opt="CPU_OPT=\"$CPU_OPT\""
118+
ngx_pcre=`echo PCRE=\"$PCRE\" | sed -e "s/\//$ngx_regex_dirsep/g"`
119+
;;
120+
121+
bcc)
122+
ngx_makefile=makefile.bcc
123+
ngx_opt="-DCPU_OPT=\"$CPU_OPT\""
124+
ngx_pcre=`echo \-DPCRE=\"$PCRE\" \
125+
| sed -e "s/\//$ngx_regex_dirsep/g"`
126+
;;
127+
128+
*)
129+
ngx_makefile=
130+
;;
131+
132+
esac
133+
134+
135+
if [ -n "$ngx_makefile" ]; then
136+
137+
cat << END >> $NGX_MAKEFILE
36138

37139
`echo "$PCRE/pcre.lib: $PCRE/pcre.h $NGX_MAKEFILE" \
38140
| sed -e "s/\//$ngx_regex_dirsep/g"`
@@ -43,9 +145,9 @@ if [ -n "$ngx_makefile" ]; then
43145

44146
END
45147

46-
else
148+
else
47149

48-
cat << END >> $NGX_MAKEFILE
150+
cat << END >> $NGX_MAKEFILE
49151

50152
$PCRE/pcre.h: $PCRE/Makefile
51153

@@ -61,4 +163,6 @@ $PCRE/.libs/libpcre.a: $PCRE/Makefile
61163

62164
END
63165

166+
fi
167+
64168
fi

auto/options

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ PCRE=NONE
146146
PCRE_OPT=
147147
PCRE_CONF_OPT=
148148
PCRE_JIT=NO
149+
PCRE2=YES
149150

150151
USE_OPENSSL=NO
151152
OPENSSL=NONE
@@ -357,6 +358,7 @@ use the \"--with-mail_ssl_module\" option instead"
357358
--with-pcre=*) PCRE="$value" ;;
358359
--with-pcre-opt=*) PCRE_OPT="$value" ;;
359360
--with-pcre-jit) PCRE_JIT=YES ;;
361+
--without-pcre2) PCRE2=DISABLED ;;
360362

361363
--with-openssl=*) OPENSSL="$value" ;;
362364
--with-openssl-opt=*) OPENSSL_OPT="$value" ;;
@@ -573,6 +575,7 @@ cat << END
573575
--with-pcre=DIR set path to PCRE library sources
574576
--with-pcre-opt=OPTIONS set additional build options for PCRE
575577
--with-pcre-jit build PCRE with JIT compilation support
578+
--without-pcre2 do not use PCRE2 library
576579

577580
--with-zlib=DIR set path to zlib library sources
578581
--with-zlib-opt=OPTIONS set additional build options for zlib

auto/summary

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ if [ $USE_PCRE = DISABLED ]; then
1616

1717
else
1818
case $PCRE in
19-
YES) echo " + using system PCRE library" ;;
19+
YES) echo " + using system $PCRE_LIBRARY library" ;;
2020
NONE) echo " + PCRE library is not used" ;;
21-
*) echo " + using PCRE library: $PCRE" ;;
21+
*) echo " + using $PCRE_LIBRARY library: $PCRE" ;;
2222
esac
2323
fi
2424

0 commit comments

Comments
 (0)
0