1 From 81289d1d1adaf5a767a4b4d1309c286468cfd37f Mon Sep 17 00:00:00 2001
2 From: Samuel Martin <s.martin49@gmail.com>
3 Date: Thu, 24 Apr 2014 23:27:32 +0200
4 Subject: [PATCH 1/5] auto/type/sizeof: rework autotest to be cross-compilation
7 Rework the sizeof test to do the checks at compile time instead of at
8 runtime. This way, it does not break when cross-compiling for a
9 different CPU architecture.
11 Signed-off-by: Samuel Martin <s.martin49@gmail.com>
13 auto/types/sizeof | 42 ++++++++++++++++++++++++++++--------------
14 1 file changed, 28 insertions(+), 14 deletions(-)
16 diff --git a/auto/types/sizeof b/auto/types/sizeof
17 index 9215a54..c2c3ede 100644
18 --- a/auto/types/sizeof
19 +++ b/auto/types/sizeof
24 -cat << END > $NGX_AUTOTEST.c
25 +cat << _EOF > $NGX_AUTOTEST.c
27 #include <sys/types.h>
29 @@ -25,29 +25,43 @@ $NGX_INCLUDE_UNISTD_H
30 $NGX_INCLUDE_INTTYPES_H
31 $NGX_INCLUDE_AUTO_CONFIG_H
34 - printf("%d", (int) sizeof($ngx_type));
36 +#define PASTE2( x, y) x##y
37 +#define PASTE( x, y) PASTE2( x, y)
40 +#define SAY_IF_SIZEOF( typename, type, size) \\
41 + static char PASTE( PASTE( PASTE( sizeof_, typename), _is_), size) \\
42 + [(sizeof(type) == (size)) ? 1 : -1]
44 +SAY_IF_SIZEOF(TEST_TYPENAME, TEST_TYPE, TEST_SIZE);
55 -ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
56 - -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
57 +_ngx_typename=`echo "$ngx_type" | sed 's/ /_/g;s/\*/p/'`
59 +ngx_size=`for i in 1 2 4 8 16 ; do \
60 + $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
61 + -DTEST_TYPENAME="$_ngx_typename" -DTEST_TYPE="$ngx_type" -DTEST_SIZE="$i" \
62 + $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
63 + $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 || continue ;\
64 + echo $i ; break ; done`
66 -eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
67 +rm -rf $NGX_AUTOTEST*
69 +if test -z $ngx_size ; then
73 -if [ -x $NGX_AUTOTEST ]; then
74 - ngx_size=`$NGX_AUTOTEST`
75 +if [ $ngx_size -gt 0 ]; then
76 echo " $ngx_size bytes"
80 -rm -rf $NGX_AUTOTEST*
85 if [ "$ngx_type"="long" ]; then