默認編譯 openwrt 時會先編譯一套 toolchain. 這個步驟耗時較長. 使用外部 toolchain 能夠多個 project 共用一套 toolchain , 並且也不重再編譯它了. 省時省力.linux
make menuconfig
git
[*] Advanced configuration options (for developers) ---> [*] Use external toolchain ---> │ │ --- Use external toolchain │ │ │ │ [ ] Use host's toolchain │ │ │ │ (mipsel-openwrt-linux-uclibc) Target name │ │ │ │ (mipsel-openwrt-linux-uclibc-) Toolchain prefix │ │ │ │ (/opt/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2) Toolchain root │ │ │ │ (uclibc) Toolchain libc │ │ │ │ (./usr/bin ./bin) Toolchain program path │ │ │ │ (./usr/include ./include) Toolchain include path │ │ │ │ (./usr/lib ./lib) Toolchain library path
編譯完在 .config 下能夠見到如下變量的定義:code
CONFIG_EXTERNAL_TOOLCHAIN=y # CONFIG_NATIVE_TOOLCHAIN is not set CONFIG_TARGET_NAME="mipsel-openwrt-linux-uclibc" CONFIG_TOOLCHAIN_PREFIX="mipsel-openwrt-linux-uclibc-" CONFIG_TOOLCHAIN_ROOT="/opt/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2" CONFIG_TOOLCHAIN_LIBC="uclibc" CONFIG_TOOLCHAIN_BIN_PATH="./usr/bin ./bin" CONFIG_TOOLCHAIN_INC_PATH="./usr/include ./include" CONFIG_TOOLCHAIN_LIB_PATH="./usr/lib ./lib"
這些變量在 rules.mk 裏起做用.ip
我使用主 trunk 的 openwrt, 編譯 kenrel 時碰到了問題. 在 kernel 的 Makefile 裏設置 KBUILD_VERBOSE = 1
看到是交叉編譯器沒有指定路徑. 跟蹤到是 rules.mk 裏 TARGET_CROSS 只保留了交叉編譯器前綴, 沒加路徑. 改了一下就能夠徹底編譯過了.get
diff --git a/rules.mk b/rules.mk index 0822979..70f3afc 100644 --- a/rules.mk +++ b/rules.mk @@ -144,9 +144,9 @@ ifndef DUMP TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH) else ifeq ($(CONFIG_NATIVE_TOOLCHAIN),) - TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX)) TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT)) TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH))) + TARGET_CROSS:=$(call qstrip,$(TOOLCHAIN_ROOT_DIR)/bin/$(CONFIG_TOOLCHAIN_PREFIX)) TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH))) TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH))) ifneq ($(TOOLCHAIN_BIN_DIRS),)