openwrt 添加 应用(luci-application)

本文详细介绍在OpenWRT系统中添加自定义应用的具体步骤,包括创建应用目录结构、配置Makefile及IPKG包控制文件等内容,并解释了如何使新增应用在编译菜单中可见。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

openwrt 添加应用的几个步骤如下:

(1)在目录 ./feeds/luci/applications 下添加要增加的应用,譬如 "luci-test"

(2)里面应该包含以下几个目录

hbg@root:~/trunk/feeds/luci/applications/luci-test$ tree
.
├── ipkg                      //  1、包相关
│   ├── conffiles
│   ├── postinst
│   └── postrm
├── luasrc                  //   2、web界面相关
│   ├── controller
│   │   └── test.lua
│   ├── model
│   └── view
├── Makefile              //  3、编译相关
├── po
│   ├── en
│   │   └── test.po
│   └── zh_CN
│       └── test.po
├── root                   //  4、/etc/目录下相关文件
│   ├── config
│   │   └── test               
│   ├── init.d
│   │   └── test
│   └── uci-defaults
│       └── luci-dtest
└── src                    //  5、实现功能的主程序
    ├── test.c
    └── test.h

 

(3)除此之外,还需要修改  ./feeds/luci/contrib/package/luci 目录下的makefile,使其能够在 make menuconfig  中显示。

$(eval $(call application,dtest, test 1.0,\
       +PACKAGE_luci-app-test:libuci +libpthread +libubox +librt)) 

 

然后就可以在 make menuconfig中查找到test的选项了。

注意: 在执行命令"make menuconfig"之前,需要先清空 /tmp目录。

 

 

 

 

补充知识:

Categories(luci目录)

The LuCI modules are divided into several category directories, namely:

  • applications (Single applications or plugins for other modules or applications, 应用)
  • i18n (Translation files, 翻译文件)
  • libs (Independent libraries, 独立的库)
  • modules (Collections of applications, 应用集合)
  • themes (Frontend themes, 前端主题)

Each module goes into a subdirectory of any of this category-directories.

Module directory

The contents of a module directory are as follows:

Makefile

This is the module's makefile. If the module just contains Lua source code or resources then the following Makefile should suffice.

如果module中只有 lua 代码文件和资源文件,那么Makefile包含如下内容足以:

include ../../build/config.mk

include ../../build/module.mk

 

If you have C(++) code in your module your Makefile should at least contain the following things.

如果module中包含了 C 或 C++ 代码文件,则需要包含如下内容:

include ../../build/config.mk

include ../../build/gccconfig.mk

include ../../build/module.mk

 

compile:

    # Commands to compile and link your C-code

    # and to install them under the dist/ hierarchy

 

clean: luaclean

    # Commands to clean your compiled objects

src

The src directory is reserved for C source code.

src 目录用来保存 C源码。

luasrc

luasrc contains all Lua source code files. These will automatically be stripped or compiled depending on the Make target and are installed in the LuCI installation directory.

Luasrc 目录用来保存所有的 lua 源代码。 

lua

lua is equivalent to luasrc but containing Lua files will be installed in the Lua document root.

htdocs

All files under htdocs will be copied to the document root of the target webserver.

htdocs 目录将被拷贝到目标webserver下的文档根目录。

root

All directories and files under root will be copied to the installation target as they are.

拷贝到设备的根目录下。

dist

dist is reserved for the builder to create a working installation tree that will represent the file system on the target machine. DO NOT put any files there as they will get deleted.

 

ipkg

ipkg contains IPKG package control files, like preinst, posinst, prerm, postrm. conffiles. See IPKG documentation for details.

 

转载于:https://www.cnblogs.com/rohens-hbg/p/5704474.html

### OpenWRT LuCI 开发教程 #### 创建一个新的 LuCI 应用程序 为了创建新的 LuCI 应用程序,在 `luci-app-myapplication` 目录下添加 `Makefile` 文件,该文件定义了应用程序的基本配置: ```makefile include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Support for Test LUCI_DEPENDS:=+libjson-script +uhttpd-mod-lua include ../../luci.mk ``` 此段代码设置了应用程序的标题以及依赖项,并调用了构建包命令[^1]。 #### 定义软件包编译目录 对于任何 LuCI 或者其他类型的 OpenWRT 软件包来说,`PKG_BUILD_DIR` 变量指定了软件包的实际编译路径。默认情况下,它位于 `$BUILD_DIR/$PKG_NAME-$PKG_VERSION` 中,除非另有指定[^2]。 #### 控制器脚本编写 控制器负责处理来自 Web 浏览器的请求并返回适当的数据给视图层。下面是一个简单的例子来展示如何设置一个新入口点: ```lua module("luci.controller.LuoYeLuCI", package.seeall) function index() entry({"admin", "network", "LuoYeconfig"}, cbi("LuoYeCBI"), _("LuoYeTest"), 100) end ``` 这段 Lua 代码注册了一个名为 LuoYeconfig 的网络配置选项到管理面板下的 Network 类别里[^3]。 #### 理解 Luci MVC 架构 Luci 使用经典的 Model-View-Controller (MVC) 设计模式实现了良好的可扩展性和灵活性。这使得开发者能够轻松地定制 HTML 页面并与 Shell 脚本交互。公共组件存放在 `/luci/controller/` 下;而特定于用户的部分则保存在其各自的子文件夹内,例如管理员专用的功能会存储在 `/luci/controller/admin/` 中[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值