以创建一个最简单的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内容:
-
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打印出来,说明编译成功了(在backfire/bin/brcm47xx/packages目录下能找到hello.ipk)。或者make package/hello/compile V=99也可单独编译hello的ipk包。
六、将生成的ipk包用ftp工具上传到路由器上的/tmp目录下,用ssh连接到路由器上到/tmp目录下执行opkg install xxxx.ipk
阅读(1507) | 评论(0) | 转发(0) |