解剖Nginx·自动脚本篇(7)类型相关脚本系列
2012-03-16 00:10
2883 查看
解剖 Nginx·自动脚本篇(7)类型相关脚本系列
Author: PoechantBlog: blog.CSDN.net/Poechant
Email: zhongchao.ustc#gmail.com (#->@)
Date: March 12th, 2012
Copyright © 柳大·Poechant
1 auto/types/sizeof
该脚本的功能,是通过测试程序获知给定的ngx_type的大小。
1.1 显示提示信息
echo $ngx_n "checking for $ngx_type size ...$ngx_c" cat << END >> $NGX_AUTOCONF_ERR ---------------------------------------- checking for $ngx_type size END
1.2 生成计算ngx_type
的测试程序
cat << END > $NGX_AUTOTEST.c #include <sys/types.h> #include <sys/time.h> $NGX_INCLUDE_UNISTD_H #include <signal.h> #include <sys/resource.h> $NGX_INCLUDE_INTTYPES_H $NGX_INCLUDE_AUTO_CONFIG_H int main() { printf("%d", sizeof($ngx_type)); return 0; } END
1.3 编译测试程序
首先生成编译的命令。ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \ -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"注意
-o $NGX_AUTOTEST是生成可执行文件,然后执行编译。
eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
1.4 运行测试程序,得到ngx_size
如果NGX_AUTOTEST文件存在且可执行,则设定
ngx_size大小。
ngx_size= if [ -x $NGX_AUTOTEST ]; then ngx_size=`$NGX_AUTOTEST` echo " $ngx_size bytes" fi
1.5 删除NGX_AUTOTEST
测试程序可执行文件
rm -f $NGX_AUTOTEST
1.6 设定整数最大值
分别处理 32 位系统的数据大小和 64 位系统的数据大小,设定整数最大值。其他情况作为错误处理。case $ngx_size in 4) if [ "$ngx_type"="long" ]; then ngx_max_value=2147483647L else ngx_max_value=2147483647 fi ngx_max_len='(sizeof("-2147483648") - 1)' ;; 8) if [ "$ngx_type"="long long" ]; then ngx_max_value=9223372036854775807LL else ngx_max_value=9223372036854775807L fi ngx_max_len='(sizeof("-9223372036854775808") - 1)' ;; *) echo echo "$0: error: can not detect $ngx_type size" echo "----------" >> $NGX_AUTOCONF_ERR cat $NGX_AUTOTEST.c >> $NGX_AUTOCONF_ERR echo "----------" >> $NGX_AUTOCONF_ERR echo $ngx_test >> $NGX_AUTOCONF_ERR echo "----------" >> $NGX_AUTOCONF_ERR exit 1 esac
2 auto/types/typedef
通过两个循环,分别处理ngx_type和
ngx_types。向
objs/ngx_auto_config.h文件写入
typedef定义。
2.1 生成测试程序
cat << END > $NGX_AUTOTEST.c #include <sys/types.h> #include <signal.h> #include <sys/socket.h> #include <sys/time.h> #include <sys/resource.h> #include <netinet/in.h> $NGX_INCLUDE_INTTYPES_H int main() { $ngx_try i = 0; return 0; } END
2.2 编译测试程序
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
2.3 设置ngx_found
值
if [ -x $NGX_AUTOTEST ]; then if [ $ngx_try = $ngx_type ]; then echo " found" ngx_found=yes else echo ", $ngx_try used" ngx_found=$ngx_try fi fi
2.4 删除测试程序可执行文件
rm -f $NGX_AUTOTEST
2.5 异常情况
if [ $ngx_found = no ]; then echo $ngx_n " $ngx_try not found$ngx_c" echo "----------" >> $NGX_AUTOCONF_ERR cat $NGX_AUTOTEST.c >> $NGX_AUTOCONF_ERR echo "----------" >> $NGX_AUTOCONF_ERR echo $ngx_test >> $NGX_AUTOCONF_ERR echo "----------" >> $NGX_AUTOCONF_ERR else break fi到此循环就结束了。然后:
if [ $ngx_found = no ]; then echo echo "$0: error: can not define $ngx_type" exit 1 fi
2.6 将typedef
语句写入objs/ngx_auto_config.h
ngx_found是原类型,
ngx_type是别名类型。
if [ $ngx_found != yes ]; then echo "typedef $ngx_found $ngx_type;" >> $NGX_AUTO_CONFIG_H fi
3 auto/types/value
这与auto/define有些类似,但
auto/define表示“设置了 K 值,其值为 V”,与“没有设置 K 值”相对。而
auto/types/value是设置任意参数和其值。
cat << END >> $NGX_AUTO_CONFIG_H #ifndef $ngx_param #define $ngx_param $ngx_value #endif END
4 auto/types/uintptr_t
4.1 提示
echo $ngx_n "checking for uintptr_t ...$ngx_c" echo >> $NGX_ERR echo "checking for uintptr_t" >> $NGX_ERR
4.2 生成测试程序
cat << END > $NGX_AUTOTEST.c #include <sys/types.h> $NGX_INTTYPES_H int main() { uintptr_t i = 0; return 0; } END
4.3 编译测试程序
found=no eval "$CC -o $NGX_AUTOTEST $NGX_AUTOTEST.c >> $NGX_ERR 2>&1" if [ -x $NGX_AUTOTEST ]; then echo " uintptr_t found" found=yes else echo $ngx_n " uintptr_t not found" $ngx_c fi
4.4 删除测试程序可执行文件
rm $NGX_AUTOTEST*
4.5 无可执行文件时的处理
if [ $found = no ]; then found="uint`expr 8 \* $ngx_ptr_size`_t" echo ", $found used" echo "typedef $found uintptr_t;" >> $NGX_AUTO_CONFIG_H echo "typedef $found intptr_t;" | sed -e 's/u//g' >> $NGX_AUTO_CONFIG_H fi-转载请注明来自“柳大·Poechant的CSDN博客”:blog.CSDN.net/Poechant-
相关文章推荐
- 解剖Nginx·自动脚本篇(7)类型相关脚本系列
- 解剖Nginx·自动脚本篇(5)编译器相关主脚本
- 解剖Nginx·自动脚本篇(4)工具型脚本系列
- 解剖Nginx·自动脚本篇(4)工具型脚本系列
- 解剖Nginx·自动脚本篇(7)类型相关脚本系列
- 解剖 Nginx ·自动脚本篇(3)源码相关变量脚本 auto/sources
- 解剖Nginx·自动脚本篇(3)源码相关变量脚本 auto/sources
- 解剖Nginx·自动脚本篇(6)编译器名称变量脚本 auto/cc/name
- 解剖 Nginx ·自动脚本篇(2)设置初始变量脚本 auto/init
- 解剖Nginx·自动脚本篇(6)编译器名称变量脚本 auto/cc/name
- 解剖Nginx·自动脚本篇(1)解析配置选项脚本 auto/options
- 解剖Nginx·自动脚本篇(1)解析配置选项脚本 auto/options
- 解剖Nginx·自动脚本篇(1)解析配置选项脚本 auto/options
- 解剖Nginx·自动脚本篇(2)设置初始变量脚本 auto/init
- 解剖Nginx·自动脚本篇(7)类型相关脚本系列
- 解剖Nginx·自动脚本篇(3)源码相关变量脚本 auto/sources
- 解剖Nginx·自动脚本篇(4)工具型脚本系列
- 解剖Nginx·自动脚本篇(5)编译器相关主脚本
- 解剖Nginx·模块开发篇(3)ngx_http_hello_world_module 模块的基本函数实现
- 解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程