Index: Makefile
===================================================================
--- Makefile	(revision df56f5c5794ef0f96486018092af3433f68006da)
+++ Makefile	(revision 2431f30122eccfaa411fde382b9414078c527ff4)
@@ -100,4 +100,5 @@
 distclean: clean
 	rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc release/HelenOS-*
+	cd ./uspace/app/binutils/; ./distclean.sh
 
 clean:
Index: uspace/app/binutils/Makefile
===================================================================
--- uspace/app/binutils/Makefile	(revision df56f5c5794ef0f96486018092af3433f68006da)
+++ uspace/app/binutils/Makefile	(revision 2431f30122eccfaa411fde382b9414078c527ff4)
@@ -46,5 +46,5 @@
 # because targets derived from it will be referenced from
 # other than the current directory.
-USPACE_PREFIX = $(subst $(space),\ ,$(PWD))/../..
+USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
 
 # Ensure static configuration of Makefile.common.
@@ -70,5 +70,6 @@
 
 # Patch $PATH to intercept toolchain calls.
-PATH := $(PWD):$(PATH)
+PATH := $(shell pwd):$(PATH)
+export PATH
 
 # Shell script for false toolchain generation.
@@ -89,28 +90,38 @@
 # Map the HelenOS target to binutils target.
 ifeq ($(PLATFORM),amd64)
-TARGET=amd64-linux-gnu
-else ($(PLATFORM),arm32)
-TARGET=arm-linux-gnu
-else ($(PLATFORM),ia32)
-TARGET=i686-pc-linux-gnu
-else ($(PLATFORM),ia64)
-TARGET=ia64-pc-linux-gnu
-else ($(PLATFORM),mips32)
-TARGET=mipsel-linux-gnu
-else ($(PLATFORM),mips32eb)
-TARGET=mips-linux-gnu
-else ($(PLATFORM),mips64)
-TARGET=mips64el-linux-gnu
-else ($(PLATFORM),ppc32)
-TARGET=ppc-linux-gnu
-else ($(PLATFORM),ppc64)
-TARGET=ppc64-linux-gnu
-else ($(PLATFORM),sparc64)
-TARGET=sparc64-linux-gnu
+TARGET = amd64-linux-gnu
+endif
+ifeq ($(PLATFORM),arm32)
+TARGET = arm-linux-gnu
+endif
+ifeq ($(PLATFORM),ia32)
+TARGET = i686-pc-linux-gnu
+endif
+ifeq ($(PLATFORM),ia64)
+TARGET = ia64-pc-linux-gnu
+endif
+ifeq ($(PLATFORM),mips32)
+TARGET = mipsel-linux-gnu
+endif
+ifeq ($(PLATFORM),mips32eb)
+TARGET = mips-linux-gnu
+endif
+ifeq ($(PLATFORM),mips64)
+TARGET = mips64el-linux-gnu
+endif
+ifeq ($(PLATFORM),ppc32)
+TARGET = ppc-linux-gnu
+endif
+ifeq ($(PLATFORM),ppc64)
+TARGET = ppc64-linux-gnu
+endif
+ifeq ($(PLATFORM),sparc64)
+TARGET = sparc64-linux-gnu
 endif
 
 # Binutils configure flags.
 CONF_FLAGS = --disable-nls --disable-shared --enable-static \
-	--with-zlib=no
+	--with-zlib=no --with-ppl=no --with-cloog=no  \
+	--with-gmp=no --with-mpfr=no --with-mpc=no
 
 # Binutils make targets.
@@ -123,5 +134,4 @@
 all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
 		$(BINUTILS_CONFIGURED) $(REDIST_DETECT)
-	export PATH
 	make -C $(REDIST_DIR) $(MAKE_TARGETS)
 	cp -f $(REDIST_DIR)/gas/as-new ./as
@@ -143,25 +153,29 @@
 $(REDIST_DETECT): $(REDIST_FILENAME)
 	tar -x -j -f $<
-	mv -f $(REDIST_NAME) $(REDIST_DIR)
+	mv -f -T $(REDIST_NAME) $(REDIST_DIR)
+	touch $@
 
 # Generate false toolchain scripts.
 $(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
-	$^ gcc $(CC) '$(CFLAGS)'
-	$^ as $(AS)
-	$^ ar $(AR)
-	$^ ranlib
-	$^ ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
-	$^ objdump $(OBJDUMP)
-	$^ objcopy $(OBJCOPY)
-	$^ strip $(STRIP)
+	./$< gcc $(CC) '$(CFLAGS)'
+	./$< as $(AS)
+	./$< ar $(AR)
+	./$< ranlib
+	./$< ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
+	./$< objdump $(OBJDUMP)
+	./$< objcopy $(OBJCOPY)
+	./$< strip $(STRIP)
 
 # Patch binutils source tree.
 $(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
-	$^ do $(REDIST_DIR)
+	./$< do $(REDIST_DIR)
 	touch $@
 
 # Configure binutils.
+# $LD variable have to exported to override configure script caching.
 $(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
-	$^ --target=$(TARGET) $(CONF_FLAGS)
+	export LD=ld; \
+	cd $(REDIST_DIR); \
+	./configure --target=$(TARGET) $(CONF_FLAGS)
 
 # Delete binaries.
@@ -169,12 +183,12 @@
 # Unpatch binutils.
 # Delete generated scripts.
-clean: $(BINUTILS_PATCH)
+clean: $(BINUTILS_PATCH) clean_
 	rm -f as ld
-	if [ -e $(REDIST_DIR)/Makefile ]; then
-		make -C $(REDIST_DIR) distclean
+	if [ -e $(REDIST_DIR)/Makefile ]; then \
+		make -C $(REDIST_DIR) distclean; \
 	fi
-	if [ -e $(BINUTILS_PATCHED) ]; then
-		./intrusive.sh undo $(REDIST_DIR)
-		rm -f $(BINUTILS_PATCHED)
+	if [ -e $(BINUTILS_PATCHED) ]; then \
+		./intrusive.sh undo $(REDIST_DIR); \
+		rm -f $(BINUTILS_PATCHED); \
 	fi
 	rm -f $(TOOLCHAIN)
Index: uspace/app/binutils/distclean.sh
===================================================================
--- uspace/app/binutils/distclean.sh	(revision 2431f30122eccfaa411fde382b9414078c527ff4)
+++ uspace/app/binutils/distclean.sh	(revision 2431f30122eccfaa411fde382b9414078c527ff4)
@@ -0,0 +1,35 @@
+#! /bin/bash
+
+#
+# Copyright (c) 2011 Petr Koupy
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Delete binutils redistributable package.
+rm -f *tar.bz2
+# Delete binutils source tree.
+rm -r -f redist/*
+
Index: uspace/app/binutils/intrusive.sh
===================================================================
--- uspace/app/binutils/intrusive.sh	(revision df56f5c5794ef0f96486018092af3433f68006da)
+++ uspace/app/binutils/intrusive.sh	(revision 2431f30122eccfaa411fde382b9414078c527ff4)
@@ -34,18 +34,104 @@
 # would require too much complexity.
 #
+# List of patch descriptions:
+#
+# Patch 1
+# Even though binutils build process supports cross compilation where
+# build and host platforms are different, it is not easily applicable
+# to HelenOS. It would be difficult to satisfy binutils expectations
+# of host headers, libraries and tools on a build system (at least
+# until these are developed/ported). Another issue would be the 
+# necessity to carry out time consuming full canadian cross compilation
+# (even in case when build, host and target hardware platforms are the
+# same). Instead of going into such trouble, it is easier to leverage
+# already  built HelenOS toolchain as a first stage of canadian cross
+# and trick binutils scripts to do a simple cross compilation while 
+# actually doing second stage of canadian cross. Because binutils
+# configure scripts try to compile and execute various testing code, it
+# have to be ensured that these tests are skipped. Such behaviour can
+# be acomplished by patching cross compilation flag while leaving host
+# and build parameters empty (i.e. configure script believes it is
+# not doing cross compilation while skipping some testing as in the case
+# of cross compilation).
+# 
+# Patch 2
+# Enabled cross compilation flag brings along some anomalies which
+# have to reverted. 
+#
+# Patch 3
+# Binutils plugin support is dependent on libdl.so library.
+# By default, the plugin support is switched off for all
+# configure scripts of binutils. The only exception is configure
+# script of ld 2.21 (and possibly above), where plugin support
+# became mandatory (although not really needed).
+#
 
 case "$1" in
 	"do")
-		# Binutils plugin support is dependent on libdl.so library.
-		# By default, the plugin support is switched off for all
-		# configure scripts of binutils. The only exception is configure
-		# script of ld 2.21 (and possibly above), where plugin support
-		# became mandatory (although not really needed). 
-		mv -f "$2/ld/configure" "$2/ld/configure.backup"
-		sed 's/enable_plugins=yes/enable_plugins=no/g' \
-			< "$2/ld/configure.backup" > "$2/ld/configure"
+		# Backup original files.
+		cp -f "$2/configure" "$2/configure.backup"
+		cp -f "$2/bfd/configure" "$2/bfd/configure.backup"
+		cp -f "$2/gas/configure" "$2/gas/configure.backup"
+		cp -f "$2/intl/configure" "$2/intl/configure.backup"
+		cp -f "$2/ld/configure" "$2/ld/configure.backup"
+		cp -f "$2/libiberty/configure" "$2/libiberty/configure.backup"
+		cp -f "$2/opcodes/configure" "$2/opcodes/configure.backup"
+
+		# Patch main binutils configure script.
+		cat "$2/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
+		> "$2/configure"
+
+		# Patch bfd configure script.
+		cat "$2/bfd/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
+		> "$2/bfd/configure"
+
+		# Patch gas configure script.
+		cat "$2/gas/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
+		> "$2/gas/configure"
+
+		# Patch intl configure script.
+		cat "$2/intl/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
+		> "$2/intl/configure"
+
+		# Patch ld configure script.
+		cat "$2/ld/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
+		# See Patch 3.
+		sed 's/^enable_plugins=yes/enable_plugins=no/g' \
+		> "$2/ld/configure"
+
+		# Patch libiberty configure script.
+		cat "$2/libiberty/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
+		> "$2/libiberty/configure"
+
+		# Patch opcodes configure script.
+		cat "$2/opcodes/configure.backup" | \
+		# See Patch 1.
+		sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
+		# See Patch 2.
+		sed 's/BUILD_LIBS=-liberty/BUILD_LIBS=..\/libiberty\/libiberty.a/g' \
+		> "$2/opcodes/configure"
+
 		;;
 	"undo")
+		# Restore original files.
+		mv -f "$2/configure.backup" "$2/configure"
+		mv -f "$2/bfd/configure.backup" "$2/bfd/configure"
+		mv -f "$2/gas/configure.backup" "$2/gas/configure"
+		mv -f "$2/intl/configure.backup" "$2/intl/configure"
 		mv -f "$2/ld/configure.backup" "$2/ld/configure"
+		mv -f "$2/libiberty/configure.backup" "$2/libiberty/configure"
+		mv -f "$2/opcodes/configure.backup" "$2/opcodes/configure"
 		;;
 	*)
Index: uspace/app/binutils/toolchain.sh
===================================================================
--- uspace/app/binutils/toolchain.sh	(revision df56f5c5794ef0f96486018092af3433f68006da)
+++ uspace/app/binutils/toolchain.sh	(revision 2431f30122eccfaa411fde382b9414078c527ff4)
@@ -75,7 +75,7 @@
 			sed 's/-W[^ ]*//g' | \
 			sed 's/-pipe//g' | \
-			sed 's/-std=[^ ]*//g' | \
 			sed 's/-g//g' | \
 			sed 's/ [ ]*/ /g'`"
+		echo '	echo' \'"$2"\' \'"$CFLAGS"\' '"$@"'
 		echo "	$2" "$CFLAGS" '$@'
 		echo 'fi'
@@ -86,4 +86,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
 		echo "$2" '$@'
 		) > 'as'
@@ -93,4 +94,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
 		echo "$2" '$@'
 		) > 'ar'
@@ -100,4 +102,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
 		echo "ar -s" '$@'
 		) > 'ranlib'
@@ -107,4 +110,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2 -n $3 -T $4"\' '"$@"' \'"$5"\'
 		echo "$2 -n $3 -T $4" '$@' "$5"
 		) > 'ld'
@@ -114,4 +118,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
 		echo "$2" '$@'
 		) > 'objdump'
@@ -121,4 +126,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
 		echo "$2" '$@'
 		) > 'objcopy'
@@ -128,4 +134,5 @@
 		(
 		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
 		echo "$2" '$@'
 		) > 'strip'
