nginx-cn/build

131 lines
3.4 KiB
Plaintext
Raw Permalink Normal View History

2024-02-19 21:13:12 -05:00
#!/bin/bash
. ./config
2024-02-19 21:13:12 -05:00
# make install prefix
[[ ! -d "${INSTALL_PREFIX}" ]] && {
mkdir -p ${INSTALL_PREFIX}
}
2024-02-19 21:13:12 -05:00
2024-09-16 00:24:22 -04:00
# clean Nginx sources beforehand.
2024-02-19 21:13:12 -05:00
pushd sources/nginx/
2024-09-16 00:24:22 -04:00
echo "cleaning nginx sources"
git clean -dxf
2024-02-19 21:13:12 -05:00
popd
BASE_CONFIGURE_FLAGS=(
2024-02-19 21:13:12 -05:00
# Build everything with Clang + ThinLTO
--with-cc="clang"
--with-cc-opt="-pipe -march=native -mtune=native -flto=thin"
--with-ld-opt="-march=native -mtune=native -flto=thin"
# Use CloudFlare zlib
--with-zlib="$TOP/sources/cf-zlib"
--with-zlib-opt="-O3 -march=native -mtune=native -pipe -flto=thin"
--with-compat
--with-debug
--with-file-aio
--with-http_addition_module
--with-http_auth_request_module
--with-http_dav_module
--with-http_degradation_module
--with-http_flv_module
--with-http_geoip_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_mp4_module
--with-http_random_index_module
--with-http_realip_module
--with-http_secure_link_module
--with-http_slice_module
--with-http_ssl_module
--with-http_stub_status_module
--with-http_sub_module
--with-http_v2_module
# we don't need this functionality, so
# we strip it from our builds
#
# --with-mail
# --with-mail_ssl_module
--with-pcre-jit
--with-stream
--with-stream_geoip_module
--with-stream_realip_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
--with-threads
2024-09-16 00:24:22 -04:00
# Add modules into the build
2024-02-19 21:13:12 -05:00
--add-module=$TOP/sources/modules/nginx-module-vts
--add-module=$TOP/sources/modules/ngx-fancyindex
2024-03-23 03:20:55 -04:00
--add-module=$TOP/sources/modules/lua-nginx-module
2024-02-19 21:13:12 -05:00
# --add-module=$TOP/sources/modules/nginx-rtmp-module
# --add-module=$TOP/modules/nginx-dav-ext-module
)
2024-09-16 00:24:22 -04:00
# Do a dummy config of cloudflare zlib so nginx build can actually distclean (which it does for some reason)..
# I wish it didn't try that but oh well.
2024-02-19 21:13:12 -05:00
pushd $TOP/sources/cf-zlib
CFLAGS="-O3 -march=native -mtune=native -pipe -flto=thin -pipe" CC="clang" \
./configure
popd
2024-03-23 03:20:55 -04:00
# build and install luajit and the resty lua libraries into prefix
pushd $TOP/sources/luajit2
git clean -dxf
make PREFIX=$INSTALL_PREFIX -j49
make PREFIX=$INSTALL_PREFIX install
2024-03-23 03:20:55 -04:00
popd
2024-09-16 00:24:22 -04:00
# resty libs that can be installed
RESTY_LIBS=(
2024-09-16 00:24:22 -04:00
lua-resty-{core,lrucache,websocket}
)
2024-03-23 03:20:55 -04:00
2024-09-16 00:24:22 -04:00
# install resty libs
for lib in ${RESTY_LIBS[@]}; do
echo "installing $lib"
pushd $TOP/sources/$lib
make install PREFIX=$INSTALL_PREFIX
2024-09-16 00:24:22 -04:00
popd
done
2024-09-16 00:19:46 -04:00
2024-02-19 21:13:12 -05:00
pushd $TOP/sources/nginx
2024-03-23 03:20:55 -04:00
# needed for lua-nginx-module
export LUAJIT_INC="$INSTALL_PREFIX/include/luajit-2.1"
export LUAJIT_LIB="$INSTALL_PREFIX/lib"
2024-03-23 03:20:55 -04:00
# TODO: see ./install for --sbin-path
2024-02-19 21:13:12 -05:00
./auto/configure \
--prefix=$PREFIX/etc/nginx \
--conf-path=$PREFIX/etc/nginx/nginx.conf \
2024-09-16 00:24:22 -04:00
--sbin-path=$PREFIX/bin/nginx \
2024-02-19 21:13:12 -05:00
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/nginx.lock \
--user=http \
--group=http \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=stderr \
--http-client-body-temp-path=/var/lib/nginx/client-body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
"${BASE_CONFIGURE_FLAGS[@]}"
make -j $(($(nproc)+1))
popd
# Strip nginx and install it into the staging prefix
pushd $TOP/sources
cp nginx/objs/nginx nginx/objs/nginx.unstripped
strip nginx/objs/nginx
[[ ! -d "${INSTALL_PREFIX}/bin" ]] && mkdir -p ${INSTALL_PREFIX}/bin
cp nginx/objs/nginx $INSTALL_PREFIX/bin/nginx
popd