我后来是通过shell来实现的。通过shell自动生成一个头文件fdfs_os_bits.h,头文件中通过宏OS_BITS来定义操作系统的位数(32或者64)。在Linux中已经调试通过。
shell代码片断如下:
tmp_src_filename=fdfs_check_bits.c
cat <<EOF > $tmp_src_filename
#include <stdio.h>
int main()
{
printf("%d/n", sizeof(long));
return 0;
}
EOF
cc $tmp_src_filename
bytes=`./a.out`
/bin/rm -f a.out $tmp_src_filename
if [ "$bytes" -eq 8 ]; then
OS_BITS=64
else
OS_BITS=32
fi
cat <<EOF > common/fdfs_os_bits.h
#ifndef _FDFS_OS_BITS
#define _FDFS_OS_BITS
#define OS_BITS $OS_BITS
#endif
EOF