HOST: centos 7
NGINX VERSION: nginx-1.9.7
ZLIB VERSION: zlib-1.2.8
PCRE VERSION: pcre-8.37
[root@localhost nginx-on-android]# pwd
/opt/cBPM-android/nginx-on-android
[root@localhost nginx-on-android]# ls
nginx-1.9.7 nginx_mod_h264_streaming-2.2.7 nginx-rtmp-module openssl-1.0.1p pcre-8.37 zlib-1.2.8
++++++++++++++++++++++++++++++++++++++++
参考:http://m.blog.csdn.net/blog/zangcf/22688873
前面做过很多次尝试,编译也通过了,但是去掉了很多glob和crypto的函数,导致运行的时候还是会出错,所以,本次按照正常方法,加全所有的函数,然后编译之后运行。
1)在工作目录下建立build目录
/opt/cBPM-android/nginx-on-android/build
2)准备文件,
a) 下载openssl,wget wget http://www.openssl.org/source/openssl-1.0.1p.tar.gz
b) 下载nginx,wget http://nginx.org/download/nginx-1.9.7.tar.gz
c) 下载pcre,wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
d) 下载zlib,wget http://www.zlib.net/zlib-1.2.8.tar.gz
e) 下载下载nginx_mod_h264,wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
f) 下载rtmp模组,git clone https://github.com/arut/nginx-rtmp-module
3) 编译openssl
a) tar tar xvf openssl-1.0.1p.tar.gz
b) cd openssl-1.0.1p
c) 使用如下的配置文件
--------------------------------my_configure_openssl.sh start here-----------------------------------------
#!/bin/sh
./config no-asm shared
--prefix=/opt/cBPM-android/nginx-on-android/build
--------------------------------my_configure_openssl.sh end here-----------------------------------------
d) gedit Makefile,进入修改Makefile
1 step) 找到所有的-m64,删除
2 step) 找到CC= gcc,替换为CC= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
3 step) 找到AR= ar $(ARFLAGS) r,替换为AR= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar $(ARFLAGS) r
4 step) 找到RANLIB= /usr/bin/ranlib,替换为RANLIB= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
5 step) 找到NM= nm,修改为NM= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-nm
6 step) 找到MAKEDEPPROG= gcc,修改为MAKEDEPPROG= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
e)cp Makefile Makefile.ok
f)执行make -j4 && make install
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
或者 使用下面方法:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
参考: https://wiki.openssl.org/index.php/Android
下载makedepend.zip , 从http://llg.cubic.org/docs/vc7.html下载。 解压编译,然后 cp makedepend /bin/
下载Setenv-android.sh , wget https://wiki.openssl.org/images/7/70/Setenv-android.sh
[root@localhost openssl-1.0.1p]# gedit Setenv-android.sh //关键设置如下:
#-------------------------------------------------------
ANDROID_NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
_ANDROID_NDK="android-ndk-r8e"
_ANDROID_EABI="arm-linux-androideabi-4.7"
_ANDROID_API="android-14"
export MACHINE=armv7
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=arm
#export CROSS_COMPILE="arm-linux-androideabi-"
export CROSS_COMPILE=""
#-------------------------------------------------------
[root@localhost openssl-1.0.1p]# pwd
/opt/cBPM-android/nginx-on-android/openssl-1.0.1p
chmod a+x Setenv-android.sh
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/android-14/
make depend
make all
find . -name "*.a"
find . -name libcrypto.a
find . -name libssl.a
readelf -h ./libcrypto.a | grep -i 'class|machine' | head -2
cp libssl.a libcrypto.a /opt/cBPM-android/criteria-lin/lib
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4) 编译pcre
a)tar xvf pcre-8.37.tar.gz
b) cd pcre-8.37
c) gedit my_configure_pcre.sh
-------------------------my_configure_pcre.sh start here--------------------------
#!/bin/sh
NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
CPATH="/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
./configure
--host=arm-linux
--prefix=/opt/cBPM-android/nginx-on-android/build
CPP="$CPATH/arm-linux-androideabi-cpp"
CXX="$CPATH/arm-linux-androideabi-g++"
CXXCPP="$CPATH/arm-linux-androideabi-cpp"
CC="$CPATH/arm-linux-androideabi-gcc"
AR="$CPATH/arm-linux-androideabi-ar"
AS="$CPATH/arm-linux-androideabi-as"
-------------------------my_configure_pcre.sh end here-------------------------
d) chmod +x my_configure_pcre.sh
e)./my_configure_pcre.sh
f) make -j4 && make install
[root@localhost pcre-8.37]# find . -name "*.a"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
或者 使用(参考)下面方法:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/sh
NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
LDFLAGS="-L$NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi-v7a -L/opt/cBPM-android/criteria-lin/lib -L/opt/cBPM-android/lighttpd-1.4.37/src/.libs -lstlport_static -lgcc -lc"
CPATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
CPP="$CPATH/arm-linux-androideabi-cpp"
CXX="$CPATH/arm-linux-androideabi-g++"
CXXCPP="$CPATH/arm-linux-androideabi-cpp"
CC="$CPATH/arm-linux-androideabi-gcc"
LD="$CPATH/arm-linux-androideabi-ld"
AR="$CPATH/arm-linux-androideabi-ar"
AS="$CPATH/arm-linux-androideabi-as"
./configure --host=arm-linux --prefix=/opt/cBPM-android/nginx-on-android/build CC=$CC CPP=$CPP AR=$AR AS=$AS CXX=$CXX CXXCPP=$CXXCPP
d) chmod u+x my_configure_pcre.sh
e) ./my_configure_pcre.sh
f) make && make install
++++++++++++++++
编译pcre,也可以参考:http://blog.chinaunix.net/uid-14735472-id-5214130.html
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5) 解压zlib
/opt/cBPM-android/nginx-on-android/zlib-1.2.8
6) 解压nginx_mod_h264
/opt/cBPM-android/nginx-on-android/nginx_mod_h264_streaming-2.2.7
7) 编译nginx
a) tar xvf nginx-1.9.7.tar.gz
b) cd nginx-1.9.7
c) gedit auto/cc/name
if [ "$NGX_PLATFORM" != win32 ]; then
ngx_feature="C compiler"
ngx_feature_name=
#ngx_feature_run=yes
ngx_feature_run=no ==>set to no to skip check
ngx_feature_incs=
ngx_feature_path=
#exit 1
d) gedit auto/types/sizeof
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS
==> ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS
e) gedit src/os/unix/ngx_errno.h
at line 15 add #define NGX_SYS_NERR 333
f) gedit src/os/unix/ngx_shmem.c
#if (NGX_HAVE_MAP_ANON) ==> #if (!NGX_HAVE_MAP_ANON)
g) gedit auto/lib/pcre/make
./configure --disable-shared $PCRE_CONF_OPT
修改为
./configure --disable-shared $PCRE_CONF_OPT
--host=arm-linux
--prefix=/opt/cBPM-android/nginx-on-android/build
CC=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
CPP=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp
AR=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
AS=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as
CXX=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
CXXCPP=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp
h) gedit auto/lib/openssl/make
$OPENSSL/.openssl/include/openssl/ssl.h: $NGX_MAKEFILE
cd $OPENSSL \
&& if [ -f Makefile ]; then $(MAKE) clean; fi \
&& ./config --prefix=$ngx_prefix no-shared $OPENSSL_OPT \
&& $(MAKE) \
&& $(MAKE) install LIBDIR=lib
修改为
$OPENSSL/.openssl/include/openssl/ssl.h: $NGX_MAKEFILE
cd $OPENSSL \
i) 打开/opt/cBPM-android/nginx-on-android/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c,删除
if (r->zero_in_uri) {
return NGX_DECLINED;
}
j) gedit my_configure_nginx.sh
------------------------my_configure_nginx.sh start here------------------------
#!/bin/sh
BUILD_PATH=/opt/cBPM-android/nginx-on-android/build
CC_PATH=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
CPP_PATH=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
LD_PATH=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
./configure
--prefix=$BUILD_PATH
--builddir=$BUILD_PATH
--with-zlib=/opt/cBPM-android/nginx-on-android/zlib-1.2.8
--with-pcre=/opt/cBPM-android/nginx-on-android/pcre-8.37
--with-pcre-jit
--with-cc=$CC_PATH
--with-cpp=$CPP_PATH
--with-ld-opt=$LD_PATH
--with-openssl=/opt/cBPM-android/nginx-on-android/openssl-1.0.1p
--add-module=/opt/cBPM-android/nginx-on-android/nginx_mod_h264_streaming-2.2.7
--with-http_flv_module
--with-http_mp4_module
--add-module=/opt/cBPM-android/nginx-on-android/nginx-rtmp-module
------------------------my_configure_nginx.sh end here------------------------
[root@localhost nginx-1.9.7]# ./my_configure_nginx.sh
k) gedit ../build/Makefile
注意这里使用的arm_linux_gcc版本必须是4.4.3以后的,之前的本本可能会出错。
1 step)找到 /opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/include/openssl/ssl.h ,替换为/opt/cBPM-android/nginx-on-android/build/include/openssl/ssl.h
2 step)找到-I /opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/include ,替换为-I /opt/cBPM-android/nginx-on-android/build/include/openssl
3 step) CFLAGS增加-I/opt/cBPM-android/nginx-on-android/build/include
-I/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/include和
4 step) CLAGS去掉 -Werror
5 step) 找到 /opt/cBPM-android/nginx-on-android/pcre-8.37/.libs/libpcre.a
/opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/lib/libssl.a,
/opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/lib/libcrypto.a
/opt/cBPM-android/nginx-on-android/pcre-8.37/.libs/libpcre.a
替换为/opt/cBPM-android/nginx-on-android/build/lib/*.a (上面四个文件的路径,位于同一个文件夹)
6 step) 在链接目标文件增加libc的标准库地址/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/libcrypt.a和/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/libc.a /opt/cBPM-android/nginx-on-android/build/lib/libpcre.a
这里如果集成Makefile还有找不到的文件,需要指定链接过程,类似做法如上。
l) make -j4 && make install
大工告成
---------------------------
$linker $libdirs -o $exe_output /opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib/crtbegin_static.o $link_objects $link_resobjects $link_options $libs /opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib/crtend_android.o
---------------------------
错误:
src/os/unix/ngx_linux_config.h:32:18: fatal error: glob.h: No such file or directory
解决:
参考:https://groups.google.com/forum/#!topic/Android-ndk/vSH6MWPD0Vk
[root@localhost nginx-1.9.7]# wget https://github.com/white-gecko/TokyoCabinet/raw/master/glob.h
[root@localhost nginx-1.9.7]# wget https://github.com/white-gecko/TokyoCabinet/raw/master/glob.c
[root@localhost nginx-1.9.7]# cp glob.* /opt/cBPM-android/nginx-on-android/build/
---------------------------
[root@localhost nginx-1.9.7]# gedit src/core/ngx_rwlock.c
#error ngx_atomic_cmp_set() is not defined!
改为:
//#error ngx_atomic_cmp_set() is not defined!
---------------------------
[root@localhost nginx-1.9.7]# gedit /opt/cBPM-android/nginx-on-android/zlib-1.2.8/contrib/minizip/crypt.h
添加:
#include "zconf.h"
---------------------------
[root@localhost nginx-1.9.7]# gedit src/core/ngx_config.h
添加
#include <ngx_posix_config.h>
---------------------------
/opt/cBPM-android/nginx-on-android/nginx-rtmp-module/ngx_rtmp_exec_module.c:774:23: error: 'PR_SET_PDEATHSIG' undeclared (first use in this function)
[root@localhost nginx-1.9.7]# gedit /opt/cBPM-android/nginx-on-android/nginx-rtmp-module/ngx_rtmp_exec_module.c
prctl(PR_SET_PDEATHSIG, e->kill_signal, 0, 0, 0);
改为:
//prctl(PR_SET_PDEATHSIG, e->kill_signal, 0, 0, 0);
---------------------------
相关热门文章
给主人留下些什么吧!~~
评论热议