0005-auto-unix-make-sys_nerr-guessing-cross-friendly.patch
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
From 08617a8d29ee22831175697555558fec8f52772c Mon Sep 17 00:00:00 2001
From: Samuel Martin <s.martin49@gmail.com>
Date: Sun, 1 Jun 2014 16:05:04 +0200
Subject: [PATCH] auto/unix: make sys_nerr guessing cross-friendly
This patch replaces the default sys_nerr runtest with a test done at
buildtime.
The idea behind this buildtime test is finding the value of the ERR_MAX
macro if defined, or the EHWPOISON (which is currently the last errno)
otherwise.
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
Refresh for 1.8.0.
Signed-off-by: Danomi Manchego <danomimanchego123@gmail.com>
---
auto/os/sys_nerr | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
auto/unix | 10 ++++++++
2 files changed, 88 insertions(+)
create mode 100644 auto/os/sys_nerr
diff --git a/auto/os/sys_nerr b/auto/os/sys_nerr
new file mode 100644
index 0000000..8970f5f
--- /dev/null
+++ b/auto/os/sys_nerr
@@ -0,0 +1,78 @@
+
+# Copyright (C) Samuel Martin <s.martin49@gmail.com>
+
+
+echo $ngx_n "checking for sys_nerr value...$ngx_c"
+
+# sys_nerr guessing is done using a (very) poor (but working)
+# heuristics, by checking for the value of ERR_MAX if defined, or
+# EHWPOISON otherwise.
+
+cat << END >> $NGX_AUTOCONF_ERR
+
+----------------------------------------
+checking for sys_nerr value
+
+END
+
+ngx_sys_nerr=
+
+cat << _EOF > $NGX_AUTOTEST.c
+
+#include <stdio.h>
+#include <errno.h>
+
+static char sys_nerr_test[ERR_MAX];
+int main(void)
+{
+ return 0;
+}
+
+_EOF
+
+if $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
+ $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
+ $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 ; then
+ _ngx_max_err_macro=ERR_MAX
+else
+ # the +2 has been empirically found!
+ _ngx_max_err_macro="EHWPOISON + 2"
+fi
+
+cat << _EOF > $NGX_AUTOTEST.c
+
+#include <stdio.h>
+#include <errno.h>
+
+static char sys_nerr_test[(TEST_ERR_MAX == $_ngx_max_err_macro) ? 1 : -1];
+int main(void)
+{
+ return 0;
+}
+
+_EOF
+
+
+ngx_sys_nerr=`for i in $(seq 0 2000) ; do \
+ $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
+ -DTEST_ERR_MAX="$i" \
+ $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
+ $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 || continue ;\
+ echo $i ; break ; done`
+
+rm -rf $NGX_AUTOTEST*
+
+if test -z $ngx_sys_nerr ; then
+ ngx_size=0
+ ngx_sys_nerr=0
+fi
+
+cat << END >> $NGX_AUTO_CONFIG_H
+
+#ifndef $ngx_feature_name
+#define $ngx_feature_name $ngx_sys_nerr
+#endif
+
+END
+
+echo " $ngx_sys_nerr"
diff --git a/auto/unix b/auto/unix
index 7dbf9d1..00a7370 100755
--- a/auto/unix
+++ b/auto/unix
@@ -595,6 +595,10 @@ ngx_feature_incs='#include <errno.h>
#include <stdio.h>'
ngx_feature_path=
ngx_feature_libs=
+
+if false ; then
+# Disabled because only valid for native build.
+
ngx_feature_test='printf("%d", sys_nerr);'
. auto/feature
@@ -643,6 +647,12 @@ if [ $ngx_found = no ]; then
. auto/feature
fi
+else
+ # Cross-compilation support
+ . auto/os/sys_nerr
+
+fi
+
ngx_feature="localtime_r()"
ngx_feature_name="NGX_HAVE_LOCALTIME_R"
--
1.9.1