分享记录下去年调试 openwrt 项目的方法,openwrt 的第一个 hello_world 应用程序 hello_world.ipk,需要以下几个步骤:
1.在 ./package 目录下新建 hello_world 目录
2.在 ./package/hello_world /目录下创建 Makefile 和 "src" 目录
3.在 ./package/hello_world/src/ 目录下添加 hello_world.c 和 Makefile
# ll ./package/hello_world/
# ./package/hello_world/Makefile
# ./package/hello_world/src/hello_world.c
# ./package/hello_world/src/Makefile
# ./package/hello_world/Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=hello_world
PKG_VERSION:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/hello_world
SECTION:=base
CATEGORY:=Utilities
TITLE:=Hello world -prints a hello world message
endef
define Package/hello_world/description
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/hello_world/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello_world $(1)/bin/
endef
$(eval $(call BuildPackage,hello_world))
# ./package/hello_world/src/Makefile
all:hello_world
hello_world:hello_world.o
$(CC) $(LDFLAGS) hello_world.o -o hello_world
hello_world.o:hello_world.c
$(CC) $(CFLAGS) -c hello_world.c
clean:
rm *.o hello_world
# ./package/hello_world/src/hello_world.c
#include <stdio.h>
int main(char argc,char *argv[])
{
int i = 0;
while(1)
{
printf("Hello world!!!%d\n",i);//打印内容
i++;
if(i>10) i=0;
sleep(1);
}
return 0;
}
未完,待续......