openwrt搭建应用ipk

过程
一、工程搭建
在\172.18.3.99\work\T750\fg360-open-sdk\openwrt\package新建hello目录
hello目录下建Makefile和src目录
src目录建hello.c Makefile
填写内容
1、编写源文件和源文件编译的makefile
在这里插入图片描述

#include <stdio.h>
#include <unistd.h>

int main()
{
    
    
    int i = 0;
    while(i < 10)
    {
    
    
        printf("hello guoguo\n");
        i++;
        sleep(1);
    }
    return 0;
}
#CC=gcc
WFLAGS=-Wall 
CFLAGS=-O2 
INCLUDES= -I./

all:hello
hello:hello.o
	$(CC) hello.o -o hello
hello.o:hello.c
	$(CC) $(CFLAGS) -c hello.c
clean:
	rm -rf *.o hello
hello:hello.o
	$(CC) hello.o -o hello
hello.o:hello.c
	$(CC) $(CFLAGS) -c hello.c
clean:
	rm -rf *.o hello

2、编写系统makefile
在这里插入图片描述

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
 
PKG_NAME:=hello
PKG_VERSION=1
PKG_RELEASE:=1.0
 
PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
 
include $(INCLUDE_DIR)/package.mk
 
define Package/hello
	SECTION:=utils
	CATEGORY:=hello
	TITLE:=hello
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)
endef
 
define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
                $(TARGET_CONFIGURE_OPTS) \
                CFLAGS="$(TARGET_CFLAGS)" \
                CPPFLAGS="$(TARGET_CPPFLAGS)" \
                LDFLAGS="$(TARGET_LDFLAGS)"
endef
 
define Package/hello/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello $(1)/bin/
endef
 
$(eval $(call BuildPackage,hello))

3、编写启动脚本

二、编译
1、添加应用到配置
root@075b49df5d1c:/home/work/sdk/T750_V1.0.15_1/fg360-open-sdk/openwrt# make menuconfig

2、编译
编译
进入\172.18.3.99\work\T750\fg360-open-sdk\openwrt目录
make menuconfig

选择
Utiltles -->
hello…
保存退出

make package/hello/compile V=s
make package/hello/install

生成文件在
bin/{TARGET}/package目录下:hello.ipk

三、安装
1、传输生成的opk文件到开发部
2、安装
opkg install hello.ipk

猜你喜欢

转载自blog.csdn.net/u010835747/article/details/121407769