Skip to main content
The following variables are defined by the OpenWrt build infrastructure (primarily rules.mk and include/package.mk) and are available in all package and target Makefiles.

Directory Variables

VariableDescriptionExample Value
TOPDIRAbsolute path to the OpenWrt source root/home/user/openwrt
BUILD_DIRBase directory for compiled package sources$(TOPDIR)/build_dir/target-mips_24kc_musl
BUILD_DIR_BASEParent of all build directories$(TOPDIR)/build_dir
BUILD_DIR_HOSTBuild directory for host tools$(TOPDIR)/build_dir/host
STAGING_DIRTarget sysroot staging directory$(TOPDIR)/staging_dir/target-mips_24kc_musl
STAGING_DIR_HOSTHost tools staging directory$(TOPDIR)/staging_dir/host
STAGING_DIR_HOSTPKGHost package staging directory$(TOPDIR)/staging_dir/hostpkg
TARGET_DIRStaged rootfs for image assembly$(BUILD_DIR)/root-ath79
INCLUDE_DIROpenWrt include directory$(TOPDIR)/include
SCRIPT_DIROpenWrt scripts directory$(TOPDIR)/scripts
TMP_DIRTemporary files directory$(TOPDIR)/tmp
BIN_DIROutput directory for images and packages$(TOPDIR)/bin/targets/ath79/generic
DL_DIRDownload cache for source archives$(TOPDIR)/dl
TOOLCHAIN_DIRCross-toolchain staging directory$(TOPDIR)/staging_dir/toolchain-mips_24kc_gcc-14.3.0_musl
VariableDescription
PKG_BUILD_DIRDirectory where package sources are extracted and compiled. Defaults to $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION).
PKG_INSTALL_DIRStaging install directory for make install output. Defaults to $(PKG_BUILD_DIR)/ipkg-install.
PACKAGE_DIRDirectory where built .ipk files are placed.

Target and Architecture Variables

VariableDescriptionExample
ARCHTarget CPU architecturemips, arm, aarch64, x86_64
ARCH_SUFFIXCPU type suffix (from CONFIG_CPU_TYPE)_24kc, _cortex-a9
BOARDTarget board identifierath79, x86, mediatek
SUBTARGETSubtarget namegeneric, nand, 64
CPU_TYPECPU subtype string24kc, cortex-a53
TARGET_SUFFIXTarget ABI suffixmusl, muslgnueabihf
GNU_TARGET_NAMEFull GNU target tripletmips-openwrt-linux-musl
OPTIMIZE_FOR_CPUAdjusted CPU string for -marchmips, i486
LIB_SUFFIXLibrary directory suffix64 (for 64-bit) or empty

Compiler and Linker Variables

VariableDescription
TARGET_CROSSCross-compiler prefix, e.g. mips-openwrt-linux-musl-
TARGET_CCC compiler: $(TARGET_CROSS)gcc
TARGET_CXXC++ compiler: $(TARGET_CROSS)g++
TARGET_ARArchiver: $(TARGET_CROSS)gcc-ar
TARGET_RANLIBRanlib: $(TARGET_CROSS)gcc-ranlib
TARGET_NMSymbol lister: $(TARGET_CROSS)gcc-nm
TARGET_LDLinker: $(TARGET_CROSS)ld.$(TARGET_LINKER)
TARGET_LINKERLinker backend (bfd or mold)
HOSTCCHost C compiler (for build-time tools)
HOSTCXXHost C++ compiler
VariableDescription
TARGET_CFLAGSC compiler flags for the target. Includes optimization, arch, and hardening flags.
TARGET_CXXFLAGSC++ compiler flags. Initially equal to TARGET_CFLAGS.
TARGET_ASFLAGSAssembler flags.
TARGET_LDFLAGSLinker flags. Includes toolchain library paths.
TARGET_CPPFLAGSC preprocessor flags. Includes toolchain include paths.
TARGET_OPTIMIZATIONCore optimization flags from the target config (e.g., -Os -pipe).
FPICPosition-independent code flag (-fPIC or -fpic depending on arch).
SOFT_FLOAT_CONFIG_OPTION--with-float=soft if soft float is enabled, else empty.

Build System Utilities

VariableDescription
PKG_CONFIGPath to pkg-config configured for the target sysroot
FAKEROOTPath to fakeroot binary
SEDsed -i -e using the host sed
ESEDsed -E -i -e (extended regex)
MKHASHOpenWrt hash utility
CPcp -fpR
LNln -sf
INSTALL_BINinstall -m0755 — install an executable
INSTALL_SUIDinstall -m4755 — install a setuid executable
INSTALL_DATAinstall -m0644 — install a data file
INSTALL_CONFinstall -m0600 — install a config file (owner-read-only)
INSTALL_DIRinstall -d -m0755 — create a directory
PYTHONpython3

Config Variables

All .config settings are available as CONFIG_* variables. Common ones used in package Makefiles:
VariableDescription
CONFIG_ARCHTarget architecture string
CONFIG_TARGET_BOARDTarget board name
CONFIG_TARGET_SUBTARGETSubtarget name
CONFIG_TARGET_ARCH_PACKAGESArchitecture string for package feeds
CONFIG_USE_MUSLSet to y if musl is the C library
CONFIG_USE_LTOSet to y if LTO is globally enabled
CONFIG_USE_GC_SECTIONSSet to y if gc-sections is globally enabled
CONFIG_USE_MIPS16Set to y if MIPS16 mode is enabled
CONFIG_USE_MOLDSet to y if the mold linker is enabled
CONFIG_GCC_VERSIONActive GCC version string (e.g., 14.3.0)
CONFIG_LIBCActive C library name (musl or glibc)

Build docs developers (and LLMs) love