Lean 源码编译指南

目录

  1. 1. 固件编译
    1. 1.1. 安装依赖
    2. 1.2. 系统推荐 Ubuntu 20.04、全程科学上网、不使用 root 用户
    3. 1.3. 软件源添加
    4. 1.4. 主题修改
    5. 1.5. 后台背景修改
    6. 1.6. 后台地址修改
    7. 1.7. 修改内核版本
    8. 1.8. 修改自定义型号
    9. 1.9. 编译
    10. 1.10. 重新配置
    11. 1.11. 二次编译
  2. 2. 报错解决
    1. 2.1. Killed signal terminated program cc1plus

固件编译

本文所有操作均基于 Lean‘s OpenWRT 项目的 18.06 分支,因为我特别喜欢的 luci-theme-argon 主题,还没有兼容最新的 lede 23.05 分支,无奈只能留在 18.06 分支,不过好在固件安装在我的软路由上已稳定运行一年多未重启,稳定性还是比较有保障。

安装依赖

sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache clang cmake cpio curl device-tree-compiler flex gawk gcc-multilib g++-multilib gettext \
genisoimage git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libfuse-dev libglib2.0-dev \
libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libpython3-dev \
libreadline-dev libssl-dev libtool llvm lrzsz msmtp ninja-build p7zip p7zip-full patch pkgconf \
python3 python3-pyelftools python3-setuptools qemu-utils rsync scons squashfs-tools subversion \
swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev

系统推荐 Ubuntu 20.04、全程科学上网、不使用 root 用户

git clone https://github.com/coolsnowwolf/lede.git

软件源添加

cd lede/
vim feeds.conf.default
添加:
src-git helloworld https://github.com/fw876/helloworld
src-git kenzo https://github.com/kenzok8/openwrt-packages
src-git small https://github.com/kenzok8/small

主题修改

cd lede/package/lean  
rm -rf luci-theme-argon  
git clone -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git
make menuconfig #choose LUCI->Theme->Luci-theme-argon 

后台背景修改

替换bg1.jpg
/lede/package/lean/luci-theme-argon/htdocs/luci-static/argon/img

后台地址修改

cd lede/
vim package/base-files/files/bin/config_generate

修改内核版本

vim /target/linux/x86/Makefile

修改自定义型号

# target/linux/x86/base-files/lib/preinit/01_sysinfo 这个首先启动,所以值会被覆盖
sed -i -E 's|echo\s+"?\$vendor\s+\$product"?\s*>.*|echo "Beikong G30 with 2.5Gbps*4" > /tmp/sysinfo/model|' target/linux/x86/base-files/lib/preinit/01_sysinfo

# package/lean/autocore/files/x86/autocore 这个后启动,所以直接修改这个
h="Beikong G30 with 2.5Gbps*4"

编译

cd lede/
./scripts/feeds update -a && ./scripts/feeds install -a
make menuconfig
make download -j8
make V=s -j1   //首次编译建议线程1

重新配置

rm -rf ./tmp && rm -rf .config
make menuconfig

二次编译

git pull
./scripts/feeds update -a && ./scripts/feeds install -a
make defconfig
make download -j8
make V=s -j$(nproc)

报错解决

Killed signal terminated program cc1plus

g++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[5]: *** [Makefile:1157: gimple-match.o] Error 1
make[5]: *** Waiting for unfinished jobs....
make[5]: Leaving directory '/home/lean/lede/build_dir/toolchain-x86_64_gcc-13.3.0_musl/gcc-13.3.0-initial/gcc'
make[4]: *** [Makefile:4605: all-gcc] Error 2
make[4]: Leaving directory '/home/lean/lede/build_dir/toolchain-x86_64_gcc-13.3.0_musl/gcc-13.3.0-initial'
make[3]: *** [Makefile:37: /home/lean/lede/build_dir/toolchain-x86_64_gcc-13.3.0_musl/gcc-13.3.0-initial/.built] Error 2
make[3]: Leaving directory '/home/lean/lede/toolchain/gcc/initial'
time: toolchain/gcc/initial/compile#47.90#11.93#875.14
    ERROR: toolchain/gcc/initial failed to build.
make[2]: *** [toolchain/Makefile:97: toolchain/gcc/initial/compile] Error 1
make[2]: Leaving directory '/home/lean/lede'
make[1]: *** [toolchain/Makefile:93: /home/lean/lede/staging_dir/toolchain-x86_64_gcc-13.3.0_musl/stamp/.toolchain_compile] Error 2
make[1]: Leaving directory '/home/lean/lede'
make: *** [/home/lean/lede/include/toplevel.mk:231: world] Error 2

这个报错大概率就是硬件资源(内存)不足,系统终止了编译,添加个 SWAP 分区即可

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile