201610021304Cross compile nginx 1.11 for arm

目標 : 產生 arm elf 的 nginx httpd

(原始 solution 參考網頁 http://www.cnblogs.com/tolimit/p/4371995.html )

前置軟體需求 : 

arm cross compiler

nginx 1.11 source code

pcre 8.35 source code

zlib source code

 

(1) 首先製作 configure 的設定 script 

#!/bin/sh

BSP_ROOT=/home/raibura/BspRoot/imx6LBV2330_2014-05-02

BSP_TOOLCHAIN_PATH=${BSP_ROOT}/cross_compiler/fsl-linaro-toolchain
BSP_BIN_PREFIX=${BSP_TOOLCHAIN_PATH}/bin/arm-fsl-linux-gnueabi-
SRCROOT=${BSP_ROOT}

CC_PATH=${BSP_BIN_PREFIX}gcc
CPP_PATH=${BSP_BIN_PREFIX}g++
INSTALL_PATH=/mnt/shared/src/nginx_master/
PCRE_PATH=/mnt/shared/src/pcre-8.35/
ZLIB_PATH=/mnt/shared/src/zlib-master/
CC_OPTS="-I ${BSP_ROOT}/source/linux-3.0.35/include/"

auto/configure --prefix=$INSTALL_PATH --with-zlib=$ZLIB_PATH --with-pcre=$PCRE_PATH --with-cc=$CC_PATH --with-cpp=$CPP_PATH --with-cc-opt=$CC_POTS --with-ld-opt="-L ${BSP_ROOT}/source/linux-3.0.35/lib/"

 

(2) configure 遇到 arm cross compiler not found :

修改 auto/cc/name,把 exit 1 mark 掉

 

if [ "$NGX_PLATFORM" != win32 ]; then
    ngx_feature="C compiler"
    ngx_feature_name=
    ngx_feature_run=yes
    ngx_feature_incs=
    ngx_feature_path=
    ngx_feature_libs=
    ngx_feature_test=
    . auto/feature

    if [ $ngx_found = no ]; then
        echo
        echo $0: error: C compiler $CC is not found
        echo
        #exit 1       
    fi

 

 

(3) configure 遇到 sizeof int 問題,修改 auto/types/sizeof

 

ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
          -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"

把 $CC 改成 x86 gcc,如下例

ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS \
          -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"

(4) make 時遇到,PCRE 錯誤,沒設定 pcre 的 platform,修改 objs/Makefile,加上 arm cross compiler 的 prefix

checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/mnt/shared/src/pcre-8.35':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
make[1]: *** [/mnt/shared/src/pcre-8.35
make[1]: Leaving directory `/mnt/shared/src/nginx-1.11'
make: *** [build] Error 2

把 /mnt/shared/src/pcre-8.35

    cd /mnt/shared/src/pcre-8.35/ \
    && if [ -f Makefile ]; then $(MAKE) distclean; fi \
    && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
    ./configure --disable-shared 

把
    ./configure --disable-shared 
改成
    ./configure --disable-shared --host=arm-fsl-linux-gnueabi

(5) make 後,遇到 conversion data type warning,但視作 error,修改 objs/Makefile
把下面敘述的 -Werror 拿掉
CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g

(6) 修改 objs/ngx_auto_config.h,新增下面的敘述到檔尾,避免 compiling, linking stage failed

#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR    132
#endif

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

(7) compiling stage 遇到  ngx_atomic_cmp_set() is not defined! 
修改 src/core/ngx_rwlock.c 把 #error ngx_atomic_cmp_set() is not defined! mark 掉

#if (NGX_HTTP_UPSTREAM_ZONE || NGX_STREAM_UPSTREAM_ZONE)
#error ngx_atomic_cmp_set() is not defined!
#endif

(8) linking stage 找不到 ngx_rwlock_rlock(), ngx_rwlock_wlock(), ngx_rwlock_unlock(),手動在 src/core/ngx_rwlock.c 修改成

#else
void ngx_rwlock_wlock(ngx_atomic_t *lock) {}
void ngx_rwlock_rlock(ngx_atomic_t *lock) {}
void ngx_rwlock_unlock(ngx_atomic_t *lock) {}

#if (NGX_HTTP_UPSTREAM_ZONE || NGX_STREAM_UPSTREAM_ZONE)
//#error ngx_atomic_cmp_set() is not defined!
#endif

好了,經過以上步驟, ngix 的執行檔就可以產生出來,接下來是要擔心 upload 時,
會產生 synchronous 的問題,之後再用 mutex 取代原本的 atomic lock 看看。

 

回應
BloggerVAds
關鍵字
累積 | 今日
loading......
    沒有新回應!
東亞衛星雲圖
東亞衛星雲圖
點圖開啟中央氣象局PDA網頁
+加強版 @Frank的雜記
Instant MSG
Since Apr.3 2015
Free counters!