斐讯K2 mentohust 编译

我在网络上没有找到合适的mentohust可执行文件,找到的怎么也连接不上校园网。
只能尝试自己编译了。

幸运的是,我自己编译的版本,使用正常。你如果使用的设备和我一样,可以直接前往本文末尾,下载我编译好的版本。


我首先参考的是:KyleRicardo/MentoHUST-OpenWrt-ipk: MentoHUST-OpenWrt-ipk包 这一个项目,他是通过下载OpenWrt 源码来编译的。这样做的速度非常慢,编译一整套工具链,而且还需要下载东西(国外的服务器连接,一言难尽啊)。
他选择使用源码,可能是由于直接使用SDK会得不到libpcap.a。实际上,这是可以解决的。我最终还是使用的SDK。(源码实在是太慢了)

准备OpenWrt SDK

在这里:https://downloads.openwrt.org/releases/ 找到对应版本架构的SDK

例如我的:https://downloads.openwrt.org/releases/18.06.8/targets/ramips/mt7620/

wget https://downloads.openwrt.org/releases/18.06.8/targets/ramips/mt7620/openwrt-sdk-18.06.8-ramips-mt7620_gcc-7.3.0_musl.Linux-x86_64.tar.xz

注意文件名,一定是下载SDK。

解压SDK,进入SDK根目录。以后的操作,没有特殊说明,都是在SDK根目录中

下载libpcap

libpcap是mentohust重要的依赖,所以需要libpcap,mentohust才能正常编译

# 建议使用代理,下载还是挺慢的,在国内
./script/feeds update -a
./script/feeds install libpcap

下载mentohust,并配置

# 这里使用的就是之前参考的那个项目的
git clone https://github.com/KyleRicardo/MentoHUST-OpenWrt-ipk.git package/mentohust

接下来需要配置mentohust

nano package/mentohust/Makefile

这里需要修改Makefile文件。
由于在18.06.8版本的SDK中会自动将构建过程中生成的中间文件删除,然而我们的mentohust项目编译又依赖这些中间文件,这就会导致我们的编译失败。

关闭 menuconfig -> Advanced configuration options (for developers) -> Automatic removal of build directories 功能即可正常编译

https://github.com/KyleRicardo/MentoHUST-OpenWrt-ipk/issues/2#issuecomment-685219295

据说可以通过这样的方法关闭,然而在SDK中居然没有Advanced configuration options (for developers) 这个配置选项。
虽然在 .config 文件中,好像有一行好像可以关闭自动删除。然而,.config 文件不能手动修改,修改了会自动被修复。
我没有在网上找到关闭的方法。所以,我选择修改mentohust的编译过程。

在mentohust的正式编译前,将所需要libpcap复制到需要的位置

define Package/mentohust/description
A Ruijie Client Daemon,
Most usually used in China collages.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	mkdir -p /home/xiyu/openwrt-sdk-18.06.8-ramips-mt7620_gcc-7.3.0_musl.Linux-x86_64/build_dir/target-mipsel_24kc_musl/libpcap-*/ipkg-install/usr/lib/
	$(CP) ~/openwrt-sdk-18.06.8-ramips-mt7620_gcc-7.3.0_musl.Linux-x86_64/staging_dir/target-mipsel_24kc_musl/usr/lib/* /home/xiyu/openwrt-sdk-18.06.8-ramips-mt7620_gcc-7.3.0_musl.Linux-x86_64/build_dir/target-mipsel_24kc_musl/libpcap-*/ipkg-install/usr/lib/
	$(CP) ./src/* $(PKG_BUILD_DIR)/
	@echo hello
	$(SED) 's/dhclient/udhcpc -i/g' $(PKG_BUILD_DIR)/myconfig.c
endef


define Package/mentohust/conffiles
/etc/mentohust.conf
endef

在上面第八行(不是原Makefile文件),我创建了所需要的目录,在第九行,复制了需要的文件到对应的目录。可以看到,我都是硬编码的。(●'◡'●)

不知道要不要改libpcap的Makefile 不需要

编译

make package/mentohust/compile V=s
$ tree bin
bin
├── packages
│   └── mipsel_24kc
│       └── base
│           ├── libpcap_1.9.1-1_mipsel_24kc.ipk
│           └── mentohust_0.3.1-1_mipsel_24kc.ipk
└── targets
    └── ramips
        └── mt7620
            └── packages
                ├── libatomic_7.3.0-2_mipsel_24kc.ipk
                ├── libc_1.1.19-2_mipsel_24kc.ipk
                ├── libgcc_7.3.0-2_mipsel_24kc.ipk
                ├── libpthread_1.1.19-2_mipsel_24kc.ipk
                ├── librt_1.1.19-2_mipsel_24kc.ipk
                └── libstdcpp_7.3.0-2_mipsel_24kc.ipk

7 directories, 8 files

生成的包会在 SDK/bin/packages/架构/base/目录下

已编译的适用于K2路由的版本下载

斐讯K2路由器可用,其他相同架构的路由器(ramips/mt7620)应该也可以使用。

链接: https://pan.baidu.com/s/1dU_OVZ1zYqcvdvpJdv2X5A 提取码: kgw4

使用

# 两个文件
$ ls | grep ipk
libpcap_1.9.1-1_mipsel_24kc.ipk
mentohust_0.3.1-1_mipsel_24kc.ipk
# 先安装依赖libpcap
opkg install libpcap_1.9.1-1_mipsel_24kc.ipk
opkg install mentohust_0.3.1-1_mipsel_24kc.ipk

参考:

KyleRicardo/MentoHUST-OpenWrt-ipk: MentoHUST-OpenWrt-ipk包

OpenWrt Project: Using the SDK

posted @ 2021-03-21 11:27  夕雨714  阅读(292)  评论(0编辑  收藏  举报