mips交叉編譯nginx
阿新 • • 發佈:2018-12-20
1、準備
還需要用到zlib,下載zlib-1.2.1.2
openssl:openssl-1.0.2o.tar.gz
pcre:pcre-8.42.tar.gz
2、編譯
1>預編譯Openssl
由於openssl編譯不太好弄交叉編譯因此需要先到openssl目錄下去
./config --prefix=/home/chentao/work/code/openssl-1.0.2o/.openssl no-shared no-threads no-asm
生成Makefile以後修改Makefile中的編譯器指定
CC= mips64el-linux-gcc CFLAG= -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -O3 -Wall DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_LIBUNBOUND -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_SSL_TRACE -DOPENSSL_NO_SSL2 -DOPENSSL_NO_STORE -DOPENSSL_NO_UNIT_TEST -DOPENSSL_NO_WEAK_SSL_CIPHERS PEX_LIBS= EX_LIBS= -ldl EXE_EXT= ARFLAGS= AR= mips64el-linux-ar $(ARFLAGS) r RANLIB= mips64el-linux-ranlib RC= windres NM= mips64el-linux-nm PERL= /usr/bin/perl TAR= tar TARFLAGS= --no-recursion MAKEDEPPROG= mips64el-linux-gcc LIBDIR=lib # We let the C compiler driver to take care of .s files. This is done in # order to be excused from maintaining a separate set of architecture # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC # gcc, then the driver will automatically translate it to -xarch=v8plus # and pass it down to assembler. AS=$(CC) -c ASFLAG=$(CFLAG)
然後需要找到Makefile中所有的-m64選項去掉。
2>預處理nginx
進入nginx根目錄建立檔案my_configure.sh內容如下
#!/bin/sh BUILD_PATH=/home/chentao/work/code/nginx-1.15.6/mips-build CC_PATH=mips64el-linux-gcc CPP_PATH=mips64el-linux-g++ ./configure \ --prefix=/home/chentao/work/project/Z2-KERNEL-t/rootfs/rootfs_fs/fsxxx \ --user=root \ --group=root \ --builddir=$BUILD_PATH\build \ --with-zlib=/home/chentao/work/code/zlib-1.2.1.2 \ --with-pcre=/home/chentao/work/code/pcre-8.42 \ --with-pcre-jit \ --with-cc=$CC_PATH \ --with-cpp=$CPP_PATH \ --without-http_upstream_zone_module \ --with-openssl=/home/chentao/work/code/openssl-1.0.2o
其中--prefix為安裝目錄
--with-zlib為zlib的原始碼根目錄
--with-pcre為pcre的原始碼根目錄
--with-openssl為openssl的原始碼根目錄
執行sh ./my_configure.sh 會生成mips-buildbuild目錄
cd mips-buildbuild
加入
開啟ngx_auto_config.h檔案加入:
#ifndef NGX_HAVE_SYSVSHM #define NGX_HAVE_SYSVSHM 1 #endif
修改mips_buildbuild目錄下的Makefile
/home/chentao/work/code/pcre-8.42/Makefile: /home/chentao/work/code/nginx-1.15.6/mips-buildbuild/Makefile
cd /home/chentao/work/code/pcre-8.42 \
&& if [ -f Makefile ]; then $(MAKE) distclean; fi \
&& CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared --enable-jit --host=mips64el-linux
/home/chentao/work/code/pcre-8.42/.libs/libpcre.a: /home/chentao/work/code/pcre-8.42/Makefile
cd /home/chentao/work/code/pcre-8.42 \
&& $(MAKE) libpcre.la
/home/chentao/work/code/openssl-1.0.2o/.openssl/include/openssl/ssl.h: /home/chentao/work/code/nginx-1.15.6/mips-buildbuild/Makefile
cd /home/chentao/work/code/openssl-1.0.2o \
#&& if [ -f Makefile ]; then $(MAKE) clean; fi
#&& ./config --prefix=/home/chentao/work/code/openssl-1.0.2o/.openssl no-shared no-threads
&& $(MAKE) \
&& $(MAKE) install_sw LIBDIR=lib
/home/chentao/work/code/zlib-1.2.1.2/libz.a: /home/chentao/work/code/nginx-1.15.6/mips-buildbuild/Makefile
cd /home/chentao/work/code/zlib-1.2.1.2 \
&& $(MAKE) distclean \
&& CFLAGS="-O2 -fomit-frame-pointer -pipe " CC="$(CC)" \
./configure \
&& $(MAKE) libz.a
manpage: /home/chentao/work/code/nginx-1.15.6/mips-buildbuild/nginx.8
src/os/unix/ngx_errno.h目錄下加入
#define NGX_SYS_NERR 334
修改auto/cc/name
if [ "$NGX_PLATFORM" != win32 ]; then
ngx_feature="C compiler"
ngx_feature_name=
#ngx_feature_run=yes
ngx_feature_run=no
ngx_feature_incs=
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test=
. auto/feature
修改auto/types/sizeof
int main(void) {
printf("%d", (int) sizeof($ngx_type));
return 0;
}
END
#ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS \
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
3、編譯ngnix
make
make install
執行的時候需要需要指定prefix路徑使用使用 "nginx -l /" 指定為根目錄
完成手工。