Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5099037
  • 博文数量: 1160
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12568
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1160)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(183)

2011年(193)

2010年(138)

2009年(23)

分类: C/C++

2015-10-17 22:29:20

http://hamer-blog.logdown.com/posts/141723-how-to-port-lighttpd-to-android


Porting的過程是參考了
https://github.com/3ign0n/android-porting/tree/master/lighttpd

這次試驗的版本是 lighttpd 1.4.32, 可以從這邊download
http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.32.tar.bz2

Android 版本是 4.2.1
CPU: MIPS

首先自己的編譯環境需要先安裝 pcre dev 套件, 且你的host device上到時候也需要有pcre library (怎麼porting pcre, 請參考前一篇文章)

$ sudo apt-get install libpcre3-dev

設定好幾個環境變數

$ export ANDROID_DIR=/path/to/your/android/source/directory $ export PATH=$ANDROID_DIR/prebuilts/gcc/linux-x86/mips/mipsel-linux-android-4.6/bin:$PATH 

然後把lighttpd解壓縮到Android source的某個路徑, 比如說 devices/company/external
切到 lighttpd 資料匣, Apply patch, patch內容如下:

--- configure.orig 2013-09-27 09:52:17.164547221 +0800 +++ configure   2013-09-27 09:41:57.712559524 +0800 @@ -12461,11 +12461,12 @@  fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
 $as_echo "$ac_cv_header_stdc" >&6; } -if test $ac_cv_header_stdc = yes; then +# force to set 1
+#if test $ac_cv_header_stdc = yes; then  $as_echo "#define STDC_HEADERS 1" >>confdefs.h -fi +#fi  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sys/wait.h that is POSIX.1 compatible" >&5
 $as_echo_n "checking for sys/wait.h that is POSIX.1 compatible... " >&6; } @@ -12508,20 +12509,22 @@  fi +# Android surely has these headers except some, but autoconf doesn't detect them!!
+# excluded headers are, sys/devpoll.h sys/filio.h sys/event.h  sys/port.h uuid/uuid.h  for ac_header in arpa/inet.h fcntl.h netinet/in.h stdlib.h string.h \
 sys/socket.h sys/time.h unistd.h sys/sendfile.h sys/uio.h \ -getopt.h sys/epoll.h sys/select.h poll.h sys/poll.h sys/devpoll.h sys/filio.h \
-sys/mman.h sys/event.h port.h pwd.h sys/syslimits.h \
-sys/resource.h sys/un.h syslog.h sys/prctl.h uuid/uuid.h +getopt.h sys/epoll.h sys/select.h poll.h sys/poll.h \
+sys/mman.h pwd.h sys/syslimits.h \
+sys/resource.h sys/un.h syslog.h sys/prctl.h  do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : +#if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :  cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF -fi +#fi  done @@ -12683,6 +12686,7 @@  fi
 
 ac_fn_c_check_type "$LINENO" "off_t" "ac_cv_type_off_t" "$ac_includes_default" +ac_cv_type_off_t=yes  if test "x$ac_cv_type_off_t" = xyes; then :
 
 else @@ -12694,6 +12698,7 @@  fi
 
 ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default" +ac_cv_type_pid_t=yes  if test "x$ac_cv_type_pid_t" = xyes; then :
 
 else @@ -12705,6 +12710,7 @@  fi
 
 ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" +ac_cv_type_size_t=yes  if test "x$ac_cv_type_size_t" = xyes; then :
 
 else @@ -14462,6 +14468,9 @@  for ac_header in zlib.h
 do :
   ac_fn_c_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default" +# I have no idea to make ac_cv_header_zlib_h yes, but Android surely have zlib.
+# so I force to set "yes"
+ac_cv_header_zlib_h=yes  if test "x$ac_cv_header_zlib_h" = xyes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_ZLIB_H 1 @@ -16024,12 +16033,14 @@  do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" -if eval test \"x\$"$as_ac_var"\" = x"yes"; then : +# Android surely supports these functions, but autoconf cannot detect them
+# I don't know how to fix it, instead apply trickly workaround here
+#if eval test \"x\$"$as_ac_var"\" = x"yes"; then :  cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF -fi +#fi  done @@ -16074,6 +16085,8 @@  fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long" >&5 +# force to set 4
+ac_cv_sizeof_long=4  $as_echo "$ac_cv_sizeof_long" >&6; } @@ -16095,6 +16108,8 @@  if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (off_t))" "ac_cv_sizeof_off_t"        "$ac_includes_default"; then :
 
 else +  # no idea, checking sizeof off_t is failed
