开发openwrt应用程序
(2014-07-14 08:51:43)
标签:
it |
分类: openwrt |
1. 创建工作目录
1
2
3
4
|
cd /path/to/openwrt/package
mkdir example
cd example
mkdir
|
2. 编写代码(放到src目录):
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目录):
1
2
3
4
5
6
7
8
9
10
11
12
|
# build executable on typing
make
all: example
%.o: %.c
example:
main.o
clean:
|
4. 编写openwrt的Makefile把程序集成到openwrt编译系统(放入example目录):
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
endef
define Build/Configure
endef
TARGET_CFLAGS += $(FPIC)
define Package/example/install
endef
$(eval $(call BuildPackage,example))
|
有了这几步就可以通过make menuconfig选择example程序来编译(上面指定了Utilities分类)。单独编译程序可以用下面命令:
1
2
3
|
make package/example/compile
make package/example/install
make package/index
|
前一篇:nodog安装配置