-#############################################################
-#
-# second pass compiler build. Build the compiler targeting
-# the newly built shared uClibc library.
-#
-#############################################################
-#
-# Sigh... I had to rework things because using --with-gxx-include-dir
-# causes issues with include dir search order for g++. This seems to
-# have something to do with "path translations" and possibly doesn't
-# affect gcc-target. However, I haven't tested gcc-target yet so no
-# guarantees. mjn3
-
-GCC_BUILD_DIR2:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-final
-$(GCC_BUILD_DIR2)/.configured: $(GCC_DIR)/.patched $(STAGING_DIR)/lib/libc.a
- mkdir -p $(GCC_BUILD_DIR2)
+ifneq ($(CONFIG_TLS_SUPPORT),)
+ GCC_CONFIGURE_STAGE2+= \
+ --enable-tls
+else
+ GCC_CONFIGURE_STAGE2+= \
+ --disable-tls
+endif
+
+ifdef CONFIG_powerpc
+ TARGET_CFLAGS := $(patsubst -Os,-O2,$(TARGET_CFLAGS))
+endif
+
+GCC_MAKE:= \
+ export SHELL="$(BASH)"; \
+ $(MAKE) \
+ CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
+ CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
+
+define Host/SetToolchainInfo
+ $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
+ $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
+endef
+
+
+define Stage0/Configure
+ mkdir -p $(HOST_BUILD_DIR0)
+ (cd $(HOST_BUILD_DIR0); rm -f config.cache; \
+ $(GCC_CONFIGURE_STAGE0) \
+ );
+endef
+
+define Stage0/Compile
+ $(GCC_MAKE) -C $(HOST_BUILD_DIR0) all-gcc
+endef
+
+define Stage0/Install
+ $(GCC_MAKE) -C $(HOST_BUILD_DIR0) install-gcc
+endef
+
+
+define Stage1/Configure
+ mkdir -p $(HOST_BUILD_DIR1)
+ (cd $(HOST_BUILD_DIR1); rm -f config.cache; \
+ $(GCC_CONFIGURE_STAGE1) \
+ );
+endef
+
+define Stage1/Compile
+ $(CP) $(BUILD_DIR_TOOLCHAIN)/linux-dev/* $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/
+ $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
+ all-build-libiberty \
+ all-gcc \
+ $(if $(GCC_BUILD_TARGET_LIBGCC),all-target-libgcc)
+endef
+
+define Stage1/Install
+ $(GCC_MAKE) -C $(HOST_BUILD_DIR1) \
+ install-gcc \
+ $(if $(GCC_BUILD_TARGET_LIBGCC),install-target-libgcc)
+
+ # XXX: glibc insists on linking against libgcc_eh
+ ( cd $(TOOLCHAIN_DIR)/usr/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION) ; \
+ [ -e libgcc_eh.a ] || ln -sf libgcc.a libgcc_eh.a ; \
+ cp libgcc.a libgcc_initial.a; \
+ )
+endef
+
+
+define Stage2/Configure
+ mkdir -p $(HOST_BUILD_DIR2) $(TOOLCHAIN_DIR)/usr/$(REAL_GNU_TARGET_NAME)