使用普通用户做任何事:不要用root登录,不要使用sudo 构建目录的完整的路径名中不要包含空格 |
标准的构建流程:
# 下载并更新源代码
git clone https://git.openwrt.org/openwrt/openwrt.git openwrt
cd openwrt
git pull
# 选择一个确定的代码分支
git branch -a
git tag
git checkout v19.07.8
# 更新feeds
./scripts/feeds update -a
./scripts/feeds install -a
# 设置固件映像和kernel
make menuconfig
make kernel_menuconfig
# 构建固件映像
make -j $(nproc) defconfig download clean world
构建步骤的解释如下所示。
下载源代码
使用如下命令拉取Git代码仓库
git clone https://git.openwrt.org/openwrt/openwrt.git [<buildroot>]
可能出现的问题:
- -bash: git: command not found – 检查你的构建系统设置.
- fatal: destination path 'openwrt' already exists and is not an empty directory. – 移除或者重命名构建根目录.
更新源代码
开发分支上面的代码变动频繁,建议你使用最新代码
git pull
可能的问题:
- -bash: cd: openwrt: No such file or directory – 检查构建根目录.
- fatal: not a git repository (or any of the parent directories): .git – 工作目录应该位于clone的根目录.
更新Feeds
feeds可能会过期,所以需要拉取最新的feeds。
./scripts/feeds update -a
确保在 make menuconfig 的时候下载的包有效。
./scripts/feeds install <package_name>
./scripts/feeds install -a
可能出现的问题:
- -bash: ./scripts/feeds: No such file or directory -工作目录应该位于clone的根目录.
-
Can't exec "make": No such file or directory at ./scripts/feeds line 22. Unsupported version of make found: make Checking 'gcc'... failed. Checking 'working-gcc'... failed. Checking 'g++'... failed. Checking 'working-g++'... failed. Checking 'ncurses'... failed. Checking 'awk'... failed. Checking 'unzip'... failed. Checking 'bzip2'... failed. Checking 'wget'... failed. Checking 'python'... failed. Checking 'python3'... failed. Checking 'file'... failed.
- 检查构建系统的设置。
创建一个本地的订阅源(feed)
- 在feeds.conf.default中添加一行src-link my_packages <buildroot>/my_packages 使用你clone的openwrt的根目录(例如~/openwrt)替换<buildroot>。
- 创建目录 mkdir -p <buildroot>/my_packages/<section>/<category>/<package_name> 使用你的包名替换<package_name>(例如mkdir -p my_packages/net/network/rpcbind)。章节和类别可以在 Makefile找到。
- 从github下载Makefile ,从sources.openwrt.org下载源包,放置在 <package_name>目录。
- 执行./scripts/feeds update -a; ./scripts/feeds install <package_name>
- 如果你这么做的目的是要解决依赖问题的话,你可以多运行一次install,你应该注意到依赖问题已经解决了。
注意:如果你想覆盖一个已经存在订阅源的包,你必须把你的订阅源写在你想重写的包的订阅源行之上。
例如:你希望制作一个已经在Packages订阅源上架的包的定制版本,你的feeds.conf.default应该看起来像这样(第一行是你定制的包的订阅源)
src-link local /path/to/local/custom/feed
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
选择指定的代码版本
如果你希望构建最新版本,可以跳过此步骤。
指定分支
每个分支包含发布版本(例如17.01, 18.06, 19.07)的基线代码和独立的release(例如17.01, 18.06, 19.07)。每一个分支都努力的包含稳定的代码。这些代码都是从开发分支中小心的选择并更新补丁而得到的。
为了使用分支,你首先需要使用上面描述的git clone命令clone Git代码仓库,然后使用git checkout命令切换到指定的分支。
# 列出分支
git branch -a
# 使用 OpenWrt 19.07 分支
git checkout openwrt-19.07
一旦切换分支,建议你使用make distclean命令进行一次源代码树的完整的清洗。确保你的源代码树里面不会保留着上一次构建遗留下来的构建物或者配置文件。
指定独立的release/tag
请参阅
https://forum.openwrt.org/t/checkout-a-tagged-releases-source-code-like-v18-06-1/1256
上面的解释和建议在此处也有效。如果你希望可以长时间从代码仓库安装包,这个可能会有用。
# 拉取并列出tags
git fetch -t
git tag
# 使用 OpenWrt 19.07.8 发布
git checkout v19.07.8
检出指定的代码版本
将所有的订阅源和一个指定的OpenWrt代码版本同步(未明确其含义)
REV_HASH="4c73c34ec4215deb690bf03faea2a0fe725476f0"
git checkout ${REV_HASH}
REV_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
sed -e "/^src-git\S*/s//src-git-full/" feeds.conf.default > feeds.conf
./scripts/feeds update -a
sed -n -e "/^src-git\S*\s/{s///;s/\s.*$//p}" feeds.conf \
| while read -r FEED_ID
do
REV_DATE="$(git log -1 --format=%cd --date=iso8601-strict)"
REV_HASH="$(git -C feeds/${FEED_ID} rev-list -n 1 --before=${REV_DATE} ${REV_BRANCH})"
sed -i -e "/\s${FEED_ID}\s.*\.git$/s/$/^${REV_HASH}/" feeds.conf
done
./scripts/feeds update -a
./scripts/feeds install -a