rules.mk and include/package.mk) and are available in all package and target Makefiles.
Directory Variables
Source and Build Directories
Source and Build Directories
| Variable | Description | Example Value |
|---|---|---|
TOPDIR | Absolute path to the OpenWrt source root | /home/user/openwrt |
BUILD_DIR | Base directory for compiled package sources | $(TOPDIR)/build_dir/target-mips_24kc_musl |
BUILD_DIR_BASE | Parent of all build directories | $(TOPDIR)/build_dir |
BUILD_DIR_HOST | Build directory for host tools | $(TOPDIR)/build_dir/host |
STAGING_DIR | Target sysroot staging directory | $(TOPDIR)/staging_dir/target-mips_24kc_musl |
STAGING_DIR_HOST | Host tools staging directory | $(TOPDIR)/staging_dir/host |
STAGING_DIR_HOSTPKG | Host package staging directory | $(TOPDIR)/staging_dir/hostpkg |
TARGET_DIR | Staged rootfs for image assembly | $(BUILD_DIR)/root-ath79 |
INCLUDE_DIR | OpenWrt include directory | $(TOPDIR)/include |
SCRIPT_DIR | OpenWrt scripts directory | $(TOPDIR)/scripts |
TMP_DIR | Temporary files directory | $(TOPDIR)/tmp |
BIN_DIR | Output directory for images and packages | $(TOPDIR)/bin/targets/ath79/generic |
DL_DIR | Download cache for source archives | $(TOPDIR)/dl |
TOOLCHAIN_DIR | Cross-toolchain staging directory | $(TOPDIR)/staging_dir/toolchain-mips_24kc_gcc-14.3.0_musl |
Package Build Directories
Package Build Directories
| Variable | Description |
|---|---|
PKG_BUILD_DIR | Directory where package sources are extracted and compiled. Defaults to $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION). |
PKG_INSTALL_DIR | Staging install directory for make install output. Defaults to $(PKG_BUILD_DIR)/ipkg-install. |
PACKAGE_DIR | Directory where built .ipk files are placed. |
Target and Architecture Variables
Architecture and Board
Architecture and Board
| Variable | Description | Example |
|---|---|---|
ARCH | Target CPU architecture | mips, arm, aarch64, x86_64 |
ARCH_SUFFIX | CPU type suffix (from CONFIG_CPU_TYPE) | _24kc, _cortex-a9 |
BOARD | Target board identifier | ath79, x86, mediatek |
SUBTARGET | Subtarget name | generic, nand, 64 |
CPU_TYPE | CPU subtype string | 24kc, cortex-a53 |
TARGET_SUFFIX | Target ABI suffix | musl, muslgnueabihf |
GNU_TARGET_NAME | Full GNU target triplet | mips-openwrt-linux-musl |
OPTIMIZE_FOR_CPU | Adjusted CPU string for -march | mips, i486 |
LIB_SUFFIX | Library directory suffix | 64 (for 64-bit) or empty |
Compiler and Linker Variables
Cross-Compiler Binaries
Cross-Compiler Binaries
| Variable | Description |
|---|---|
TARGET_CROSS | Cross-compiler prefix, e.g. mips-openwrt-linux-musl- |
TARGET_CC | C compiler: $(TARGET_CROSS)gcc |
TARGET_CXX | C++ compiler: $(TARGET_CROSS)g++ |
TARGET_AR | Archiver: $(TARGET_CROSS)gcc-ar |
TARGET_RANLIB | Ranlib: $(TARGET_CROSS)gcc-ranlib |
TARGET_NM | Symbol lister: $(TARGET_CROSS)gcc-nm |
TARGET_LD | Linker: $(TARGET_CROSS)ld.$(TARGET_LINKER) |
TARGET_LINKER | Linker backend (bfd or mold) |
HOSTCC | Host C compiler (for build-time tools) |
HOSTCXX | Host C++ compiler |
Compiler and Linker Flags
Compiler and Linker Flags
| Variable | Description |
|---|---|
TARGET_CFLAGS | C compiler flags for the target. Includes optimization, arch, and hardening flags. |
TARGET_CXXFLAGS | C++ compiler flags. Initially equal to TARGET_CFLAGS. |
TARGET_ASFLAGS | Assembler flags. |
TARGET_LDFLAGS | Linker flags. Includes toolchain library paths. |
TARGET_CPPFLAGS | C preprocessor flags. Includes toolchain include paths. |
TARGET_OPTIMIZATION | Core optimization flags from the target config (e.g., -Os -pipe). |
FPIC | Position-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
Utility Variables
Utility Variables
| Variable | Description |
|---|---|
PKG_CONFIG | Path to pkg-config configured for the target sysroot |
FAKEROOT | Path to fakeroot binary |
SED | sed -i -e using the host sed |
ESED | sed -E -i -e (extended regex) |
MKHASH | OpenWrt hash utility |
CP | cp -fpR |
LN | ln -sf |
INSTALL_BIN | install -m0755 — install an executable |
INSTALL_SUID | install -m4755 — install a setuid executable |
INSTALL_DATA | install -m0644 — install a data file |
INSTALL_CONF | install -m0600 — install a config file (owner-read-only) |
INSTALL_DIR | install -d -m0755 — create a directory |
PYTHON | python3 |
Config Variables
All.config settings are available as CONFIG_* variables. Common ones used in package Makefiles:
| Variable | Description |
|---|---|
CONFIG_ARCH | Target architecture string |
CONFIG_TARGET_BOARD | Target board name |
CONFIG_TARGET_SUBTARGET | Subtarget name |
CONFIG_TARGET_ARCH_PACKAGES | Architecture string for package feeds |
CONFIG_USE_MUSL | Set to y if musl is the C library |
CONFIG_USE_LTO | Set to y if LTO is globally enabled |
CONFIG_USE_GC_SECTIONS | Set to y if gc-sections is globally enabled |
CONFIG_USE_MIPS16 | Set to y if MIPS16 mode is enabled |
CONFIG_USE_MOLD | Set to y if the mold linker is enabled |
CONFIG_GCC_VERSION | Active GCC version string (e.g., 14.3.0) |
CONFIG_LIBC | Active C library name (musl or glibc) |