+  ac_cv_type_off_t=no  if test "$ac_cv_type_off_t" = yes; then
      { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} @@ -16110,7 +16125,8 @@  $as_echo "$ac_cv_sizeof_off_t" >&6; } - +# force to set 8
+ac_cv_sizeof_long=8  cat >>confdefs.h <<_ACEOF
 #define SIZEOF_OFF_T $ac_cv_sizeof_off_t  _ACEOF 

執行下述指令, 產生一些需要的檔案, 如config.h

./configure --host=mipsel-linux CC=mipsel-linux-android-gcc CPP=mipsel-linux-android-cpp CFLAGS="-nostdlib" CPPFLAGS="-I${ANDROID_DIR}/bionic/libc/include/ -I${ANDROID_DIR}/bionic/libc/arch-mips/include/ -I${ANDROID_DIR}/bionic/libc/kernel/common/  -I${ANDROID_DIR}/bionic/libc/kernel/common/linux -I${ANDROID_DIR}/bionic/libc/kernel/common/linux/ -I${ANDROID_DIR}/bionic/libc/kernel/arch-mips -I${ANDROID_DIR}/development/ndk/platforms/android-9/include -I${ANDROID_DIR}/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/include" LDFLAGS="-Wl,-rpath-link=${ANDROID_DIR}/out/target/product/saturn/system/lib -L${ANDROID_DIR}/out/target/product/saturn/system/lib -L${ANDROID_DIR}/out/target/products/system/lib" --without-bzip2

之後把Android.mk編寫好, 放在lighttpd的資料匣內, 內容如下, 目前的BUILD_OPTION_COMMON_SRC_STATIC只能被設成false, 如果設成true會有link error的情況.

