1平台
1.1编译boa源代码平台:
1.1.1硬件平台:
主机:Think pad T400
1.1.2软件环境:
系统:ubuntu11.10_64bit(已搭建好android4.0编译环境)
交叉编译器版本:arm-linux-gcc 4.5.1
android源代码:友善之臂smart210配套android4.0.3_r1(已在本平台成功编译)
1.2boa服务器平台:
1.2.1硬件平台:
smart210开发板
1.2.1软件平台:
android4.0.3
1.2.3源代码版本
过程跟踪
2014/1/7 10/42AM:到该网址http://www.boa.org/下载boa-0.94.13版本源代码
10/46AM:将boa源代码解压并移到android源代码的external目录下,指令如下
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external# mv /home/luosuo/Desktop/boa ./boa
10/51AM:在boa/src目录下执行如下命令产生Makefile文件
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/boa/src# ./configure
10/54AM:在boa/src目录下执行如下命令生成 y.tab.c y.tab.h文件
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/boa/src# bison -y -d boa_grammar.y
制作并编译boa模块
11/01AM:在boa/src目录下执行如下命令生成 lex.yy.c文件
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/boa/src# flex boa_lexer.l
11/05AM:在boa目录下编写Android.mk文件,内容如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
#使用的源文件
LOCAL_SRC_FILES:= \
src/lex.yy.c \
src/y.tab.c \
src/alias.c \
src/boa.c \
src/buffer.c \
src/cgi.c \
src/cgi_header.c \
src/config.c \
src/escape.c \
src/get.c \
src/hash.c \
src/ip.c \
src/log.c \
src/mmap_cache.c \
src/pipe.c \
src/queue.c \
src/read.c \
src/request.c \
src/response.c \
src/select.c \
src/signals.c \
src/util.c \
src/sublog.c \
src/timestamp.c
LOCAL_CFLAGS:= -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wcast-qual\
-Wtraditional\
-Wshadow\
-Wconversion\
-Waggregate-return\
-Wmissing-prototypes\
-Wnested-externs\
-Wall \
-Wundef -Wwrite-strings -Wredundant-decls -Winline
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
#生成的对像
LOCAL_MODULE:=boa
include $(BUILD_EXECUTABLE)
11/10AM:回到android源代码跟目录准备编译boa
11/14AM:编译,指令如下
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# source build/envsetup.sh
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# export TARGET_PRODUCT=full_mini210
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make boa
编译中.......
11/20AM:提示出现一错误,导致编译过程退出。终端显示太多的警告,忽略警告信息,找到那一条错误信息,如下:
external/boa/src/compat.h:35:23: error: sys/fcntl.h: No such file or directory
百度/google上贴处此条信息,原因归纳:
android平台标准c库中有许多头文件并非存放在标准位置(linux中存放的位置)故我们需要找到android下fcntl.h文件所在位置,采用如下指令查找:
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# find -name fcntl.h
搜索到好多路径,其中有一条如下
./bionic/libc/include/fcntl.h
由此将compat.h文件中的‘ #include <sys/fcntl.h>’替换成‘#include <fcntl.h>’,保存
11/40AM:然后执行如下指令重新编译:
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make boa
编译中...
11/40AM:提示出现一错误,导致编译退出,终端同样显示太多的警告,忽略警告信息,找到那一条错误信息,如下:
external/boa/src/util.c:100:1: error: pasting "t" and "->" does not give a valid preprocessing token
百度/google上贴处此条信息,做如下修改:
将compat.h文件中的‘#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff’替换成‘#define TIMEZONE_OFFSET(foo) foo->tm_gmtoff’,保存(即去掉那两个‘#’)
11/46AM:然后执行如下指令重新编译:
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make boa
编译中...
11/48AM:编译完成,终端提示信息如下:
target Executable: boa (out/target/product/mini210/obj/EXECUTABLES/boa_intermediates/LINKED/boa)
target Symbolic: boa (out/target/product/mini210/symbols/system/xbin/boa)
target Strip: boa (out/target/product/mini210/obj/EXECUTABLES/boa_intermediates/boa)
Install: out/target/product/mini210/system/xbin/boa
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled#
制作并编译boa_indexer模块
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
#使用的源文件
LOCAL_SRC_FILES:= \
src/index_dir.c \
src/escape.c
LOCAL_SHARED_LIBRARIES := \
libcutils \
LOCAL_CFLAGS:= -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wcast-qual\
-Wtraditional\
-Wshadow\
-Wconversion\
-Waggregate-return\
-Wmissing-prototypes\
-Wnested-externs\
-Wall \
-Wundef -Wwrite-strings -Wredundant-decls -Winline
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
#生成的对像
LOCAL_MODULE:=boa_indexer
include $(BUILD_EXECUTABLE)
11/59AM:执行如下指令编译boa_indexer模块
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make boa_indexer
12/00PM:终端提示一错误,导致编译过程退出,找到错误信息,如下所示。(太多的警告信息,忽略)
external/boa/src/index_dir.c:195: error: 'MAXNAMLEN' undeclared (first use in this function)
external/boa/src/index_dir.c:195: error: (Each undeclared identifier is reported only once
external/boa/src/index_dir.c:195: error: for each function it appears in.)
MAXNAMLEN未定义问题
提示说,index_dir.c文件中的MAXNAMLEN未定义,随后我在其他文件中也没有找到,此时又想起之前将boa移植到linux平台(实际并没有移植,只是编译了一下boa源代码)时对boa进行编译就没有这个错误,可能是因为平台的原因,于是在linux平台写了个程序,打算直接输出‘MAXNAMLEN’的值,主程序文件名为main.c内容如下:#include <stdio.h>
#include <sys/stat.h>
#include <limits.h> /* for PATH_MAX */
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "compat.h"
#define LUOSUO
#define MAX_FILE_LENGTH MAXNAMLEN
#define TMP 2562
int main()
{
printf("%d %d %d\n", MAX_FILE_LENGTH,TMP,LUOSUO);
exit(0);
}
同时将boa/src目录下的 compat.h config.h文件拷贝到main.c所在的目录
luosuo@ubuntu:~/Documents/boaforandroid/MAXNAMLEN的值$ gcc -o MAXNAMLEN main.c
编译出错,信息如下:
luosuo@ubuntu:~/Documents/boaforandroid/MAXNAMLEN的值$ gcc -o MAXNAMLEN main.c
main.c: In function 'main':
main.c:17:49: error: expected expression before ')' token
将main.c文件中的‘#define LUOSUO’还有主函数中的printf("%d %d
%d\n", MAX_FILE_LENGTH,TMP
,LUOSUO)红色字体去掉,保存
luosuo@ubuntu:~/Documents/boaforandroid/MAXNAMLEN的值$ gcc -o MAXNAMLEN main.c
12/26PM:在终端运行此程序,显示如下:
luosuo@ubuntu:~/Documents/boaforandroid/MAXNAMLEN的值$ ./MAXNAMLEN
255 2562
luosuo@ubuntu:~/Documents/boaforandroid/MAXNAMLEN的值$
由此可知MAXNAMLEN值为255
#define MAXNAMLEN 255
12/40PM:使用如下指令重新编译boa_indexer模块
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make boa_indexer
12/45PM:编译完成,终端信息如下:
target Executable: boa_indexer (out/target/product/mini210/obj/EXECUTABLES/boa_indexer_intermediates/LINKED/boa_indexer)
target Symbolic: boa_indexer (out/target/product/mini210/symbols/system/xbin/boa_indexer)
target Strip: boa_indexer (out/target/product/mini210/obj/EXECUTABLES/boa_indexer_intermediates/boa_indexer)
Install: out/target/product/mini210/system/xbin/boa_indexer
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled#
修改boa.conf文件内容
创建相应目录
/system/etc # mkdir boa
2,创建/etc/boa/log目录
/system/etc/boa # mkdir log
3,创建/etc/boa/www目录
/system/etc/boa # mkdir www
4,创建/etc/boa/www/cgi-bin目录
/system/etc/boa/www # mkdir cgi-bin
拷贝文件到目标机
1,将之前编译的boa文件拷贝到目标板的/etc/boa目录中
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/out/target/product/mini210/system/xbin# adb push boa /etc/boa
1850 KB/s (52320 bytes in 0.027s)
2,将之前编译的boa_indexer文件拷贝到目标板的/etc/boa目录中
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/out/target/product/mini210/system/xbin# adb push boa_indexer /etc/boa
204 KB/s (9832 bytes in 0.046s)
3,将ubuntu文件系统/etc目录下的mime.types文件拷贝到目标板的/etc/boa目录下
root@ubuntu:/etc# adb push mime.types /etc/boa
463 KB/s (23958 bytes in 0.050s)
4,将boa目录下的boa.conf文件拷贝到目标板的/etc/boa目录下
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/boa# adb push boa.conf /etc/boa
155 KB/s (7365 bytes in 0.046s)
5,拷贝一静态html文件到/etc/boa/www目录下。
luosuo@ubuntu:~/Documents/boaforandroid$ adb push CSDN.NET.html /etc/boa/www
491 KB/s (27271 bytes in 0.054s)
服务器搭建完毕,准备测试
2,启动目标板上的boa服务器
/system/etc/boa # ./boa
3,在PC机的浏览器地址栏输入:10.192.22.208/CSDN.NET.html ,点击Enter键
准备测试CGI功能:涉及The CGI was not CGI/1.1 compliant.问题及其解决方法
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head><title>CGI Output</title></head>\n");
printf("<body>\n");
printf("<h1>Hello,world.</h1>\n");
printf("<body>\n");
printf("</html>\n");
exit(0);
}
3/57PM:采用如下指令编译
luosuo@ubuntu:~/Desktop$ arm-linux-gcc CGI_test.c -o CGI_test_D
4/01PM:将生成的可执行程序拷贝到目标板的/etc/boa/www/cgi-bin目录下
luosuo@ubuntu:~/Desktop$ adb push CGI_test_D /etc/boa/www/cgi-bin
166 KB/s (7855 bytes in 0.045s)
4/04PM:在目标板上直接运行该程序,运行命令及运行情况如下
/system/etc/boa/www/cgi-bin # ls
CGI_test_D
/system/etc/boa/www/cgi-bin # ./CGI_test_D
/system/bin/sh: ./CGI_test_D: not found
/system/etc/boa/www/cgi-bin #
502 Bad Gateway
The CGI was not CGI/1.1 compliant.luosuo@ubuntu:~/Desktop$ arm-linux-gcc -static CGI_test.c -o CGI_test_S
4/12PM:将生成的可执行程序拷贝到目标板的/etc/boa/www/cgi-bin目录下(
注意生成的可执行文件大小,与上一次编译的可执行文件大小作比较)
luosuo@ubuntu:~/Desktop$ adb push CGI_test_S /etc/boa/www/cgi-bin
2557 KB/s (611663 bytes in 0.233s)
4/14PM:在目标板上直接运行该程序,运行命令及运行情况如下
/system/etc/boa/www/cgi-bin # ls
CGI_test_D
CGI_test_S
/system/etc/boa/www/cgi-bin # ./CGI_test_S
Content-type: text/html
<html>
<head><title>CGI Output</title></head>
<body>
<h1>Hello,world.</h1>
<body>
</html>
/system/etc/boa/www/cgi-bin #
直接运行成功,
Hello,world.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head><title>CGI Output</title></head>\n");
printf("<body>\n");
printf("<h1>Hello,world.</h1>\n");
printf("<body>\n");
printf("</html>\n");
exit(0);
}
Android.mk文件内容如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
#使用的源文件
LOCAL_SRC_FILES:=\
main.c
LOCAL_CFLAGS:=-O2 -g
#LOCAL_CFLAGS+=-DLINUX
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
#生成的对像
LOCAL_MODULE:=CGI_test_M
include $(BUILD_EXECUTABLE)
4/51PM:编译该模块
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make CGI_test_M
4/52PM:编译完成,终端输出信息如下:
target thumb C: CGI_test_M <= external/cgi/main.c
target Executable: CGI_test_M (out/target/product/mini210/obj/EXECUTABLES/CGI_test_M_intermediates/LINKED/CGI_test_M)
target Symbolic: CGI_test_M (out/target/product/mini210/symbols/system/xbin/CGI_test_M)
target Strip: CGI_test_M (out/target/product/mini210/obj/EXECUTABLES/CGI_test_M_intermediates/CGI_test_M)
Install: out/target/product/mini210/system/xbin/CGI_test_M
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled#
4/53PM:将该可执行文件拷贝到目标板的/etc/boa/www/cgi-bin目录下(
注意文件的大小,明显比前两次得到的可执行文件都要小)
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/out/target/product/mini210/system/xbin# adb push CGI_test_M /etc/boa/www/cgi-bin
118 KB/s (5516 bytes in 0.045s)
4/57PM:直接在目标板运行,指令及运行结果如下
/system/etc/boa/www/cgi-bin # ls
CGI_test_D
CGI_test_M
CGI_test_S
/system/etc/boa/www/cgi-bin # ./CGI_test_M
Content-type: text/html
<html>
<head><title>CGI Output</title></head>
<body>
<h1>Hello,world.</h1>
<body>
</html>
/system/etc/boa/www/cgi-bin #
直接运行OK
Hello,world.
浏览器测试OK![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)