加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

开发openwrt应用程序

(2014-07-14 08:51:43)
标签:

it

分类: openwrt

1. 创建工作目录

Shell
1
2
3
4
cd /path/to/openwrt/package
mkdir example
cd example
mkdir  src

2. 编写代码(放到src目录):

Shell
int main(void) {   printf(“Hello, world\n”);   return 0; }
1
2
3
4
5
6
#include
int main(void)
{
  printf(Hello, world\n);
  return 0;
}

3. 编写编译所写程序的Makefile(放到src目录):

Shell
1
2
3
4
5
6
7
8
9
10
11
12
# build executable on typing make
all: example
 
%.o: %.c
 
    $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -I. -Iinclude -o $@ $^
 
example: main.o
    $(CC) -o $@ $^ -L.
 
clean:
    rm -f *.o example

4. 编写openwrt的Makefile把程序集成到openwrt编译系统(放入example目录):

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
# Top level makefile for example application
#
 
include $(TOPDIR)/rules.mk
 
PKG_NAME:=example
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
 
include $(INCLUDE_DIR)/package.mk
 
define Package/example
SECTION:=utils
CATEGORY:=Utilities
TITLE:=example -- prints example 1 to 99
endef
 
define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)
endef
 
define Build/Configure
endef
 
TARGET_CFLAGS += $(FPIC)
 
define Package/example/install
    $(INSTALL_DIR) $(1)/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/example $(1)/bin/
endef
 
$(eval $(call BuildPackage,example))

有了这几步就可以通过make menuconfig选择example程序来编译(上面指定了Utilities分类)。单独编译程序可以用下面命令:

Shell
1
2
3
make package/example/compile
make package/example/install
make package/index

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有