OpenWrt package - BuildPackage

I. Introduction

        The knowledge involved in this article comes from the OpenWrt Wiki official website. OpenWrt's software compilation template system makes it very simple to port software to OpenWrt. If we are in a typical package directory, we can find three things: package/Makefile, package/patches, and package/files.

package/patches: The directory is not required, generally for bug fixes and reducing the size of the target file.

package/Makefile: is required and provides the actual steps required to download and compile the package.

package/files: files needed by package (not .c and .h files).

Examples are as follows:

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:=@SF/bridge
PKG_HASH:=9b7dc52656f5cbec846a7ba3299f73bd

include $(INCLUDE_DIR)/package.mk

define Package/bridge
  SECTION:=base
  CATEGORY:=Network
  TITLE:=Ethernet bridging configuration utility
  #DESCRIPTION:=This variable is obsolete. use the Package/name/description define instead!
  URL:=http://bridge.sourceforge.net/
endef

define Package/bridge/description
  Ethernet bridging configuration utility Manage ethernet bridging; a way to connect networks together to form a larger network.
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))

2. BuildPackage variable

1. PKG_NAME

        The name of the package. Avoid using underscores in package names, as this can lead to hard-to-find errors and cause compilation to fail.

2. PKG_VERSION

        The version number of the package we want to download.

3. PKG_RELEASE

        The version of the package's Makefile.

4. PKG_BUILD_DIR

        The path to compile the package.

5. PKG_SOURCE

        The file name of the original source, usually a tarball package.

6. PKG_SOURCE_URL

        Where to download the source files.

7. PKG_HASH

        The checksum of the download source is used to verify whether the package is official.

8. PKG_CAT

        The way to decompress the source (zcat, bzcat, unzip).

9. PKG_BUILD_DEPENDS

        A package needs to be built before this package. If you need to ensure that the package has access to another package when it is built, use this option and specify the directory name (such as openssl) instead of the binary package (libopenssl) . This build variable only establishes build-time dependencies. Use DEPENDS to establish runtime dependencies.

10. PKG_CONFIG_DEPENDS

        Specifies which configuration options affect the build configuration and should trigger a rerun of Build/Configure

3. BuildPackage macro

1. Package/

SECTION: The type of software package, currently not in use.

CATEGORY: Which menu appears in menuconfig.

TITLE: A short description of the package.

DESCRIPTION: (Deprecated) Detailed description of the package.

URL: Link to download the original package.

MAINTAINER: The maintainer of the package.

DEPENDS: Optional, which software packages must be compiled and installed before compiling this package.

EXTRA_DEPENDS: Optional, runtime dependencies, not built, only added to the CONTROL file.

2. Package/conffiles

        List of configuration files installed by this package, one file per line. File list sections should not be indented: there are no leading tabs or spaces in the section.

3. Package/description

        Description of the package.

4. Build/Prepare

        A set of commands for unpacking or patching sources, you can safely leave this undefined.

5. Build/Configure

        If the source does not use configuration or has a normal configuration script, it can be left undefined. Otherwise you can put the configure command here or use $(call Build/Configure/Default).

6. Build/Compile

       How to compile source code, in most cases it should be set to undefined.

7. Build/Install

        How to install compiled source code.

8. Build/InstallDev

        Targets files that are required to compile the package (static libraries, header files), but are not useful on the target device.

9. Build/Clean

        For things that need to be removed during the cleaning process.

10. Package/install

        A set of commands for copying files into the ipkg directory represented by $(1). As source code, you can use the relative path that will be installed from the unpacked and compiled source code, or $(PKG_INSTALL_DIR), which is where the files from Build/Install in the steps above end.

        The reason some definitions are prefixed with "Package/" and others are just "Build" is that multiple packages can be built from a single source. OpenWrt works assuming one source per package Makefile, but you can split that source into as many packages as you want . Since you only need to compile the source code once, there is a global set of "Build" definitions, but you can add any number of "Package/" definitions by adding additional calls to BuildPackage - see the dropbear package example.

4. Summary

        This article summarizes the variables and macros of OpenWrt BuildPackage and their detailed usage.

Guess you like

Origin blog.csdn.net/to_be_better_wen/article/details/132518667