美文网首页
openwrt生成apk

openwrt生成apk

作者: 嵌入式工作 | 来源:发表于2018-11-22 17:45 被阅读0次

    在建立文件夹和文件

    cd package/utils/
    mkdir hello_world
    cd hello_world
    mkdir src
    vim src/hello_world
    
    

    编辑hello_world.c

    #include <stdio.h>
    
    int main(char argc ,char *argv[])
    {
        int i=1;
        while(1)
        {
            printf("hello world!!!!!%d\r\n",i++);
            if(i>10)
            {
                i=1;
            }
            sleep(1);
            
            
        }
        return 0;
        
    }
    
    

    在src下面编辑Makefile , vim Makefile

    all:hello_world
    hello:hello_world.o
            $(CC) $(LDFLAGS) hello_world.o -o hello_world
    hello_world.o:hello_world.c
            $(CC) $(LDFLAGS) -c hello_world.c
    
    clean:
            rm *.o hello_world  
    ~                             
    

    返回hello_world目录下,编辑Makefile

    
    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))
    
    

    回到顶层目录

    make menuconfig
    并选择我们已经加进去的安装包。
    Utilities --->
    <M> hello_world.................... Hello world -prints a hello world message
    保存退出。
    make V=s
    等待编译完成后,我们就可以在以下路径找到生成的安装包
    “openwrt/ bin/ramips/packages/base/hello_world_1.0_ramips_24kec.ipk”

    安装此安装包后
    opkg install openwrt/ bin/ramips/packages/base/hello_world_1.0_ramips_24kec.ipk”
    直接在串口终端输入:
    hello_world

    相关文章

      网友评论

          本文标题:openwrt生成apk

          本文链接:https://www.haomeiwen.com/subject/tffrqqtx.html