[PATCH] Fix PCRE detection on OSX.
Piotr Sikora
piotr at cloudflare.com
Tue Dec 11 08:19:25 UTC 2012
Hey guys,
thanks for going into details why this happens, but to cut this
discussion short, I'll just focus on the patches.
> Index: auto/lib/pcre/conf
> ===================================================================
> --- auto/lib/pcre/conf (revision 4948)
> +++ auto/lib/pcre/conf (working copy)
> @@ -101,7 +101,17 @@
> ngx_feature_test="pcre *re;
> re = pcre_compile(NULL, 0, NULL, 0, NULL);
> if (re == NULL) return 1"
> - . auto/feature
> +
> + if [ "$NGX_SYSTEM" = "Darwin" ]; then
> + # Apple provides libpcre in /usr/lib but no /usr/include/pcre.h.
> + # This may interfere with libpcre installed into /usr/local if
> + # system compiler is used. To work around this, we delay the
> + # default test until after we tested /usr/local.
> + ngx_found=no
> +
> + else
> + . auto/feature
> + fi
>
> if [ $ngx_found = no ]; then
>
> @@ -119,6 +129,14 @@
> . auto/feature
> fi
>
> + if [ $ngx_found = no -a "$NGX_SYSTEM" = "Darwin" ]; then
> + ngx_feature="PCRE library"
> + ngx_feature_path=
> + ngx_feature_libs="-lpcre"
> +
> + . auto/feature
> + fi
> +
> if [ $ngx_found = no ]; then
>
> # RedHat RPM, Solaris package
I like this, it makes much more sense to defer the check instead of
completely skipping it.
> --- a/auto/lib/pcre/conf Mon Nov 26 18:01:49 2012 +0000
> +++ b/auto/lib/pcre/conf Mon Dec 10 18:21:53 2012 +0400
> @@ -172,6 +172,7 @@ else
> ngx_feature="PCRE JIT support"
> ngx_feature_name="NGX_HAVE_PCRE_JIT"
> ngx_feature_test="int jit = 0;
> + pcre_free_study(NULL);
> pcre_config(PCRE_CONFIG_JIT, &jit);
> if (jit != 1) return 1;"
> . auto/feature
>
> probably will be good enough. It will prevent build failures
> by checking if the code we are going to compile will compile.
>
> (Yes, I understand that it won't resolve the root cause, i.e. the
> library vs. headers mismatch. And yes, I understand that it will
> make PCRE JIT unavailable in some cases. I don't think we care
> though.)
While I agree that this is a better test for PCRE JIT presence and
that it should be included regardless of the OSX issue, I don't think
that this is solution to the problem at hand, because all it does is
hide the issue from the end user... Putting JIT capabilities aside, I
also dislike the fact that we might be throwing away almost 3 years of
PCRE fixes just because we cannot be bothered to link against newer
library that's available outside of the default search path... I
definitely prefer the solution with postponed check for the default
search path on OSX.
Alternatively, we could first try looking for the PCRE library with
JIT support and fallback to looking for the PCRE library without one:
diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf
index 6a8c326..4f75018 100644
--- a/auto/lib/pcre/conf
+++ b/auto/lib/pcre/conf
@@ -92,21 +92,101 @@ else
PCRE=NO
- ngx_feature="PCRE library"
- ngx_feature_name="NGX_PCRE"
+ ngx_feature="PCRE library with JIT support"
+ ngx_feature_name="NGX_HAVE_PCRE_JIT"
ngx_feature_run=no
ngx_feature_incs="#include <pcre.h>"
ngx_feature_path=
ngx_feature_libs="-lpcre"
ngx_feature_test="pcre *re;
+ int jit = 0;
re = pcre_compile(NULL, 0, NULL, 0, NULL);
- if (re == NULL) return 1"
+ if (re == NULL) return 1;
+ pcre_free_study(NULL);
+ pcre_config(PCRE_CONFIG_JIT, &jit);
+ if (jit != 1) return 1;"
. auto/feature
if [ $ngx_found = no ]; then
# FreeBSD port
+ ngx_feature="PCRE library with JIT support in /usr/local/"
+ ngx_feature_path="/usr/local/include"
+
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lpcre"
+ else
+ ngx_feature_libs="-L/usr/local/lib -lpcre"
+ fi
+
+ . auto/feature
+ fi
+
+ if [ $ngx_found = no ]; then
+
+ # RedHat RPM, Solaris package
+
+ ngx_feature="PCRE library with JIT support in /usr/include/pcre/"
+ ngx_feature_path="/usr/include/pcre"
+ ngx_feature_libs="-lpcre"
+
+ . auto/feature
+ fi
+
+ if [ $ngx_found = no ]; then
+
+ # NetBSD port
+
+ ngx_feature="PCRE library with JIT support in /usr/pkg/"
+ ngx_feature_path="/usr/pkg/include"
+
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lpcre"
+ else
+ ngx_feature_libs="-L/usr/pkg/lib -lpcre"
+ fi
+
+ . auto/feature
+ fi
+
+ if [ $ngx_found = no ]; then
+
+ # MacPorts
+
+ ngx_feature="PCRE library with JIT support in /opt/local/"
+ ngx_feature_path="/opt/local/include"
+
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lpcre"
+ else
+ ngx_feature_libs="-L/opt/local/lib -lpcre"
+ fi
+
+ . auto/feature
+ fi
+
+ if [ $ngx_found = yes ]; then
+ PCRE_JIT=YES
+ fi
+
+ if [ $ngx_found = no ]; then
+
+ ngx_feature="PCRE library"
+ ngx_feature_name="NGX_PCRE"
+ ngx_feature_path=
+ ngx_feature_libs="-lpcre"
+ ngx_feature_test="pcre *re;
+ re = pcre_compile(NULL, 0, NULL, 0, NULL);
+ if (re == NULL) return 1"
+
+ . auto/feature
+ fi
+
+ if [ $ngx_found = no ]; then
+
+ # FreeBSD port
+
ngx_feature="PCRE library in /usr/local/"
ngx_feature_path="/usr/local/include"
@@ -167,19 +247,6 @@ else
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
PCRE=YES
fi
-
- if [ $PCRE = YES ]; then
- ngx_feature="PCRE JIT support"
- ngx_feature_name="NGX_HAVE_PCRE_JIT"
- ngx_feature_test="int jit = 0;
- pcre_config(PCRE_CONFIG_JIT, &jit);
- if (jit != 1) return 1;"
- . auto/feature
-
- if [ $ngx_found = yes ]; then
- PCRE_JIT=YES
- fi
- fi
fi
if [ $PCRE != YES ]; then
but honestly, it seems like a bit of an overkill.
Best regards,
Piotr Sikora
More information about the nginx-devel
mailing list