Openwrtラーニングパス-(5-OpenwrtパッケージMakefile)



Openwrt Learning Path



3482555-4fcb6bd769f2e41b.jpgタイトル:無償

OpenwrtパッケージMakefile

'Openwrt main Makefile'セクションに、メインMakefileが渡されるということわざがあります。include package/Makefileパッケージの下のMakefileを呼び出すと、パッケージの下のMakefileが呼び出しを再度呼び出します。$(call subdir,package)トラバースパッケージサブディレクトリ内のMakefile。パッケージの下のMakefileはソースコードで提供されており、変更されませんが、packageサブディレクトリ内のMakefileは、私たちが頻繁に処理しなければならないものです。この章ではそれについて説明します。

パッケージの下のサブディレクトリを開くだけで、通常、いくつかのことがわかります。



  • Package / $(PKG_NAME)/ Makefile [必須]
  • パッケージ/ $(PKG_NAME)/ src / [オプション]
  • パッケージ/ $(PKG_NAME)/ patchs / [オプション]
  • パッケージ/ $(PKG_NAME)/ files / [オプション]

srcディレクトリ、patchesディレクトリ、filesディレクトリはすべてオプションです。 srcディレクトリには、汎用モジュールのソースコードが格納されています。 pactchesディレクトリには通常、バグ修正と実行可能ファイルサイズの最適化が含まれています。 filesディレクトリは通常、構成ファイルを含むスクリプトを実行します。待つ。 Makefileで指定されている限り、ディレクトリ名はオプションであるため、他のディレクトリも表示される場合があります。

Makefileは最も重要であり、一般に、パッケージをダウンロード、コンパイル、およびインストールするための手順を提供します。



パッケージサブディレクトリのMakefileを開くと、これがMakefileであることを認識するのは困難です。そのフォーマットは通常のMakefileとは異なり、その機能は通常のMakefileとは異なるため、作成するのに便利なテンプレートです。

ここでは、例としてpackage / bridge / Makefileを取り上げます。

include $(TOPDIR)/rules.mk PKG_NAME:=bridge PKG_VERSION:=1.0.6 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION) PKG_SOURCE:=bridge-utils-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:root@xxxxx/bridge PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd PKG_CAT:=zcat include $(INCLUDE_DIR)/package.mk define Package/bridge SECTION:=base CATEGORY:=Network DEFAULT:=y TITLE:=Ethernet bridging configuration utility DESCRIPTION:=Ethernet bridging configuration utility\ Manage ethernet bridging a way to connect networks together to\ form a larger network. URL:=http://bridge.sourceforge.net/ endef define Build/Configure $(call Build/Configure/Default,--with-linux-headers=$(LINUX_DIR)) endef define Package/bridge/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/brctl/brctl $(1)/usr/sbin/ endef $(eval $(call BuildPackage,bridge))

1.グローバル変数を含む


まず、Makefileの最初の行には、Makefileのいくつかのグローバル変数の定義である次のコマンドが含まれている必要があります。
$(TOPDIR)/rules.mkを含める



2.パッケージ変数


パッケージの構築には多くの作業は必要ありません。ほとんどの作業は他のメイクファイルに隠されており、オーサリング作業はいくつかの変数への割り当てに抽象化されています。

PKG_NAME : the name of the package, displayed in menuconfig and ipkg PKG_VERSION : The version of the package, the version of the trunk branch is exactly what we want to download. PKG_RELEASE : the erased version of this makefile PKG_BUILD_DIR : the directory where the package is compiled PKG_SOURCE : The name of the package to be downloaded, usually composed of PKG_NAME and PKG_VERSION PKG_SOURCE_URL : Download a link to this package PKG_MD5SUM : MD5 value of the package PKG_CAT: How to extract the package (zcat, bzcat, unzip) PKG_BUILD_DEPENDS : A pre-built package is required, but only when building this package, not when it is running. Its syntax is the same as DEPENDS below.

3.BuildPackage関連のマクロ定義


1.menuconfigとipkgでパッケージ情報を記述します。次の変数を定義できます。

define Package/ SECTION : Package Type CATEGORY : The location of the package in menuconfig, such as Network, Utilities SUBMENU : The secondary directory to which the package belongs in menuconfig, such as dial-in/up DEFAULT: default compilation mode, m=compile to module, y=compile to image, n or no compilation, [dependency The package is separated by a space. The front + plus is the default display. Lai package does not add + is not displayed by default. Select the dependent package to display] TITLE : Package title DESCRIPTION : Detailed description of the package, due to bugs, has now given up URL : The original location of the software, usually the home page of the software author MAINTAINER : (optional) package maintainer DEPENDS : (optional) dependencies, running other packages that the software depends on endif

