apr-1.6.5.tar.gz
apr-util-1.5.4.tar.gz
pcre-8.42.tar.gz
httpd-2.4.43.tar.gz
编译和移植apache所需要的源代码
1、安装apr
apr主要是为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库,本文就不做过多的介绍。
hdwei$tar -zxvf apr-1.6.5.tar.gz
hdwei$cd apr-1.6.5
hdwei$./configure --prefix=/usr/local/apr --host=x86 CC=gcc CXX=g++ LD=ld
hdwei$make
hdwei$sudo make install
2、安装apr-util
apr-util是apache所使用的apache可移植运行时工具库。在x86平台上可以使用最新的apr-util-1.6.1版本,因为在移植到arm平台的时候,使用较新的版本总是编译不过,所以使用apr-util-1.5.4这个版本。
hdwei$tar -zxvf apr-util-1.5.4.tar.gz
hdwei$cd apr-util-1.5.4
hdwei$./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --host=x86 CC=gcc CXX=g++ LD=ld
hdwei$make
hdwei$sudo make install
3、安装pcre
hdwei$tar -zxvf pcre-8.42.tar.gz
hdwei$cd pcre-8.42
hdwei$./configure --prefix=/usr/local/pcre --host=x86 CC=gcc CXX=g++ LD=ld
hdwei$make
hdwei$sudo make install
4、安装httpd-2.4.43
hdwei$tar -zxvf httpd-2.4.43.tar.gz
hdwei$cd httpd-2.4.43
hdwei$./configure --prefix=/usr/local/apache2 --host=x86 --enable-cgi --enable-rewrite --enable-mods-shared=all --with-pcre=/usr/local/pcre --with-includer-apr=/usr/local/apr --with-includer-apr-util=/usr/local/apr-util
hdwei$make
hdwei$sudo make install
也可以直接将apr和apr-util的源码直接解压到 httpd-2.4.43/srclib目录下,在httpd-2.4.43目录执行configure的时候,--with-includer-apr=httpd-2.4.43/srclib/apr ,with-includer-apr-util=httpd-2.4.43/srclib/apr-util,httpd-2.4.43执行configure的时候,会调用执行apr和apr-util的源码中的configure。
移植到arm平台编译和安装
这里,我直接将apr和apr-util的源码直接解压到 httpd-2.4.43/srclib目录下,然后执行configure
./configure --prefix=/home/apache2 --host=arm-linux-gnueabihf --with-pcre=/home/apache-src/httpd-2.4.43/srclib/pcre --with-includer-apr=/home/apache-src/httpd-2.4.43/srclib/apr --with-includer-apr-util=/home/apache-src/httpd-2.4.43/srclib/apr-util --enable-proxy --enable-proxy-http --with-mpm=prefork --enable-proxy-balancer --enable-dav --enable-rewrite --enable-so --enable-http --enable-expires --enable-headers --enable-mods=deflate_module --with-susexec --disable-info --without-berkeley-db --enable-dav=shared --enable-dav-lock=shared --enable-cache --enable-cache=shared --enable-disk-cache --enable-disk-cache=shared CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ LD=arm-linux-gnueabihf-ld ap_cv_void_ptr_lt_long=no ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_tcp_nodelay_with_cork=yes ac_cv_sizeof_struct_iovec=8
执行configure后,出现如下:
Server Version: 2.4.43
Install prefix: /home/handong/nfsdir/apache2
C compiler: arm-linux-gnueabihf-gcc -std=gnu99
CFLAGS: -g -O2
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: arm-linux-gnueabihf-gcc -E
执行make,出现问题如下:
tools/gen_test_char > include/private/apr_escape_test_char.h
tools/gen_test_char: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
Makefile:144: recipe for target 'include/private/apr_escape_test_char.h' failed
make[3]: *** [include/private/apr_escape_test_char.h] Error 127
make[3]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr'
/home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr/build/apr_rules.mk:118: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr'
/home/handong/nfsdir/apache/httpd-2.4.43/build/rules.mk:75: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/srclib'
/home/handong/nfsdir/apache/httpd-2.4.43/build/rules.mk:75: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
解决方法:
hdwei$cd srclib/apr
hdwei$vim include/private/apr_escape_test_char.h
添加如下内容:
#define T_ESCAPE_SHELL_CMD (1)
#define T_ESCAPE_PATH_SEGMENT (2)
#define T_OS_ESCAPE_PATH (4)
#define T_ESCAPE_ECHO (8)
#define T_ESCAPE_URLENCODED (16)
#define T_ESCAPE_XML (32)
#define T_ESCAPE_LDAP_DN (64)
#define T_ESCAPE_LDAP_FILTER (128)
static const unsigned char test_char_table[256] = {
32,30,30,30,30,30,30,30,30,30,31,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,6,16,63,22,17,22,49,17,
17,17,1,16,16,0,0,18,0,0,0,0,0,0,0,0,0,0,16,23,
55,16,55,23,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,23,31,23,23,0,23,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,23,23,23,17,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
};
继续执行make,出现问题如下:
./gen_test_char > test_char.h
./gen_test_char: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
Makefile:37: recipe for target 'test_char.h' failed
make[2]: *** [test_char.h] Error 127
make[2]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/server'
/home/handong/nfsdir/apache/httpd-2.4.43/build/rules.mk:75: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/server'
/home/handong/nfsdir/apache/httpd-2.4.43/build/rules.mk:75: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
这个问题是httpd-2.4.43/server目录下编译生成的gen_test_char可执行文件的格式为arm平台的可执行文件,这个当然不能在这里运行啦,好了,怎么办呢??,编译宿主机平台下的可执行文件就行了
解决方法:
hdwei$cd server
hdwei$gcc -Wall -O2 -DCROSS_COMPILE gen_test_char.c -s -o gen_test_char
继续执行make,这里编译稍微会久一些,接下来又会出现问题:
/home/handong/git-code/qume-repository/arm-linux-gnueabihf-4.7/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: server/mpm/event/.libs/libevent.a(event.o): undefined reference to symbol 'pthread_sigmask@@GLIBC_2.4'
/home/handong/git-code/qume-repository/arm-linux-gnueabihf-4.7/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: note: 'pthread_sigmask@@GLIBC_2.4' is defined in DSO /home/handong/git-code/qume-repository/arm-linux-gnueabihf-4.7/bin/../arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/libpthread.so.0 so try adding it to the linker command line
/home/handong/git-code/qume-repository/arm-linux-gnueabihf-4.7/bin/../arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
/home/handong/nfsdir/apache/httpd-2.4.43/build/program.mk:22: recipe for target 'httpd' failed
老子不干了,甩电脑走人.....
等等,还是再努努力算了。
解决方法:添加 -pthread 编译选项
/home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr/libtool --silent --mode=link arm-linux-gnueabihf-gcc -std=gnu99 -g -O2 -o httpd modules.lo buildmark.o -export-dynamic server/libmain.la modules/core/libmod_so.la modules/http/libmod_http.la server/mpm/event/libevent.la os/unix/libos.la -L/home/handong/nfsdir/apache/httpd-2.4.43/srclib/pcre/lib -lpcre /home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr-util/libaprutil-1.la /home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr-util/xml/expat/libexpat.la /home/handong/nfsdir/apache/httpd-2.4.43/srclib/apr/libapr-1.la -lrt -lcrypt -ldl -pthread
make,直到出现如下内容,就可以make install 了
make[4]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/modules/mappers'
make[3]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/modules/mappers'
make[2]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/modules'
make[2]: Entering directory '/home/handong/nfsdir/apache/httpd-2.4.43/support'
make[2]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43/support'
make[1]: Leaving directory '/home/handong/nfsdir/apache/httpd-2.4.43'
好了,可以开心的在arm平台使用httpd来happy了。