LOCAL_PATH:= $(call my-dir) BUILD_OPTION_COMMON_SRC_STATIC := false BUILD_OPTION_COMMON_CFLAGS += -DHAVE_CONFIG_H -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src -D_REENTRANT -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -g -Wall BUILD_OPTION_COMMON_LDFLAGS += -lpcre COMMON_LIBNAME := lighttpd_common ####################################################################################
##common sources include $(CLEAR_VARS) LOCAL_MODULE := lib$(COMMON_LIBNAME) LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) -ldl LOCAL_SRC_FILES := \  src/buffer.c src/log.c src/keyvalue.c src/chunk.c \ src/http_chunk.c src/stream.c src/fdevent.c src/stat_cache.c src/plugin.c \ src/joblist.c src/etag.c src/array.c src/data_string.c src/data_count.c \ src/data_array.c src/data_integer.c src/md5.c src/data_fastcgi.c \ src/fdevent_select.c src/fdevent_libev.c src/fdevent_poll.c \ src/fdevent_linux_sysepoll.c src/fdevent_solaris_devpoll.c \ src/fdevent_solaris_port.c src/fdevent_freebsd_kqueue.c src/data_config.c \ src/bitset.c src/inet_ntop_cache.c src/crc32.c src/connections-glue.c \ src/configfile-glue.c src/http-header-glue.c src/network_write.c \ src/network_linux_sendfile.c src/network_freebsd_sendfile.c \ src/network_writev.c src/network_solaris_sendfilev.c src/network_openssl.c \ src/splaytree.c src/status_counter.c ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) include $(BUILD_SHARED_LIBRARY) else include $(BUILD_STATIC_LIBRARY) endif ####################################################################################
##mod_flv_streaming include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_flv_streaming.c LOCAL_MODULE := mod_flv_streaming LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_evasive include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_evasive.c LOCAL_MODULE := mod_evasive LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_webdav include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_webdav.c LOCAL_MODULE := mod_webdav LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_magnet include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_magnet.c \ src/mod_magnet_cache.c LOCAL_MODULE := mod_magnet LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_cml include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_cml.c \ src/mod_cml_lua.c \ src/mod_cml_funcs.c LOCAL_MODULE := mod_cml LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_trigger_b4_dl include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_trigger_b4_dl.c LOCAL_MODULE := mod_trigger_b4_dl LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_mysql_vhost include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  $(am__liblightcomp_la_SOURCES_DIST) \ src/mod_mysql_vhost.c LOCAL_MODULE := mod_mysql_vhost LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_cgi include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_cgi.c LOCAL_MODULE := mod_cgi LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_staticfile include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_staticfile.c LOCAL_MODULE := mod_staticfile LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_dirlisting include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_dirlisting.c LOCAL_MODULE := mod_dirlisting LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_indexfile include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_indexfile.c LOCAL_MODULE := mod_indexfile LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_setenv include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_setenv.c LOCAL_MODULE := mod_setenv LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_alias include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_alias.c LOCAL_MODULE := mod_alias LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_userdir include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_userdir.c LOCAL_MODULE := mod_userdir LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_rrdtool include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_rrdtool.c LOCAL_MODULE := mod_rrdtool LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_usertrack include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_usertrack.c LOCAL_MODULE := mod_usertrack LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_proxy include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_proxy.c LOCAL_MODULE := mod_proxy LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_ssi include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_ssi_exprparser.c \ src/mod_ssi_expr.c \ src/mod_ssi.c LOCAL_MODULE := mod_ssi LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_secdownload include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_secure_download.c LOCAL_MODULE := mod_secdownload LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_expire include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_expire.c LOCAL_MODULE := mod_expire LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_evhost include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_evhost.c LOCAL_MODULE := mod_evhost LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_simple_vhost include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_simple_vhost.c LOCAL_MODULE := mod_simple_vhost LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_fastcgi include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_fastcgi.c LOCAL_MODULE := mod_fastcgi LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_extforward include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_extforward.c LOCAL_MODULE := mod_extforward LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_access include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_access.c LOCAL_MODULE := mod_access LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_compress include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 -I$(TOP)/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/include LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) -lz ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_compress.c LOCAL_MODULE := mod_compress LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##modlighttpd_auth include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_auth.c \ src/http_auth.c LOCAL_MODULE := mod_auth LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_rewrite include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_rewrite.c LOCAL_MODULE := mod_rewrite LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_redirect include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_redirect.c LOCAL_MODULE := mod_redirect LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_status include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_status.c LOCAL_MODULE := mod_status LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##mod_accesslog include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += -ldl endif LOCAL_SRC_FILES := \  src/mod_accesslog.c LOCAL_MODULE := mod_accesslog LOCAL_PRELINK_MODULE := false LOCAL_MODULE_TAGS := samples include $(BUILD_SHARED_LIBRARY) #####################################################################################
##lighttpd include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 -DLIBRARY_DIR="\"/system/lib\"" ifeq ($(BUILD_OPTION_COMMON_SRC_STATIC),false) LOCAL_SHARED_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) -l$(COMMON_LIBNAME) -ldl else LOCAL_WHOLE_STATIC_LIBRARIES += lib$(COMMON_LIBNAME) LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) -ldl -Wl,--whole-archive -l$(COMMON_LIBNAME) -Wl,-no--whole-archive endif LOCAL_SRC_FILES := \  src/server.c src/response.c src/connections.c src/network.c \ src/configfile.c src/configparser.c src/request.c src/proc_open.c \ src/plugin.c LOCAL_MODULE := lighttpd LOCAL_MODULE_CLASS := EXECUTABLES LOCAL_MODULE_TAGS := samples include $(BUILD_EXECUTABLE) #####################################################################################
##lighttpd-angel include $(CLEAR_VARS) LOCAL_CFLAGS += $(BUILD_OPTION_COMMON_CFLAGS) -W -Wshadow -pedantic -std=gnu99 -DLIBRARY_DIR="\"/system/lib\"" -DSBIN_DIR="\"/system/bin\"" LOCAL_LDFLAGS += $(BUILD_OPTION_COMMON_LDFLAGS) LOCAL_SRC_FILES := \  src/lighttpd-angel.c LOCAL_MODULE := lighttpd-angel LOCAL_MODULE_CLASS := EXECUTABLES LOCAL_MODULE_TAGS := samples include $(BUILD_EXECUTABLE) ########################################################################################################################################################### 

這樣就可以利用 mm showcommands or mm -B showcommands 來編譯lighttpd, 編譯完後會產生lighttpd, liblighttpd_common.so and 其他plugin modules.

