-$(curdir)/uClibc/prepare:=$(curdir)/kernel-headers/prepare
-ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
- $(curdir)/binutils/prepare:=$(curdir)/uClibc/prepare
- $(curdir)/gcc/prepare:=$(curdir)/binutils/install
- $(curdir)/uClibc/compile:=$(curdir)/gcc/compile
+ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
+ ifdef CONFIG_USE_MUSL
+ $(curdir)/kernel-headers/compile:=$(curdir)/gcc/initial/compile
+ $(curdir)/$(LIBC)/compile:=$(curdir)/kernel-headers/compile
+ else
+ $(curdir)/builddirs += $(LIBC)/headers gcc/minimal
+ $(curdir)/gcc/minimal/compile:=$(curdir)/binutils/compile
+ $(curdir)/kernel-headers/compile:=$(curdir)/gcc/minimal/compile
+ $(curdir)/$(LIBC)/headers/compile:=$(curdir)/kernel-headers/compile
+ $(curdir)/gcc/initial/compile:=$(curdir)/$(LIBC)/headers/compile
+ endif
+
+ $(curdir)/gcc/initial/compile+=$(curdir)/binutils/compile
+ $(curdir)/$(LIBC)/compile:=$(curdir)/gcc/initial/compile
+ $(curdir)/gcc/final/compile:=$(curdir)/$(LIBC)/compile
+ $(curdir)/$(LIBC)/utils/compile:=$(curdir)/gcc/final/compile
+endif
+
+ifndef DUMP_TARGET_DB
+ifneq ($(ARCH),)
+ $(TOOLCHAIN_DIR)/info.mk: .config
+ @for dir in $(TOOLCHAIN_DIR); do ( \
+ $(if $(QUIET),,set -x;) \
+ mkdir -p "$$dir"; \
+ cd "$$dir"; \
+ ln -nsf lib lib64; \
+ ln -nsf lib lib32; \
+ mkdir -p stamp lib usr/include usr/lib ; \
+ ); done
+ @grep GCC_VERSION $@ >/dev/null 2>&1 || $(INSTALL_DATA) $(TOPDIR)/toolchain/info.mk $@
+ @touch $@
+endif
+endif
+
+ifdef CONFIG_BUILDBOT
+ $(TOOLCHAIN_DIR)/stamp/.ver_check: $(TMP_DIR)/.build
+ cd "$(TOPDIR)"; git log --format=%h -1 toolchain > $(TMP_DIR)/.ver_check
+ cmp -s $(TMP_DIR)/.ver_check $@ || { \
+ rm -rf $(BUILD_DIR) $(STAGING_DIR) $(TOOLCHAIN_DIR) $(BUILD_DIR_TOOLCHAIN); \
+ mkdir -p $(TOOLCHAIN_DIR)/stamp; \
+ mv $(TMP_DIR)/.ver_check $@; \
+ }
+
+$(TOOLCHAIN_DIR)/info.mk $(STAGING_DIR)/.prepared: $(TOOLCHAIN_DIR)/stamp/.ver_check