基于openwrt添加自己的应用程序

接着上一篇,搭建好了环境以后:

       第一步下载源码后编译(源码存放的路径不能包含中文):

 openwrt_widore源码结构
ubuntu@ubuntu:~/Desktop/openwrt_widora$ make
 make[1] world
 make[2] target/compile
 make[3] -C target/linux compile
 make[2] package/cleanup
 make[2] package/compile
 make[3] -C package/libs/toolchain compile
 make[3] -C package/LetThink compile
 make[3] -C package/libs/libnl-tiny compile
 make[3] -C package/libs/libjson-c compile
 make[3] -C package/utils/lua compile
 make[3] -C package/libs/libubox compile
 make[3] -C package/system/ubus compile
 make[3] -C package/system/uci compile
 make[3] -C package/network/config/netifd compile
 make[3] -C package/system/opkg host-compile
 make[3] -C package/system/ubox compile
 make[3] -C package/libs/lzo compile
 make[3] -C package/libs/zlib compile
 make[3] -C package/libs/ncurses host-compile
 make[3] -C package/libs/ncurses compile
 make[3] -C package/utils/util-linux compile
 make[3] -C package/utils/ubi-utils compile
 make[3] -C package/system/procd compile
 make[3] -C package/system/usign host-compile
 make[3] -C package/utils/jsonfilter compile
 make[3] -C package/system/usign compile
 make[3] -C package/base-files compile
 make[3] -C package/system/fstools compile
 make[3] -C package/boot/uboot-envtools compile
 make[3] -C package/kernel/gpio-button-hotplug compile
 make[3] -C package/firmware/linux-firmware compile
 make[3] -C package/kernel/linux compile
 make[3] -C package/libs/polarssl compile
 make[3] -C package/network/utils/iptables compile
 make[3] -C package/network/config/firewall compile
 make[3] -C package/network/config/swconfig compile
 make[3] -C package/network/ipv6/odhcp6c compile
 make[3] -C package/network/services/dnsmasq compile
 make[3] -C package/network/services/dropbear compile
 make[3] -C package/libs/ocf-crypto-headers compile
 make[3] -C package/libs/openssl compile
 make[3] -C package/network/services/hostapd compile
 make[3] -C package/network/services/odhcpd compile
 make[3] -C package/libs/libpcap compile
 make[3] -C package/network/utils/linux-atm compile
 make[3] -C package/network/utils/resolveip compile
 make[3] -C package/network/services/ppp compile
 make[3] -C package/network/utils/curl compile
 make[3] -C package/network/utils/iwinfo compile
 make[3] -C package/system/mtd compile
 make[3] -C package/system/opkg compile
 make[3] -C package/utils/busybox compile
 make[2] package/install
 make[3] package/preconfig
 make[2] target/install
 make[3] -C target/linux install
 make[2] package/index
ubuntu@ubuntu:~/Desktop/openwrt_widora$ 

编译通过,证明自己搭建的开发环境Ok.

   第二步:在/openwrt_widora/package/ 目录中添加加自己的应用程序代码:首先建立自己的项目工程文件夹:LetThink,在其中再添加自己的源文件目录src以及在/home/ubuntu/Desktop/openwrt_widora/package/LetThink/Makefile中编写烧入到openwrt中的规则:

src目录:

Makefile编写规则:

include $(TOPDIR)/rules.mk

PKG_NAME:=LetThink
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/LetThink
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=LetThink -- prints a snarky message
endef

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

define Build/Prepare
	echo "Here is Package/Prepare"
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) -rf ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
	$(TARGET_CC) $(TARGET_CFLAGS) -fprofile-generate -o $(PKG_BUILD_DIR)/LetThink $(PKG_BUILD_DIR)/source/*.c -I$(PKG_BUILD_DIR)/include/ 
endef
define Package/LetThink/install
	echo "Here is Package/install"
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/LetThink $(1)/bin/
endef
    
$(eval $(call BuildPackage,LetThink))

 添加自己的应用程序包,并编译 make V=s:

 

编译成功后,在/home/ubuntu/Desktop/openwrt_widora/bin/ramips/packages/base/ 发现生成的LetThink_1_ramips_24kec.ipk,以及/home/ubuntu/Desktop/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/生成的LetThink目录。

将生成的ipk包以及LetThink可执行用WinScp上传到OpenWrt路由器中:执行验证 opkg install LetThink_1_ramips_24kec.ipk或者直接运行可执行 ./ LetThink.

 

验证通过!!!

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ya土豆儿~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值