源码
切换到 openwrt 源码根目录,然后执行下列命令:
mkdir hello_world //创建一个名为“hello_world”的文件夹,用于放置安装包源码。
cd hello_world //进入“hello_world”目录
mkdir src //新建一个名为“src”的目录用于放置源码
mkdir root //新建一个名为“root ”的目录用于放置文件
vi src/hello_world.c //在 src 目录下新建一个名为 hello_world.c 文件
输入 hello_world.c 中的内容:
#include <stdio.h>
int main(char argc, char *argv[])
{
int i = 1;
while(1){
//1~10 循环
printf("Hello world!!!%d\n",i); //打印内容
if (i < 10){
i++;
}else{
i = 1;
}
sleep(1);// 一秒钟打印一次
}
return 0;
}
vi src/Makefile,//在 src 目录下新建一个 Makefile,输入下面内容:
all: hello_world
hello_world: hello_world.o
$(CC) $(LDFLAGS) hello_world.o -o hello_world
helloworld.o: hello_world.c
$(CC) $(CFLAGS) -c hello_world.c
clean:
rm *.o hello_world
vi 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/
$(CP) $(PKG_BUILD_DIR)/root/* $(1)/
endef
$(eval $(call BuildPackage,hello_world))