安装好交叉编译环境,在package目录建立hello_world目录,用于存放hello_world的相关Makefile文件和.c文件,hello_world目录建立src目录和Makefile文件,src目录建立hello_world.c 和 Makefile。
openwrt@qk365-openwrt:~/qsdk$ mkdir package/hello_world
openwrt@qk365-openwrt:~/qsdk$ mkdir package/hello_world/src
openwrt@qk365-openwrt:~/qsdk$ vim package/hello_world/Makefile
//编写hello_world下的Makefile文件
openwrt@qk365-openwrt:~/qsdk$vim package/hello_world/src/Makefile
//编写src下的Makefile文件
openwrt@qk365-openwrt:~/qsdk$vim package/hello_world/src/hello_world.c
hello_world目录下的Makefile
include $(TOPDIR)/rules.mk
//包含相关规则
PKG_NAME:=hello_world //package名字
PKG_VERSION:=1.0 //package版本
PKG_RELEASE:=1 //package发布版本
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
//package路径
include $(INCLUDE_DIR)/package.mk
define Package/hello_world
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Hello workd -prints a hello world message
endef
define Package/hello_world/description
If you can't figure out what this program does,you're probaly brain-dead and need immediate medical attention.
endef
define Build/Prepare
echo "Here is Package/Prepare"
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/hello_world/install
echo "Here is Package/install"
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello_world $(1)/usr/bin/
endef
$(eval $(call BuildPackage,hello_world))