御风灰灰
发布于 2024-07-11 / 8 阅读
0
0

openresty移植

1. 下载源码

1.1 openresy

wget https://openresty.org/download/openresty-1.21.4.1.tar.gz
tar -xf openresty-1.21.4.1.tar.gz

1.2 下载pcre下载

wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
tar -xf pcre-8.40.tar.gz

1.3 下载openssl

wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz
tar -xf openssl-1.1.1t.tar.gz

1.4 下载zlibc

wget http://www.zlib.net/zlib-1.2.13.tar.gz
tar -xf zlib-1.2.13.tar.gz

2. 编译前修改

2.1 openresty修改

2.1.1 修改LuaJIT

  • 修改 openresty-1.21.4.1/bundle/LuaJIT-2.1-20220411/src/Makefile中的 HOST_CC 变量
#HOST_CC= $(CC)
HOST_CC= gcc

2.1.2 修改nginx

  • 编译时提示undefined reference to 'ngx_shm_alloc'

源码修改

vim build/nginx-1.21.4/objs/ngx_auto_config.h

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

shell命令修改

HEAD_FILE=`find . -name "ngx_auto_config.h"`

echo "#ifndef NGX_HAVE_SYSVSHM" >> ${HEAD_FILE}
echo "#define NGX_HAVE_SYSVSHM 1" >> ${HEAD_FILE}
echo "#endif" >> ${HEAD_FILE}

2.2 pcre修改

  • 交叉编译时出现you should use --build, --host, --target
# 在进行openresty配置时增加一下参数
--with-pcre-conf-opt="--host=x86_64-linux-musl" \

# 该参数在pcre/config.sub中使用,调整出对应的参数

3. 编译总结

3.1 编译配置脚本

export CROSS_COMPILE_ROOT=/date/zhangfenghui/tools/openwrt-toolchain/toolchain-x86_64_gcc-11.2.0_musl
export STAGING_DIR=$CROSS_COMPILE_ROOT/bin:$STAGING_DIR
export HOST_CC=gcc
export PATH=$CROSS_COMPILE_ROOT/bin:$PATH

export SDK_ROOT=/date/zhangfenghui/share/example/openresty

export CC=x86_64-openwrt-linux-musl-gcc
export CXX=x86_64-openwrt-linux-musl-g++
export AR=x86_64-openwrt-linux-musl-ar
export LD=x86_64-openwrt-linux-musl-ld
export RANLIB=x86_64-openwrt-linux-musl-ranlib
export STRIP=x86_64-openwrt-linux-musl-strip

if [ $# == 0 ] ; then
    echo "exit"
    return
fi

if [ $1 == "config" ]; then
./configure --prefix=/usr/local/openresty \
            --with-luajit \
            --without-http_redis2_module \
            --with-http_iconv_module \
            --with-http_ssl_module \
            --with-pcre-conf-opt="--host=x86_64-linux-musl" \
            --with-pcre=$SDK_ROOT/pcre-8.40 \
            --with-openssl=$SDK_ROOT/openssl-1.1.1t \
            --with-zlib=$SDK_ROOT/zlib-1.2.13 \
            --with-cc=$CC \
            --with-cpp=$CXX
fi


if [ $1 == "make" ]; then
    make
fi

3.2 指定根文件安装

如果不带DESTDIR变量则安装在本级的openresty目录, 带了可以指定路径安装并打包

DESTDIR=/date/zhangfenghui/share/example/openresty/openresty make install

评论