Every OpenWrt package is a directory containing aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/openwrt/openwrt/llms.txt
Use this file to discover all available pages before exploring further.
Makefile that describes how to download, build, and install the software. The build system reads this Makefile and handles cross-compilation, dependency resolution, and .ipk package generation automatically.
Package directory structure
Packages live underpackage/<category>/<name>/ in the OpenWrt source tree, or in a feed repository. The typical layout is:
Makefile— the only required file. Defines source location, build instructions, and installed files.files/— static files that are copied into the package duringPackage/<name>/install. Useful for UCI defaults, init scripts, and default configs.patches/— quilt-managed patches applied to the upstream source after unpacking. Patches are applied in filename order.
Creating a minimal package
The following walkthrough creates a simple package for a hypothetical C program calledhello.
Create the package directory
Create a directory under the appropriate category. Use
utils for general utilities:Write the Makefile
Create The last line,
package/utils/hello/Makefile with the following content:$(eval $(call BuildPackage,hello)), registers the package with the build system. Every package Makefile must end with one or more of these calls.Understand the key variables
| Variable | Purpose |
|---|---|
PKG_NAME | Package name, also used as the build directory name |
PKG_VERSION | Upstream version string |
PKG_RELEASE | OpenWrt packaging revision (increment when the Makefile changes without a version bump) |
PKG_SOURCE | Tarball filename to download |
PKG_SOURCE_URL | URL(s) to download the tarball from (space-separated, tried in order) |
PKG_HASH | SHA-256 hash of the downloaded source tarball |
PKG_LICENSE | SPDX license identifier |
PKG_LICENSE_FILES | Path(s) to license file(s) inside the source tree |
Define the package metadata
The
define Package/<name> block sets the metadata visible in make menuconfig:SECTION— opkg section (e.g.,base,libs,utils,net).CATEGORY— top-levelmenuconfigcategory (e.g.,Base system,Utilities,Network).TITLE— short one-line description shown in menuconfig.DEPENDS— space-separated list of package dependencies. Prefix with+for runtime deps and@for config symbol conditions.
Define the install step
The Common install helpers:
Package/<name>/install block is called when assembling the .ipk. The argument $(1) is the staging directory that maps to the root filesystem:| Macro | Usage |
|---|---|
$(INSTALL_DIR) | Create a directory (with parents) |
$(INSTALL_BIN) | Install an executable file (mode 0755) |
$(INSTALL_DATA) | Install a data file (mode 0644) |
$(INSTALL_CONF) | Install a config file (mode 0600) |
$(CP) | Copy files or directories recursively |
Add config files (optional)
Static files in the The path
files/ directory are available during the install step. A common pattern for init scripts:./files/ is relative to the package Makefile directory.Using a git source instead of a tarball
For packages that track a git repository, replace the tarball variables with:PKG_SOURCE_VERSION is set, PKG_VERSION is derived automatically from PKG_SOURCE_DATE and an abbreviated commit hash.
Always set
PKG_MIRROR_HASH for git sources. This is the SHA-256 of the generated .tar.zst archive, not the git commit. Generate it by running the download step once: make package/mypackage/download V=s and then hashing the file in dl/.Adding patches
Patches are stored inpatches/ and managed with quilt. They are applied automatically during the prepare step.
010-description.patch).
Build system helpers
For packages that use autoconf or CMake, include the appropriate helper instead of writing manualBuild/Configure and Build/Compile blocks:
- Autotools
- CMake