解剖Nginx·自动脚本篇(7)类型相关脚本系列
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
-
解剖Nginx·自动脚本篇(7)类型相关脚本系列的更多相关文章
- 解剖Nginx·自动脚本篇(5)编译器相关主脚本
在 Nginx 的自动脚本中,auto/cc目录下的所有脚本都是用于编译器相关配置使用的.Nginx的出色跨平台性(Linux.Darwin.Solaris.Win32 等)就有这些脚本的贡献.该目录 ...
- 解剖Nginx·自动脚本篇(4)工具型脚本系列
目录 auto/have 向自动配置头文件追加可用宏定义(objs/ngx_auto_config.h) auto/nohave 向自动配置头文件追加不可用宏定义(objs/ngx_auto_conf ...
- 解剖Nginx·自动脚本篇(3)源码相关变量脚本 auto/sources
在configure脚本中,运行完auto/options和auto/init脚本后,接下来就运行auto/soures脚本.这个脚本是为编译做准备的. 目录 核心模块 事件模块 OpenSSL 模块 ...
- 解剖Nginx·自动脚本篇(1)解析配置选项脚本 auto/options
在安装Nginx之前(即运行make脚本之前),首先是进行安装的配置准备,包括环境检查及生成文件.这些工作是由自动脚本完成的.和绝大多数软件一样,Nginx的自动脚本的入口,同样是名为configur ...
- 解剖Nginx·自动脚本篇(2)设置初始变量脚本 auto/init
在configure中运行完auto/options脚本后,接着运行auto/init脚本,其中所做的工作如下. 1 Makefile文件名变量 默认情况下是: objs/Makefile 代码如下: ...
- 解剖Nginx·自动脚本篇(6)编译器名称变量脚本 auto/cc/name
回顾变量 CC 最初是在auto/options脚本中初始化的: CC=${CC:-gcc} 1 C Compiler 的 feature Windows 平台的编译器叫做MSVC,其他平台的都统称为 ...
- 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!
1 学习 Nginx 模块开发需要有哪些准备? 需要的预备知识不多,有如下几点: 有过一些 C 语言的编程经历: 知道 Nginx 是干嘛的,并有过编写或改写 Nginx 的配置文件的经历. OK,就 ...
- Loadrunder之脚本篇——参数类型
Internal data Date/Time,Group Name,Iteration Number,Load Generator Name,Ramdom Number,Table,Unique N ...
- 解剖Nginx·模块开发篇(5)解读内置非默认模块 ngx_http_stub_status_module
1 Background ngx_http_stub_status_module 是一个 Nginx 的内置 HTTP 模块,该模块可以提供 Nginx 的状态信息.默认情况下这个模块是不被编译进来的 ...
随机推荐
- openssl 查看证书细节
打印证书的过期时间 openssl x509 -in signed.crt -noout -dates 打印出证书的内容: openssl x509 -in cert.pem -noout -text ...
- win10安装.net3.5 报错解决
在win10光盘里提取“microsoft-windows-netfx3-ondemand-package.cab”安装包 然后放在sxs目录 新建批处理...??Cls@ECHO OFFTITLE ...
- angularJS控制器之间的相互通信方式、$broadcast、$emit、$on
在项目中,我们可能会很经常性的利用到控制器之间的相互通信,在angular中的控制器之间的相互通信有以下几种方式: 1)通过本地数据的存储localstorage,sessionstorage, 2) ...
- Python——while、continue、break、while-else、or、and、not
1. while 终止while循环: (1) 改变条件,使其不成立 (2) break 应用实例1:计算1+2+3+...+100 #1.使用两个变量 count = 1 sum = 0 while ...
- RK3288 修改设备默认的蓝牙名称
path:device/rockchip/rk3288/bluetooth/bdroid_buildcfg.h /* * Copyright (C) 2012 The Android Open Sou ...
- error: device not found
C:\Users\Administrator>adb shell error: device not found 出现上面情况,首先检查设备管理器中,安卓的驱动是否安装OK? 如果驱动 ...
- Windows运行命令集锦
开始菜单中的“运行”(Win+R)是通向程序的快捷途径,输入特定的命令后,即可快速的打开Windows的大部分程序,熟练的运用它,将给我们的操作带来诸多便捷. winver 检查Windows版本 ...
- golang调用动态库
测试动态库 test_so.h int test_so_func(int a,int b); test_so.c #include "test_so.h" int test_so_ ...
- 数组与指针的区别,以及在STL中传递数组/指针
数组和指针在作为实参传入T[] 或T*的形参时没有区别 void f(int pi[]) { cout << sizeof(pi) << endl; } int a[5] = ...
- C#(.Net)中调用Sql sever汉字字符串显示为?问号
利用Sql语言,向数据库中导入‘C语’,结果在检查的时候,发现如上图所示. 网络上,很多人说是编码问题,但是都没给出具体的解决方案,最终用这种方法解决了! 把上图中需要储存汉字字符串的类型变为 nva ...