2.構成手順

Define Build/Configure (optional) The ./configure is required in Automake, so this configuration method is mainly for software that needs to be configured. Package-designed, generally self-developed software packages can not be described here. endif

3.パッケージのインストール

define Package/install The installation method of the package, including a series of copies of the compiled file to the specified location. Bring one when calling The parameter is the image file system directory embedded in the system, so $(1) indicates the image of the embedded system. record. Generally, the following methods can be used: $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ endif

4.その他のBuildPackage関連のマクロ定義

上記の3つは、ブリッジモジュールで使用されるマクロ定義です。他にも多くの定義があります。また、それらを理解することができ、他の状況が使用される可能性があります。

1.コンパイルの準備

Define Build/Prepare (optional) Packages downloaded from the Internet do not need to be described, for non-online downloads or self-developed packages. The compilation preparation method must be explained as follows: mkdir -p $(PKG_BUILD_DIR) Create a build directory, which is $(TOPDIR)/build_dir/target-*/$(PKG_NAME)-%(PKG_VERSION) $(CP) ./src/* $(PKG_BUILD_DIR)/ Copy the source code of the package src to the build directory. endif

2.ソースコードをコンパイルします

Define Build/Compile (optional) The default is to compile the Makefile inside the source, if you want to pass some parameters such as the ring What is the environment variable, then you can define, compile methods, can not be defined without special instructions. if not The definition will use the default compilation method Build/Compile/Default Self-developed packages can consider the following definitions. $(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS) CFLAGS='$(TARGET_CFLAGS) -I$(LINUX_DIR)/include' endif

3.インストール前に実行されるスクリプト

Define Package/ $(PKG_NAME)/ preinst (optional) The script that was executed before the software installation, don't forget to add #!/bin/sh in the first sentence. If the script is finished, cancel the installation process and let it return false. #!/bin/sh ......... exit 0 endif

4.インストール後に実行されるスクリプト

Define Package/ $(PKG_NAME)/ postinst (optional) The script that was executed after the software was installed, don't forget to add #!/bin/sh in the first sentence. #!/bin/sh ......... exit 0 endif

5.以前に実行されたスクリプトを削除します

Define Package/ $(PKG_NAME)/ prerm (optional) The software removes the script that was executed before, and don't forget to add #!/bin/sh to the first sentence. If the script is finished executing to cancel the deletion process, just let it return false. #!/bin/sh ......... exit 0 endif

6.削除後に実行されたスクリプト

Define Package/ $(PKG_NAME)/ postrm (optional) The script that was executed after the software was deleted, don't forget to add #!/bin/sh to the first sentence. #!/bin/sh ......... exit 0 endif

一部の定義の「Package /」プレフィックスと他の定義が「Build」プレフィックスとして定義されているのはなぜですか?これは、Openwrtが単一のソースから複数のパッケージをビルドする機能をサポートしているためです。 OpenWrtは、Makefileがソースコードに対応していることを前提に機能しますが、コンパイルされたプログラムを任意の数のパッケージに分割できます。コンパイルは1回だけなので、グローバルな「ビルド」定義を使用するのが最も適切です。次に、多くの「パッケージ/」定義を追加し、各パッケージのインストール方法を指定できます。

5.ソフトウェアパッケージの実装


前の定義を完了した後、eval関数を使用してさまざまな定義を実装する必要があります。これは最も重要なBuildPackageマクロであり、$(INCLUDE_DIR)/package.mkファイルで定義されています。 BuildPackageマクロには、コンパイルするパッケージの名前(この場合は「bridge」)という1つのパラメーターのみが必要です。

一般パッケージの場合$(eval $(call Package,$(PKG_NAME)))

カーネルモジュールの場合$(eval $(call KernelPackage,$(PKG_NAME)))

パッケージに複数のプログラムがある場合、eval関数は複数のパッケージを処理するように設計することもできます。

Makefileを編集して指定したディレクトリに配置すると、次回この新しいパッケージが実行されます。make menuconfig表示されたら、このパッケージを選択して保存して終了し、コンパイルして、OpenWrtに正常に移植できます。具体的な例については、「Openwrtのパッケージへの汎用モジュールの追加」セクションで説明します。

OpenwrtパッケージのMakefileの分析はここにあり、感じたときに更新され続けます。

注:上記の内容は、学習過程で私が蓄積した経験の一部です。他の記事の知識があることは避けられません。侵害がある場合は、時間内に通知してください。コンテンツのソースを時間内に削除またはマークします。エラーがある場合は、指摘して話し合いを行ってください。この記事はガイドの役割にすぎません。詳細なデータ分析については、Openwrt関連のチュートリアルを確認してください。レビューありがとうございます。