自编译小体积smartdns便于padavan集成

smartdns 官方 release 为静态编译软件,体积较大,对于 openwrt 有对应的动态编译版本软件库可选,但是并不能直接用于 padavan 系统。目测应该是动态依赖不匹配,毕竟 padavan 的内核始终是 3.4.x 和 openwrt 相差几条街了。虽然静态编译版本经过 upx 之后约 1mb 大小,使用也没啥大问题,但是既然 smartdns 是开源的,那么自行编译就是更好的选择,官方文档也有提及,好处就是动态编译出来的软件体积小多了。先看结果,upx 之后 80k 出头,是不是小多了?

编译环境:ubuntu 20.04 x64

先更新库,安装编译依赖项

sudo apt update
sudo apt install make upx

准备 padavan 的交叉编译链

git clone --depth=1 https://github.com/hanwckf/rt-n56u.git /tmp/rt-n56u
cd /tmp/rt-n56u/toolchain-mipsel
sh dl_toolchain.sh

目前 padavan 用的 openssl 版本是 1_1_1j

cd /tmp
wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1j.tar.gz
tar xvf OpenSSL_1_1_1j.tar.gz

编译 smartdns 之前,需要先交叉编译 openssl

cd /tmp/openssl-OpenSSL_1_1_1j
./config no-asm shared enable-ecdsa --cross-compile-prefix=/tmp/rt-n56u/toolchain-mipsel/toolchain-3.4.x/bin/mipsel-linux-uclibc- --prefix=/tmp/openssl
sed -i 's/-pthread -m64/-pthread/g' Makefile
make && make install

接下来就可以交叉编译 smartdns 了

git clone --depth=1 https://github.com/pymumu/smartdns.git /tmp/smartdns
cd /tmp/smartdns
chmod +x ./package/build-pkg.sh
env CFLAGS="-I/tmp/openssl/include" LDFLAGS="-L/tmp/openssl/lib" ./package/build-pkg.sh --platform linux --arch mipsel_24kc --cross-tool /tmp/rt-n56u/toolchain-mipsel/toolchain-3.4.x/bin/mipsel-linux-uclibc- --outputdir /tmp

smartdns 编译很快,成功之后在 /tmp 目录下可以看到一个对应的压缩包,我们将它先解压然后再 upx 压缩下

mkdir /tmp/out
tar xvf /tmp/smartdns.*.tar.gz --directory=/tmp/out
upx --best --lzma /tmp/out/smartdns/usr/sbin/smartdns

最后,就得到了一个 80k 出头动态编译的 smartdns 了。

个人目前已经集成到 padavan 固件了,仓库 bin 目录下就是 smartdns

https://github.com/felix-fly/v2ray-padavan-doh

  • 本文作者:飞尘
  • 版权声明:本站所有文章除特别声明外,均可转载,转载请注明出处!