406 字
2 分钟
MacOS 环境下编译 ImmortalWRT 一二事

硬件说明#

  • Mac mini M4

注意:MacOS 系统应为 “大小写敏感”,否则无法编译!

环境准备#

安装 Xcode 环境#

在 App Store 中安装 Xcode

安装 Homebrew#

直接复制下面命令到终端即可

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

如果你没有合适的网络环境,可以使用修改后的脚本,按照提示操作

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

安装编译所需的依赖#

Terminal window
brew unlink awk
brew install coreutils diffutils findutils gawk gnu-getopt gnu-tar grep make ncurses pkg-config wget quilt xz
brew install gcc@11

intel 芯片

echo 'export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/usr/local/opt/gnu-getopt/bin:$PATH"' >> ~/.bashrc
echo 'export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Apple M 系列芯片

echo 'export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/opt/homebrew/opt/gnu-getopt/bin:$PATH"' >> ~/.bashrc
echo 'export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"' >> ~/.bashrc
echo 'export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"' >> ~/.bashrc
source ~/.bashrc

初始化编译环境#

Terminal window
# 拉取源代码
git clone -b master --single-branch --filter=blob:none https://github.com/immortalwrt/immortalwrt
# 或者使用 openwrt 24
git clone -b openwrt-24.10 --single-branch --filter=blob:none https://github.com/immortalwrt/immortalwrt
cd immortalwrt
# 添加 small 源
sed -i '1i src-git kenzo https://github.com/kenzok8/openwrt-packages' feeds.conf.default
sed -i '2i src-git small https://github.com/kenzok8/small' feeds.conf.default
# 更新 feed 源
./scripts/feeds update -a && rm -rf feeds/luci/applications/luci-app-mosdns
rm -rf feeds/packages/net/{alist,adguardhome,mosdns,xray*,v2ray*,v2ray*,sing*,smartdns}
rm -rf feeds/packages/utils/v2dat
rm -rf feeds/packages/lang/golang
git clone https://github.com/kenzok8/golang feeds/packages/lang/golang
./scripts/feeds install -a

配置 OpenWRT 选项#

Terminal window
make menuconfig

编译固件#

Terminal window
make -j$(nproc) V=s
  • 编译 Alist 时可能会报 fuse.h 文件未找到 的问题,这里提供下我的解决方法:
brew install --cask macfuse
# 如果安装后还会有相同的错误,按照下面的方式设置
TARGET_CFLAGS="<path_to_macfuse_include>"
TARGET_LDFLAGS="<path_to_macfuse_lib>"
# 确保 MacOS 已经加载 macFUSE9 (如果加载可以在访达中看到 macFUSE)
sudo kextload /Library/Filesystems/macfuse.fs/Contents/Extensions/11/macfuse.kext
  • go 不支持 MacOS
brew install go
# make menuconfig 后选择使用外部的 go /opt/homebrew/go
MacOS 环境下编译 ImmortalWRT 一二事
https://fuwari.vercel.app/posts/openwrt_macos/
作者
脆脆鲨
发布于
2025-02-28
许可协议
CC BY-NC-SA 4.0