OpenWrt添加软件包之二helloworld实例

第一步创建目录编写代码

首先在<BUILDROOT>/package/目录下创建一个目录,其名称一般为你要添加的软件包的名称。比如 helloworld,然后在<BUILDROOT>/package/helloworld 添加一个Makefile文件并且创建一个目录 src,用来保存自己写的代码。
src中加入两个文件 helloworld.c 和 Makefile。结构如下:
在这里插入图片描述

  • 将以下内容分别拷进src的hellworld与Makefile
#include <stdio.h>
void main()
{ printf("hello word!\n");}
helloworld : helloworld.o
        $(CC) $(LDFLAGS) helloworld.o -o helloworld
helloworld.o : helloworld.c
        $(CC) $(CFLAGS) -c helloworld.c
clean :
        rm *.o helloworld

重点是这个Makefile内容 点击参考概述

  • 将以下内容复制到外层Makefile cd .. ; vi Makefile
include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_VERSION:=1.0

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk

define Package/helloworld
  CATEGORY:=Helloworld
  TITLE:=Helloworld -- by hzlarm
endef

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

define Package/helloworld/install
        $(INSTALL_DIR) $(1)/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef

$(eval $(call BuildPackage,helloworld))
第二步 编译

到顶层目录 make menuconfig配置(默认原始SDK都配置好,可以跑通的前提下)
在这里插入图片描述
选中为*:(这里选择 * 将其编译进固件。或者选为M编译模块)
在这里插入图片描述
保存编译 make V=s 或者make V=99都可以,编译时打印更多的信息。在openwrt/include/verbose.mk文件里面说如果V=99,那么V=s。
模块编译选择 make package/helloworld/compile V=s

第三步 运行
  • 把生成文件拷到开发板openwrt/bin/ramips/packages/base/helloworld_xxx.ipk
    安装
    opkg install helloworld_xxx.ipk
	$ which helloworld 
	/bin/helloworld
  • 把固件烧写进去,因为helloworld已经包含在固件中。
    openwrt/bin/<arch>/xxx.bin就是编译生成的文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值