openwrt开发之用户程序打包

打包用户程序到openwrt的固件bin文件

  

知道用户程序代码工程建立目录位置:openwrt/trunk/package,就可以开始建立工程了

 

1、建框架

进入openwrt/trunk/package,创建目录helloop,进入hellop目录,创建Makefile文件和src目录,进入src目录,创建helloop.c和Makefile

2、编辑helloop.c和同层makfile

 

/*******helloop.c start*********/

#include <stdio.h>

 

int main()

{

printf("hello openwrt!\n");

return 0;

}

/************helloop.c end ********/

 



/*******Makefile*********/

 

# build helloworld executable when user executes "make"

helloop: helloop.o

$(CC) $(LDFLAGS) helloop.o -o helloop

helloop.o: helloop.c

$(CC) $(CFLAGS) -c helloop.c

 

# remove object files and executable when user executes "make clean"

clean:

rm *.o helloop

 

/************makefile*********/

 

3、编辑上层makefile,即helloop目录的makefile

 

include $(TOPDIR)/rules.mk

 

PKG_NAME:=helloop

PKG_RELEASE:=1

 

 

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

 

 

include $(INCLUDE_DIR)/package.mk

 

 

 

define Package/helloop

SECTION:=utils

CATEGORY:=Utilities

TITLE:=helloop -- prints a snarky message

DEPENDS:= +libc

# DEPENDS:=+libstdcpp +libc

endef

 

 

define Build/Prepare

mkdir -p $(PKG_BUILD_DIR)

$(CP) ./src/* $(PKG_BUILD_DIR)/

endef

 

define Package/helloop/install

$(INSTALL_DIR) $(1)/bin

$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloop $(1)/bin/

endef

$(eval $(call BuildPackage,helloop))

 

4、menuconfig配置勾选

 

在openwrt源码顶层目录make menuconfig后,

进入Utilities  --->可以看到helloop,勾选。

<*> helloop.............. helloop -- prints a snarky message

 

5、编译整个工程,可以将用户程序打包至固件bin文件。

Make V=s

 

 

 附:makefile解析


  1. #-----官方文档如下
  2. This is the OpenWrt SDK. It contains a stripped-down version of the buildroot. You can use it to test/develop packages without having to compile your own toolchain or any of the libraries included with OpenWrt.
  3. To use it, just put your buildroot-compatible package directory in the subdir 'package/' and run 'make' from this directory.
  4. #------ OPENWRT集成非官方包之Makefile规则
  5. include $(TOPDIR)/rules.mk
  6. PKG_NAME:=[软件包名字 和文件夹名称一样]
  7. PKG_VERSION:=[软件包版本 自己写个]
  8. PKG_RELEASE:=1
  9. PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
  10. include $(INCLUDE_DIR)/package.mk
  11. define Package/$(PKG_NAME)
  12. SECTION:=utils
  13. CATEGORY:=[软件包在menuconfig里的位置 比如Base system]
  14. DEPENDS:=[依赖包 两个之间通过空格分隔 前面加+为默认显示 选中该软件包自动选中依赖包 不加+为默认不显示 选中依赖包才显示]
  15. TITLE:=[标题]
  16. PKGARCH:=[平台 比如ar71xx 全部写all]
  17. MAINTAINER:=[作者]
  18. endef
  19. define Package/$(PKG_NAME)/description
  20. [软件包简介]
  21. endef
  22. #非本目录下的源码文件, 拷贝到此相应目录下.
  23. # 如../../xucommon/xucommon.c, 则将 xucommon.c 拷贝到此目录下的源码的 ../../
  24. define Build/Prepare
  25. mkdir -p $(PKG_BUILD_DIR)
  26. $(CP) ./src/* $(PKG_BUILD_DIR)/
  27. endef
  28. define Build/Configure
  29. endef
  30. define Build/Compile
  31. endef
  32. define Package/$(PKG_NAME)/conffiles
  33. [升级时保留文件/备份时备份文件 一个文件一行]
  34. endef
  35. define Package/$(PKG_NAME)/install
  36. $(CP) ./files/* $(1)/
  37. endef
  38. define Package/$(PKG_NAME)/preinst
  39. [安装前执行的脚本 记得加上#!/bin/sh 没有就空着]
  40. #!/bin/sh
  41. uci -q batch <<-EOF >/dev/null
  42. delete ucitrack.@aria2[-1]
  43. add ucitrack aria2
  44. set ucitrack.@aria2[-1].init=aria2
  45. commit ucitrack
  46. EOF
  47. exit 0
  48. endef
  49. define Package/$(PKG_NAME)/postinst
  50. [安装后执行的脚本 记得加上#!/bin/sh 没有就空着]
  51. #!/bin/sh
  52. rm -f /tmp/luci-indexcache
  53. exit 0
  54. endef
  55. Package/$(PKG_NAME)/prerm
  56. [删除前执行的脚本 记得加上#!/bin/sh 没有就空着]
  57. endef
  58. Package/$(PKG_NAME)/postrm
  59. [删除后执行的脚本 记得加上#!/bin/sh 没有就空着]
  60. endef
  61. $(eval $(call BuildPackage,$(PKG_NAME)))

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值