首页 > 其他分享 >openWRT构建helloworld示例

openWRT构建helloworld示例

时间:2023-11-12 22:25:23浏览次数:43  
标签:示例 Makefile helloworld program PKG DIR directory openWRT

概述

版本号:OpenWrt 18.06.2, r7676-cddd7b4c77

helloworld示例

参考:OpenWrt:构建helloworld应用

1. 在package目录下新建helloworld文件夹,存放helloworld应用程序。

$ tree helloworld/
helloworld/
├── Makefile    # openwrt规则Makefile
└── src
    ├── helloworld.c
    └── Makefile   # 普通Makefile

helloworld/src目录下存放helloworld例程和编译Makefile:

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world\n");

    return 0;
}
# build helloworld executable when user executes "make"

helloworld: helloworld.o
	$(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o: helloworld.c
	$(CC) $(CFLAGS) -c helloworld.c

# remove object files and executable when user executes "make clean"
clean:
	rm *.o helloworld

helloworld/Makefile为符合openWrt规则的Makefile,完成包编译安装等。

Makefile语法官网

##############################################
# OpenWrt Makefile for helloworld program
#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.
#
##############################################

include $(TOPDIR)/rules.mk

# Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1


# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)


include $(INCLUDE_DIR)/package.mk

 

# Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/helloworld
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=Helloworld -- prints a snarky message
endef


# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/helloworld/description
    If you can't figure out what this program does, you're probably
    brain-dead and need immediate medical attention.
endef

 

# Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default.  The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef


# We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one


# Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist.  Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
    $(INSTALL_DIR) $(1)/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef


# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))

2. 添加软件helloworld到openwrt中。

在openwrt/目录下执行make menuconfig,Utilities->helloworld选配为M。

3. 编译

~/openwrt$ make package/helloworld/compile V=s
~/openwrt$ ls bin/packages/arm_cortex-a9_neon-vfpv3/base/helloworld_1_arm_cortex-a9_neon-vfpv3.ipk
bin/packages/arm_cortex-a9_neon-vfpv3/base/helloworld_1_arm_cortex-a9_neon-vfpv3.ipk

4. 安装运行

openwrt板卡上运行opkg安装helloworld ipk程序。

root@Bonanza:~# opkg install helloworld_1_arm_cortex-a9_neon-vfpv3.ipk
Installing helloworld (1) to root...
Configuring helloworld.
root@Bonanza:~# helloworld
hello world

参考

  1. OpenWrt 编译步骤与命令详解

标签:示例,Makefile,helloworld,program,PKG,DIR,directory,openWRT
From: https://www.cnblogs.com/embedded-linux/p/17827992.html

相关文章

  • java helloworld
    test.javapcakagemyclass//这个地方打包,表示类test是归属于myclass包的,而test.java文件是放在myclass文件夹中的,文件夹的名称与包名是对应的publicclasstest{//anapplicationpublicstaticvoidmain(String[]args){System.out.println("HelloWorld!");}}......
  • C#断点续传的实现示例
    断点续传是一种可以在文件传输过程中出现断电、网络故障等情况时,能够保证传输内容不会全部丢失,而是可以从已传输的位置继续传输的机制。在文件传输较大、较复杂的情况下,使用断点续传可以提高传输质量、稳定性和效率。在C#中,可以使用HTTP协议的Range头部域来实现断点续传。使用HTT......
  • 如何使用 RestTemplate 进行 Spring Boot 微服务通信示例
    概述下面我们将学习如何创建多个Springboot微服务以及如何使用RestTemplate类在多个微服务之间进行同步通信。微服务通信有两种风格:同步通讯异步通信同步通讯在同步通信的情况下,客户端发送请求并等待服务的响应。这里重要的一点是协议(HTTP/HTTPS)是同步的,客户端代码只......
  • Spring 6.0官方文档示例(24): replace-method的用法
    一、原始bean定义packagecn.edu.tju.study.service.anno.domain;publicclassMyValueCalculator{publicStringcomputeValue(Stringinput){return"youinputted:"+input;}//someothermethods...}二、replacebean定义packagecn.edu.......
  • Spring6.0官方文档示例:(25)@RequestScope注解
    packagecn.edu.tju.controller.listener;importorg.springframework.stereotype.Component;importorg.springframework.web.context.annotation.RequestScope;importjava.util.Date;@Component@RequestScope//@Scope(value="request",proxyMode=Sco......
  • Spring6.0官方文档示例:(28)多种方式添加BeanPostProcessor
    一、定义三个BeanPostProcessorpackagecn.edu.pku;importorg.springframework.beans.BeansException;importorg.springframework.beans.factory.config.BeanPostProcessor;importorg.springframework.stereotype.Component;@ComponentpublicclassMyScannedBeanPostPr......
  • 16、Flink 的table api与sql之连接外部系统: 读写外部系统的连接器和格式以及FileSyst
    文章目录Flink系列文章一、Table&SQLConnectors1、概述2、支持的外部连接3、使用示例:kafka4、Transformtableconnector/formatresources5、SchemaMapping6、Metadata7、PrimaryKey8、TimeAttributes9、ProctimeAttributes10、RowtimeAttributes11、完整示例1)、建表2)、......
  • R语言和jsonlite库编写代码示例
    R语言和jsonlite库来下载的程序。#导入jsonlite库library(jsonlite)#设置代理主机和端口proxy_host<-""proxy_port<-#使用httr库创建一个对象proxy<-create_proxy(proxy_host,proxy_port)#使用httr库的GET方法下载网页内容url<-""response<-GET(url,pro......
  • Ruby语言和VCR库编写代码示例
    Ruby语言和VCR库编写一个下载程序来完成任务。以下是代码的详细解释:require'vcr'require'open-uri'#设置VCR的配置VCR.configuredo|config|config.cassette_library_dir='vcr_cassettes'config.hook_into:webmockconfig.default_cassette_options={:rec......
  • Rust和isahc库编写代码示例
    Rust和isahc库编写的图像爬虫程序的代码:useisahc::{Client,Response};fnmain(){letclient=Client::new().with_proxy("").finish();leturl="";letresponse=client.get(url).send().await......