您的位置:首页 > 运维架构

openwrt 添加软件包案例

2015-09-10 10:26 441 查看
添加软件包的方法

1.我的openwrt的源码目录(编译后)为/home/zhangxx/owt/backfire (编译后会多出 /bin /build_dir /dl 三个目录。

自己上网查看这三个目录的用途 附上网址:http://bbs.tawei.com/thread-409-1-1.html)

.

├── bin

├── BSDmakefile

├── build_dir

├── Config.in

├── dl

├── docs

├── feeds

├── feeds.conf.default

├── include

├── LICENSE

├── Makefile

├── Makefile~

├── package

├── README

├── rules.mk

├── scripts

├── staging_dir

├── tags

├── target

├── tmp

├── toolchain

└── tools

2.进入源码的package目录,创建hello目录,进入hello目录,在hello目录下创建src目录和Makefile文件

$ cd /home/zhangxx/owt/package

$ mkdir hello

$ cd hello

$ mkdir src

$ touch Makefile

3.进入src目录,创建hello.c文件和Makefile文件

$ cd hello

$ touch hello.c Makefile

4.分别编写src目录下的hello.c Makefil文件

hello.c 文件

#include <stdio.h>

#include <unistd.h>

int main(void)

{

printf("hello!\n");

return 0;

}

Makefile 文件

hello : hello.o

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

hello.o : hello.c

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

clean :

rm *.o hello

5.编写hello下的Makefile文件, 这个Makefile 文件可以参考package下的其他文件夹里面的Makefile,参考资料上网http://bbs.tawei.com/thread-409-1-1.html “OpenWrt增加软件包方法”

Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=hello

PKG_RELEASE:=1

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

include $(INCLUDE_DIR)/package.mk

define Package/hello

SECTION:=utils

CATEGORY:=Utilities

TITLE:=hello -- prints a snarky mwssage

endef

define Package/hello/description

It's my first package demo.

endef

define Build/Prepare

echo "Here is Package/Prepare"

mkdir -p $(PKG_BUILD_DIR)

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

endef

define Package/hello/install

echo "Here is Package/install"

$(INSTALL_DIR) $(1)/bin

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

endef

$(eval$(call BuildPackage,hello))

6.进入openwrt的源码目录 /home/zhangxx/owt/backfire 然后 make menuconfig 在Utilities可以看到hello的选项

$ cd /home/zhangxx/owt/backfire

$ name menuconfig

选择Utilities --->

< > hello................................... hello -- prints a snarky mwssage
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: