以一个ser2net软件包为例解读openwrt19.07编译文件及luci编译步骤

以一个ser2net软件包为例解读openwrt19.07编译文件及luci编译步骤br/>1、包编译;
第一步拷贝ser2net-3.5.1.tar.gz文件到dl目录,
并在feeds/package/net/下建立ser2net目录,并建立Makefile文件;
//包头信息
PKG_NAME:=ser2net
PKG_VERSION:=3.5.1
PKG_RELEASE:=5
//包位置,会自解压到build_dir/target-mipsel_24kc_musl/ser2net-3.5.1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/ser2net
PKG_HASH:=02f5dd0abbef5a17b80836b0de1ef0588e257106fb5e269b86822bfd001dc862
//其他信息
PKG_LICENSE:=GPL-2.0-or-later
PKG_LICENSE_FILES:=COPYING
PKG_MAINTAINER:=Michael Heimpold <mhei@heimpold.de>

PKG_FIXUP:=autoreconf
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk
//定义包的Luci位置;
define Package/ser2net
  SECTION:=net
  CATEGORY:=Network
  TITLE:=Serial to Network Proxy
  URL:=https://sourceforge.net/projects/ser2net/
endef
//包描述
define Package/ser2net/description
  This project provides a proxy that allows telnet/tcp connections to be made to
  serial ports on a machine.
endef
//定义包的配置文件
define Package/ser2net/conffiles
/etc/config/ser2net
/etc/ser2net.conf
endef
//安装相关文件到相对应的位置;
define Package/ser2net/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ser2net $(1)/usr/sbin/

    $(INSTALL_DIR) $(1)/etc
    $(INSTALL_CONF) ./files/ser2net.conf $(1)/etc/

    $(INSTALL_DIR) $(1)/etc/config
    $(INSTALL_CONF) ./files/ser2net.config $(1)/etc/config/ser2net

    $(INSTALL_DIR) $(1)/etc/init.d
    $(INSTALL_BIN) ./files/ser2net.init $(1)/etc/init.d/ser2net
endef

$(eval $(call BuildPackage,ser2net))

并在该目录下建立配置文件files目录,建立三个配置文件
ser2net.conf ->运行参数配置文件
ser2net.config ->web配置文件参数
ser2net.init ->启动配置文件
2、luci相关内容编译;
(1)文件目录结构
htdocs -> luci-status->resources->view->ser2net->
leds.js //三个页面的js文件;
proxies.js
settings.js
po ->翻译文件信息;
root ->usr/share/luci-> menu.d ->luci.app-ser2net.json 文件,该文件确定的文件菜单位置,以及菜单页调用的view文件名;
{
"admin/services/ser2net": {
"title": "ser2net",
"action": {
"type": "firstchild"
},
"depends": {
"acl": [ "luci-app-ser2net" ],
"uci": { "ser2net": true }
}
},

            "admin/services/ser2net/settings": {
                "title": "Settings",
                "order": 1,
                "action": {
                    "type": "view",
                    "path": "ser2net/settings"
                }
            },

            "admin/services/ser2net/proxies": {
                "title": "Proxies",
                "order": 2,
                "action": {
                    "type": "view",
                    "path": "ser2net/proxies"
                }
            },

            "admin/services/ser2net/leds": {
                "title": "LEDs",
                "order": 3,
                "action": {
                    "type": "view",
                    "path": "ser2net/leds"
                }
            }
        }

    ->usr/share/rpcd/acl.d -> luci-app-ser2net.json
    {
        "luci-app-ser2net": {
            "description": "Grant access to LuCI app ser2net",
            "read": {
                "uci": [ "ser2net" ]
            },
            "write": {
                "uci": [ "ser2net" ]
            }
        }
    }

(1)编译Makefile 文件内容
include $(TOPDIR)/rules.mk

    LUCI_TITLE:=LuCI Support for ser2net
    LUCI_DEPENDS:=+ser2net

    PKG_LICENSE:=Apache-2.0

    include ../../luci.mk

相应内容在luci/luci.mk文件里
    拷贝以上htdocs,root,以及po文件内容到相应位置;  
    define Package/$(PKG_NAME)/install
        if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
          $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
          cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
          $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
          $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
          $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
        else true; fi
        if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
          $(INSTALL_DIR) $(1)$(HTDOCS); \
          cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
          $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true); \
          $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true); \
        else true; fi
        if [ -d $(PKG_BUILD_DIR)/root ]; then \
          $(INSTALL_DIR) $(1)/; \
          cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
        else true; fi
        if [ -d $(PKG_BUILD_DIR)/src ]; then \
          $(call Build/Install/Default) \
          $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
        else true; fi
    endef
上一篇:包Packages


下一篇:webpack入门指南-step02