以下就開始setup host上的環境, 可以先透過adb的方式把相關的modules都push上host device, 接下來檔案存放的路徑是暫時測試用, 你可以自行依自己的需求與規則來擺放
我把 plugins (mod_*.so)都放到 /system/lib/web-plugin 資料夾
把 lighttpd 放到 /system/bin
把 liblighttpd_common.so 放到 /system/lib
另外 libpcre.so 是需要的(這個請參考前篇文章), 請確定libpcre.so有存在/system/lib內

接下來把 lighttpd soruce 內的 doc/config/conf.d 內的所有檔案通通放到 /etc/lighttpd/conf.d
然後在/etc/lighttpd 放上 lighttpd.conf, 內容如下:

#######################################################################
##
## /etc/lighttpd/lighttpd.conf
##
## check /etc/lighttpd/conf.d/*.conf for the configuration of modules.
##
#######################################################################  #######################################################################
##
## Some Variable definition which will make chrooting easier.
##
## if you add a variable here. Add the corresponding variable in the
## chroot example aswell.
## var.log_root = "/data/www/log" var.server_root = "/data/www" var.state_dir = "/data/www/run" var.home_dir = "/data/www" var.conf_dir = "/data/www/etc" var.cache_dir = home_dir + "/tmp" var.socket_dir = home_dir + "/tmp" server.modules = ( "mod_access",
) server.port = 4080 server.use-ipv6 = "disable" #server.username  = "lighttpd"
#server.groupname = "lighttpd"  server.core-files = "enable" server.document-root = server_root + "/htdocs" #server.pid-file = state_dir + "/lighttpd.pid"  server.errorlog = log_root + "/error.log" server.event-handler = "linux-sysepoll" # not supported?
# I got an error "server.network-backend has a unknown value: linux-sendfile"
#server.network-backend = "linux-sendfile"  server.max-fds = 512 server.stat-cache-engine = "simple" server.max-connections = 170 index-file.names += ( "index.xhtml", "index.html", "index.htm", "default.htm", "index.php" ) url.access-deny = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" { server.range-requests = "disable" } ##
## mimetype mapping
## include "conf.d/mime.conf" server.follow-symlink = "enable" server.upload-dirs = ( "/data/www/tmp" ) #include "conf.d/webdav.conf"  

上述動作都準備完畢後, 就可以用下述的指令來測試看看整個環境設定是否ok了

$ lighttpd -t -f /etc/lighttpd/lighttpd.conf -m /system/lib/web-plugin

如果沒問題的話會, 執行結果會顯示

Syntax OK

再來就是驗證是否web server可以運行了, 用以下指令來啟動lighttpd,

$ lighttpd -D -f /etc/lighttpd/lighttpd.conf -m /system/lib/web-plugin

在/data/www/htdocs 內放一個index.html來測試

<html> <body> <p>Hello, lighthttpd on Android!!</p> </body> </html> 

然後你就可以透過browser 連到host device來確認是否可以看到index.html的內容了, 如下:
browser1.png

以上這樣就算是完成porting跟初步測試了. 再進階的就還需要研究研究. 關於web server的東西我其實也都尚無概念, 有很多知識都還要想辦法盡快吸收.

<date: 2013-09-30> 以下是要說明怎麼啟動cgi (也許google可以找到很多答案, 但是這邊是我動手try過後確定可行的方法)

  1. edit lighttpd.conf to add mod_alias plugin. 這個動作是一定要作的, 不然會發現就算之後已經有load mod_cgi, 且對應的conf 都設定了, 但卻還是不 work.
    @ lighttpd.conf
    server.modules = ( "mod_access", "mod_alias" ) .....
    .....
    include "conf.d/cgi.conf" 
  2. 再來就是去編輯 cgi.conf, uncomment掉以下內容
@ cgi.conf
alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" ) $HTTP["url"] =~ "^/cgi-bin" { cgi.assign = ( "" => "" ) } 
  1. 在host device上create /data/www/cgi-bin 資料夾, 並設定好權限 chmod 755 /data/www/cgi-bin

  2. 由於我的環境沒有porting perl, ruby 等功能, 所以這邊示範的是怎麼用C 寫一個簡單的cgi 程式來測試, 很簡單, 試試以下內容:

    #include <stdio.h> int main(void) { printf("Content-Type: text/html\n\n"); printf("Hello world\n\n"); return 0; } 

    將其編譯好後放到/data/www/cgi-bin , 比如說 first, 之後就透過browser來測試看看
    http://localhost:4080/cgi-bin/first
    如果成功的話, 你就可以看到browser上秀出 Hello world

阅读(1183) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册