怎么创建openwrt软件包

发布时间:2021-08-06 23:56:35 作者:chen
来源:亿速云 阅读:295

本篇内容介绍了“怎么创建openwrt软件包”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

方法一

1、生成SDK

make menuconfig选上“Build the OpenWRT SDK”,然后 Save,退出。再make一次。
make 完成之后,在 bin/ramips/ 目录下会生成SDK的压缩文件:
OpenWrt-SDK-ramips-rt305x_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2

2、安装SDK

把上面生成的OpenWrt-SDK-ramips-rt305x_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2解压到别的目录下

3、创建helloworld项目

其实,这里可以是任意我们想要加入的程序,库等。这里就以helloword为例。
在任意路径下,创建helloword项目。比如这里还是在 ~/Workspace/OpeWRT 目录下。
 

$ cd ~/Workspace/OpenWRT
$ mkdir helloword
$ cd helloword
$ touch helloword.c Makefile

在 ~/Workspace/OpenWRT/ 目录下创建了 helloword 目录,并生成 helloword.c与Makefile文件。
如下为 helloworld.c的内容:

#include <stdio.h>
 
int main()
{
    printf("This is my hello word!\n");
    return 0;
}

Makefile的内容:

helloworld : helloworld.o
    $(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o : helloworld.c
    $(CC) $(CFLAGS) -c helloworld.c

clean :
    rm *.o helloworld

自己make一下确保程序没有问题,一定要注意tab键空格。
 

4、创建helloworld包

进入 OpenWrt/Packages/ 并在该目录下创建 helloworld 目录,并进入该目录。

$ cd ~/Workspace/OpenWrt/OpenWrt-SDK/package
$ mkdir helloworld
$ cd helloworld

将我们第三步写的程序复制到这个目录下来,更名为src。再新建一个 Makefile 文件。

$ cp -r ../../../helloworld src
$ touch Makefile

整个过程下来,package目录结构如下:

package
|-- helloworld
|   |-- Makefile
|   `-- src
|       |-- helloworld.c
|       `-- Makefile
`-- Makefile

Makefile 文件如下:

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/helloworld
	SECTION:=utils
	CATEGORY:=Utilities
	TITLE:=Hello world!!!
	DEPENDS:=+libwebsockets +libsqlite3 +libjson-c
endef

define Package/helloworld/description
	It's my first package demo.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Package/helloworld/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/sbin
endef

$(eval $(call BuildPackage,helloworld))

make -j1 V=s 成功了。生成了 helloworld_1_ramips_24kec.ipk。
 

5、试验helloworld

通过WinSCP把ipk上能到openwrt根目录下的/tmp

cd /tmp
opkg install helloworld_1_ramips_24kec.ipk

用which命令查看 helloworld 安装的路径:

which helloworld

在 /bin/ 路径下

cd /bin
helloworld

方法二

1、创建helloworld项目

把方法一创建helloworld文件夹复制到openwrt根目录下的package。

2、选择helloworld项目

make menuconfig

Utilities——》helloworld勾选上并保存退出

make -j3 V=s

如果要单独编译模块:

make package/helloworld/compile
make package/helloworld/install

3、试验helloworld

cd /bin
helloworld

4、后续开发

把新helloworld文件替换旧hellworld文件

重新编译

make package/helloworld/compile

在openwrt目录的./build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/helloworld/ipkg-ramips_24kec/helloworld/bin下找到重新生成的helloworld文件,重新替换路由器/bin下面的helloworld。

“怎么创建openwrt软件包”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 如何理解openwrt libubox 开发
  2. rpmbuild使用---创建nrpe,nagios-plugins软件包

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

openwrt

上一篇:怎么使用CSS3的appearance属性改变元素的外观

下一篇:如何解决某些HTML字符打不出来的问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》