nginx coturn socat privoxy opencv 静态编译
文档说明: 只记录关键的地方; 发文时间: 2023-11-02
意义: linux 环境,免安装 下载后即可使用
环境: alpine:3.18 docker clang
状态: 完善中
体验编译结果
nginx 静态编译关键点
nginx use PCRE2 library on nginx 1.21.5
hg 脚本全称是 mercurial (基于python 的 分布式版本控制系统)
openssl zlib pcpre2 等静态库需要提构建好
nginx 静态编译,更多配置:nginx.php
hg clone -r default --rev=1 http://hg.nginx.org/nginx
cd nginx
cp -f auto/configure configure
./configure --help
PACKAGES=" libxml-2.0 libexslt libxslt openssl zlib"
PACKAGES="\$PACKAGES libpcre2-16 libpcre2-32 libpcre2-8 libpcre2-posix"
CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES)"
LDFLAGS="$(pkg-config --libs-only-L --static $PACKAGES)"
LIBS="$(pkg-config --libs-only-l --static $PACKAGES)"
./configure \
--prefix=/usr/local/nginx/ \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_v3_module \
--with-http_flv_module \
--with-http_sub_module \
--with-stream \
--with-stream_ssl_preread_module \
--with-stream_ssl_module \
--with-threads \
--with-cc-opt=" -O2 $CPPFLAGS " \
--with-ld-opt=" -static $LDFLAGS "
make -j $(nproc)
make install
coturn 静态编译
openssl zlib libevent hiredis libmongoc 等静态库需要提构建好
coturn 静态编译,更多配置:coturn.php
PACKAGES='sqlite3'
PACKAGES="$PACKAGES libevent libevent_core libevent_extra libevent_openssl libevent_pthreads"
PACKAGES="$PACKAGES hiredis"
PACKAGES="$PACKAGES libbson-static-1.0 libmongoc-ssl-1.0 libmongoc-static-1.0 "
export SSL_CFLAGS="$(pkg-config --cflags-only-I --static openssl ) "
export SSL_LIBS="$(pkg-config --libs --static openssl ) "
export CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES)"
export LDFLAGS="$(pkg-config --libs-only-L --static $PACKAGES) --static "
export LIBS="$(pkg-config --libs-only-l --static $PACKAGES) -lstdc++ -lm " #
export CFLAGS="-O3 -g -std=gnu11 -Wall -static "
export DBCFLAGS="$(pkg-config --cflags --static libpq sqlite3 hiredis libbson-static-1.0 libmongoc-ssl-1.0 libmongoc-static-1.0 )"
export DBLIBS="$(pkg-config --libs --static libpq sqlite3 hiredis libbson-static-1.0 libmongoc-ssl-1.0 libmongoc-static-1.0 )"
export OSLIBS="$(pkg-config --libs --static $PACKAGES) -lstdc++ -lm "
export OSCFLAGS=$CPPFLAGS
sed -i.backup "s/libmongoc-1.0/libmongoc-static-1.0/" ./configure
./configure \
--prefix=/usr/local/coturn/
make -j $(nproc)
make install
socat 静态编译
socat 静态编译,更多配置:socat.php
PACKAGES='openssl readline'
CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES)" \
LDFLAGS="$(pkg-config --libs-only-L --static $PACKAGES)" \
LIBS="$(pkg-config --libs-only-l --static $PACKAGES)" \
CFLAGS="-static -O2 -Wall -fPIC -DWITH_OPENSSL" \
./configure \
--prefix=/usr/local/socat/ \
--enable-readline \
--enable-openssl-base=/usr/local/openssl/
make -j $(nproc)
make install
privoxy 静态编译
privoxy 静态编译,更多配置:privoxy.php
autoheader
autoconf
PACKAGES="openssl zlib"
PACKAGES="$PACKAGES libbrotlicommon libbrotlidec libbrotlienc "
PACKAGES="$PACKAGES libpcre libpcre16 libpcre32 libpcrecpp libpcreposix"
CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES )" \
LDFLAGS="$(pkg-config --libs-only-L --static $PACKAGES )" \
LIBS="$(pkg-config --libs-only-l --static $PACKAGES )" \
PCRE_STATIC=YES \
./configure \
--prefix=/usr/local/privoxy/ \
--enable-static-linking \
--with-openssl \
--without-mbedtls \
--with-brotli \
--with-docbook=yes
make -j $(nproc)
make install
opencv 静态编译
待完善
需要提前准备好,ffmpeg zlib openssl libarchive libiconv 等静态库(复用swoole-cli 静态库构建流程)
opencv 静态编译,更多配置:opencv.php
PACKAGES='openssl '
PACKAGES="$PACKAGES zlib"
PACKAGES="$PACKAGES libxml-2.0"
PACKAGES="$PACKAGES liblzma libzstd liblz4 "
PACKAGES="$PACKAGES libavcodec libavdevice libavfilter libavformat libavutil libswresample libswscale"
PACKAGES="$PACKAGES libwebp libpng libpng16 libjpeg libturbojpeg SvtAv1Enc SvtAv1Dec "
PACKAGES="$PACKAGES dav1d sdl2 aom freetype2 gmp lcms2 " # libtiff-4
PACKAGES="$PACKAGES libbrotlicommon libbrotlidec libbrotlienc"
PACKAGES="$PACKAGES x264 vpx ogg opus openh264 libpcap fdk-aac fribidi librabbitmq x265 gflags "
PACKAGES="$PACKAGES fftw3q Imath libglog openblas blas64 lapack64 blas"
CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES)"
LDFLAGS="$(pkg-config --libs-only-L --static $PACKAGES) "
LIBS="$(pkg-config --libs-only-l --static $PACKAGES)"
CPPFLAGS="$CPPFLAGS -I/usr/local/bzip2/include -I/usr/local/libiconv/include -I/usr/local/libxml2/include "
LDFLAGS="$LDFLAGS -L/usr/local/bzip2/lib -L/usr/local/libiconv/lib"
LIBS="$LIBS -lbz2 -liconv "
mkdir -p build
cd build
cmake .. \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/usr/local/opencv \
-DCMAKE_POLICY_DEFAULT_CMP0074=NEW \
-DOPENCV_EXTRA_MODULES_PATH="../opencv_contrib/modules" \
-DCMAKE_CXX_STANDARD=14 \
-DCMAKE_C_STANDARD=11 \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_SHARED_LIBS=OFF \
-DOpenCV_STATIC=ON \
-DENABLE_PIC=ON \
-DWITH_FFMPEG=ON \
-DFFMPEG_ROOT=/usr/local/ffmpeg \
-DZLIB_ROOT=/usr/local/zlib \
-Dfreetype2_ROOT=/usr/local/freetype \
-DPNG_ROOT=/usr/local/png \
-DJPEG_ROOT=/usr/local/jpeg \
-DLAPACK_ROOT=/usr/local/lapack \
-DOpenBLAS_ROOT=/usr/local/openblas \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=ON \
-DBUILD_opencv_apps=ON \
-DBUILD_opencv_js=OFF \
-DBUILD_JAVA=OFF \
-DBUILD_CUDA_STUBS=OFF \
-DBUILD_FAT_JAVA_LIB=OFF \
-DBUILD_ANDROID_SERVICE=OFF \
-DBUILD_OBJC=OFF \
-DBUILD_KOTLIN_EXTENSIONS=OFF \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DBUILD_DOCS=ON
ninja
ninja install
使用已经准备好的脚本
详见 ffmpeg 静态编译 稍微添加点参数即可,如下:
复用swoole-cli 静态库构建流程
php prepare.php +opencv +coturn +privoxy +socat