原文地址:http://blog.csdn.net/viviwen123/article/details/23931809
以创建一个最简单的hello world为例。
一、在packages中创建hello目录,在hello目录下创建src目录。
二、hello/Makefile内容:
-
include $(TOPDIR)/rules.mk
-
-
-
PKG_NAME:=hello
-
PKG_VERSION:=5.0
-
PKG_RELEASE:=1
-
-
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
-
-
include $(INCLUDE_DIR)/package.mk
-
-
define Package/$(PKG_NAME)
-
SECTION:=utils
-
CATEGORY:=Utilities
-
TITLE:=hello -- a Test Program
-
MAINTAINER:=wuzhiwen
-
endef
-
-
define Package/$(PKG_NAME)/description
-
a test program
-
endef
-
-
define Build/Prepare
-
mkdir -p $(PKG_BUILD_DIR)
-
$(CP) ./src/* $(PKG_BUILD_DIR)/
-
endef
-
-
define Package/hello/install
-
$(INSTALL_DIR) $(1)/bin
-
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello $(1)/bin/
-
endef
-
-
$(eval $(call BuildPackage,hello))
三、/hello/src/main.c内容:
-
#include
-
#include
-
-
int main()
-
{
-
printf("Hello World\n");
-
exit (EXIT_SUCCESS);
-
}
四、/hello/src/Makefile内容:
-
OBJECTS = hello
-
-
all : $(OBJECTS)
-
-
PKG_NAME=docs
-
-
hello: main.o
-
$(CC) $(LDFLAGS) $^ -o $@
-
-
main.o:main.c
-
$(CC) $(CFLAGS) -c $<
-
-
.PHONY:clean
-
clean:
-
@-rm *.o hello
五、make menuconfig,在Utilities中找到hello,选择上,保存退出。make V=99,编译固件,刷到路由器上,在终端输入hello,一行Hello World打印出来,说明编译成功了(在/bin目录下能找到hello)。或者make package/hello/compile V=99也可单独编译hello的ipk包。
Makefile的缩进要用tab,不然无法识别。
打包好的hello目录里的文件:
官方wiki:http://wiki.openwrt.org/doc/devel/packages?s[]=pkg&s[]=source或者:http://wiki.openwrt.org/zh-cn/doc/devel/packages
阅读(1175) | 评论(0) | 转发(1) |