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
|
From: Samuel Martin <s.martin49@gmail.com>
Date: Tue, 4 Jul 2017 11:09:20 -0400
Subject: [PATCH] auto/type/sizeof: rework autotest to be cross-compilation
friendly
Rework the sizeof test to do the checks at compile time instead of at
runtime. This way, it does not break when cross-compiling for a
different CPU architecture.
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
Refresh for 1.8.0.
Signed-off-by: Danomi Manchego <danomimanchego123@gmail.com>
[martin@barkynet.com: Updated for 1.10.0]
Signed-off-by: Martin Bark <martin@barkynet.com>
Signed-off-by: Adam Duskett <Adamduskett@outlook.com>
Refresh for 1.12.0
---
auto/types/sizeof | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/auto/types/sizeof b/auto/types/sizeof
index 480d8cfa49aa..61dcd2de5d44 100644
--- a/auto/types/sizeof
+++ b/auto/types/sizeof
@@ -14,7 +14,7 @@ END
ngx_size=
-cat << END > $NGX_AUTOTEST.c
+cat << _EOF > $NGX_AUTOTEST.c
#include <sys/types.h>
#include <sys/time.h>
@@ -25,22 +25,41 @@ $NGX_INCLUDE_UNISTD_H
$NGX_INCLUDE_INTTYPES_H
$NGX_INCLUDE_AUTO_CONFIG_H
-int main(void) {
- printf("%d", (int) sizeof($ngx_type));
+#if !defined( PASTE)
+#define PASTE2( x, y) x##y
+#define PASTE( x, y) PASTE2( x, y)
+#endif /* PASTE */
+
+#define SAY_IF_SIZEOF( typename, type, size) \\
+ static char PASTE( PASTE( PASTE( sizeof_, typename), _is_), size) \\
+ [(sizeof(type) == (size)) ? 1 : -1]
+
+SAY_IF_SIZEOF(TEST_TYPENAME, TEST_TYPE, TEST_SIZE);
+
+int main(void)
+{
return 0;
}
-END
+_EOF
-ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
- -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
+_ngx_typename=`echo "$ngx_type" | sed 's/ /_/g;s/\*/p/'`
+ngx_size="-1"
+ngx_size=`for i in 1 2 4 8 16 ; do \
+ $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
+ -DTEST_TYPENAME="$_ngx_typename" -DTEST_TYPE="$ngx_type" -DTEST_SIZE="$i" \
+ $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
+ $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 || continue ;\
+ echo $i ; break ; done`
-eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
+rm -rf $NGX_AUTOTEST*
+if test -z $ngx_size ; then
+ ngx_size=-1
+fi
-if [ -x $NGX_AUTOTEST ]; then
- ngx_size=`$NGX_AUTOTEST`
+if [ $ngx_size -gt 0 ]; then
echo " $ngx_size bytes"
fi
|