quinnwencn / blog

Apache License 2.0
0 stars 0 forks source link

00 编译OpenWRT系统 #19

Open quinnwencn opened 4 months ago

quinnwencn commented 4 months ago

下载代码

从github下载OpenWRT源码,并切换到22-03分支:

git clone https://github.com/openwrt/openwrt.git
git checkout -b openwrt-22.03 remotes/origin/openwrt-22.03

编译准备

安装编译依赖

我是用的是arm版本的ubuntu22.04,需要安装一些依赖:

sudo apt -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev  subversion flex uglifyjs git-core p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler  antlr3 gperf wget curl swig rsync

下载OpenWRT依赖的源码

由于OpenWRT官方的源码仓库位于git.openwrt.org,访问经常会失败,因此我把源码改为了github的源码,这些都在openwrt的github仓库里,要修改的文件是openwrt/feed.conf.default。 原始文件内容:

src-git packages https://git.openwrt.org/feed/packages.git
src-git luci https://git.openwrt.org/project/luci.git
src-git routing https://git.openwrt.org/feed/routing.git
src-git telephony https://git.openwrt.org/feed/telephony.git
#src-git video https://github.com/openwrt/video.git
#src-git targets https://github.com/openwrt/targets.git
#src-git oldpackages http://git.openwrt.org/packages.git
#src-link custom /usr/src/openwrt/custom-feed

使用sed更改

sed -i 's/git.openwrt.org/github.com/g' feeds.conf.default
sed -i 's/feed/openwrt/g' feeds.conf.default
sed -i 's/project/openwrt/g' feeds.conf.default

更改后的版本:

src-git packages https://github.com/openwrt/packages.git
src-git luci https://github.com/openwrt/luci.git
src-git routing https://github.com/openwrt/routing.git
src-git telephony https://github.com/openwrt/telephony.git
#src-git video https://github.com/openwrt/video.git
#src-git targets https://github.com/openwrt/targets.git
#src-git oldpackages http://github.com/packages.git
#src-link custom /usr/src/openwrt/custom-openwrt

下载和安装依赖源码:

./scripts/feeds update -a
./scripts/feeds install -a

编译OpenWRT

首先是配置OpenWRT

make menuconfig

然后直接多线程编译

make -j16 V=s

如果出错了,改为单线程,查看出错的具体原因。

quinnwencn commented 4 months ago

对于OpenWRT 里编译某个包的搜索路径的问题,这里做一个说明: 每个编译包在寻找lib和头文件时,都会到staging_dir/targetxxx/usr/lib和staging_dir/targetxxx/usr/include查找对应的库文件和头文件,因此在依赖包的Makefile中,必须增加define Build/InstallDev定义,并将对应的库文件和头文件安装。