Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 4069f5c448feea0259e2e4055190f10c6d9ee0b0)
+++ uspace/Makefile	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
@@ -111,4 +111,9 @@
 	drv/bus/usb/vhc
 
+ifeq ($(CONFIG_BINUTILS),y)
+DIRS += \
+	app/binutils
+endif
+
 ## Networking
 #
Index: uspace/app/binutils/Makefile
===================================================================
--- uspace/app/binutils/Makefile	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
+++ uspace/app/binutils/Makefile	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
@@ -0,0 +1,234 @@
+#
+# 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.
+#
+
+nullstring =
+space = $(nullstring) # space
+
+# When redefined to 'y' on the command line, certain areas of this Makefile
+# behave slightly differently to simplify the maintenance of binutils port.
+MAINTAIN_BINUTILS=n
+
+# Information for obtaining specific binutils redistributable package.
+# Might be subject to change in the future.
+REDIST_VERSION = 2.21
+REDIST_NAME = binutils-$(REDIST_VERSION)
+REDIST_FILENAME = $(REDIST_NAME).tar.bz2
+REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
+
+# Directory for the binutils source tree.
+REDIST_DIR = ./redist
+
+# File to detect the presence of binutils source tree.
+REDIST_DETECT = $(REDIST_DIR)/configure
+
+# Directory for resulting binutils binaries.
+BIN_DIR = ./bin
+
+# $USPACE_PREFIX have to be based on the absolute path,
+# because targets derived from it will be referenced from
+# other than the current directory.
+USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
+
+# Ensure static configuration of Makefile.common.
+STATIC_ONLY = y
+
+# Link with POSIX runtime library.
+POSIX_COMPAT = y
+
+# Makefile.common for native applications.
+COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
+
+# Generated from native Makefile.common.
+COMMON_MAKEFILE_PATCHED = ./Makefile.common
+
+# AWK script which generates patched Makefile.common.
+MAKEFILE_PATCH = ./patch.awk
+
+# Compilers that can be used to build binutils.
+SUPPORTED_COMPILERS = gcc_cross gcc_native
+
+# Patched Makefile.common for ported user space applications.
+-include $(COMMON_MAKEFILE_PATCHED)
+
+# Patch $PATH to intercept toolchain calls.
+PATH := $(shell pwd):$(PATH)
+export PATH
+
+# Shell script for false toolchain generation.
+TOOLCHAIN_SCRIPT = ./toolchain.sh
+
+# False toolchain.
+TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
+
+# Stamp indicating whether the binutils source tree is patched.
+BINUTILS_PATCHED = ./done
+
+# Shell script for instrusive patches of binutils source tree.
+BINUTILS_PATCH = ./intrusive.sh
+
+# Detection whether the binutils are already configured.
+BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
+
+# Generated source file for libposix function stubs without posix_ prefix.
+CONFOBJ_SOURCE = ./confobj.c
+
+# Dummy object file for libposix function stubs without posix_ prefix..
+# Required by binutils configure script tests that links against symbols
+# without including headers (which means that symbols are not prefixed).
+CONFOBJ_OBJECT = $(subst $(space),\ ,$(shell pwd))/confobj.o
+
+# Required by libposix on RISC platforms.
+BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
+
+# Map the HelenOS target to binutils target.
+ifeq ($(PLATFORM),amd64)
+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-ppl=no --with-cloog=no  \
+	--with-gmp=no --with-mpfr=no --with-mpc=no
+
+# Binutils make targets.
+MAKE_TARGETS = all-gas all-ld
+
+# Check presence of gcc compiler.
+# Make binutils.
+# Copy binaries.
+ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
+all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
+		$(CONFOBJ_OBJECT) $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
+	make -C $(REDIST_DIR) $(MAKE_TARGETS)
+	cp -f $(REDIST_DIR)/gas/as-new $(BIN_DIR)/as
+	cp -f $(REDIST_DIR)/ld/ld-new $(BIN_DIR)/ld
+else
+all:
+	# Skipped: Cannot build binutils with unsupported compiler.
+endif
+
+# Create patched Makefile.common from native Makefile.common.
+$(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
+	awk -f $^ > $@
+
+# Download binutils redistributable package.
+$(REDIST_FILENAME):
+	wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
+
+# Extract binutils source tree.
+$(REDIST_DETECT): $(REDIST_FILENAME)
+	tar -x -j -f $<
+	mv -f -T $(REDIST_NAME) $(REDIST_DIR)
+	touch $@
+
+# Generate stubs for libposix functions without posix_ prefix.
+$(CONFOBJ_SOURCE):
+	echo '/* GENERATED FILE. DO NOT MODIFY. */' > $@; \
+	$(OBJDUMP) -t $(LIBPOSIX_PREFIX)/libposix.a | \
+	grep 'F .text' | grep -o -h -I -E 'posix_[^.]*$$' | sort -u | \
+	sed 's/posix_\([^ ]*\)/char \1() { return 0; }/g' >> $@
+
+# Compile dummy object for configure script tests.
+$(CONFOBJ_OBJECT): $(CONFOBJ_SOURCE) $(TOOLCHAIN)
+	./gcc -c -o $@ $<
+
+# Generate false toolchain scripts.
+$(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
+	./$< gcc $(CC) \
+		'$(CFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS) $(CONFOBJ_OBJECT)'
+	./$< 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)
+	touch $@
+
+# Configure binutils.
+# $LD variable have to exported to override configure script caching.
+$(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
+	export LD=ld; \
+	cd $(REDIST_DIR); \
+	./configure --target=$(TARGET) $(CONF_FLAGS)
+
+# Delete binaries.
+# Clean binutils.
+# Unpatch binutils.
+# Delete everything in redist folder.
+# Delete generated scripts.
+clean: $(BINUTILS_PATCH) clean_
+	rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
+	rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
+ifeq ($(MAINTAIN_BINUTILS),y)
+	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); \
+	fi
+else
+	rm -r -f redist/*
+	rm -f $(BINUTILS_PATCHED)
+endif
+	rm -f $(TOOLCHAIN)
+	rm -f $(COMMON_MAKEFILE_PATCHED)
+
Index: uspace/app/binutils/distclean.sh
===================================================================
--- uspace/app/binutils/distclean.sh	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
+++ uspace/app/binutils/distclean.sh	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
@@ -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 64639256fa3f0d80b3d76b8d985a9528ede74547)
+++ uspace/app/binutils/intrusive.sh	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
@@ -0,0 +1,209 @@
+#! /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.
+#
+
+#
+# This shell script is reserved for intrusive patches (hacks) to binutils
+# that cannot be done in a clean and isolated way or for which doing so 
+# 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).
+#
+# Patch 4
+# Whereas most systems maps pid_t to signed int, HelenOS maps it
+# to 64-bit unsigned integer (which is further masked by libposix to
+# 64-bit signed integer). Because libiberty blindly expects pid_t to be
+# signed int, there is some type incompatibility in libiberty
+# files related to executing a subprocess. Since both as and ld are
+# not runtime dependent on this functionality, the simplest solution is
+# to patch libiberty to avoid compiler warnings.
+#
+# Patch 5
+# When host and target system is equal, libbfd wants to compile a support
+# for core files, which is dependent on non-standard headers sys/param.h
+# and sys/user.h. Since we are cross compiling even when host and target
+# are equal, variables related to core file support must be cleared.
+#
+# Patch 6
+# There is a few occurences in binutils where POSIX function is declared 
+# and called without first including the corresponding header. Such
+# declarations cause a problem to the linker, because all functions
+# from libposix are prefixed with the posix_ prefix.
+#
+# Patch 7
+# Implementation of fnmatch inside libiberty is not very friendly to the
+# non-GNU libc which implements its own native fnmatch. To resolve this 
+# incompatibility, libiberty fnmatch has to be manually hidden.
+#
+
+case "$1" in
+	"do")
+		# 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/libiberty/Makefile.in" "$2/libiberty/Makefile.in.backup"
+		cp -f "$2/include/fnmatch.h" "$2/include/fnmatch.h.backup"
+		cp -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch.c.backup"
+		cp -f "$2/libiberty/pex-common.h" "$2/libiberty/pex-common.h.backup"
+		cp -f "$2/libiberty/xstrerror.c" "$2/libiberty/xstrerror.c.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' | \
+		# See Patch 5.
+		sed 's/COREFILE=".*"/COREFILE='\'\''/g' | \
+		sed 's/COREFILE=[^ ]*/COREFILE='\'\''/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"
+
+		# Hide libiberty fnmatch implementation.
+		# See Patch 7.
+		mv -f "$2/include/fnmatch.h" "$2/include/fnmatch_hide.h"
+		(
+		# Avoid compiler warning for empty compilation unit.
+		echo 'char __fnmatch_hide(void);'
+		echo 'char __fnmatch_hide(void) { return 0; }'
+		echo '#define __GNU_LIBRARY__'
+		cat "$2/libiberty/fnmatch.c.backup"
+		) > "$2/libiberty/fnmatch.c"
+		mv -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch_hide.c"
+		cat "$2/libiberty/Makefile.in.backup" | \
+		sed 's/fnmatch/fnmatch_hide/g' \
+		> "$2/libiberty/Makefile.in"
+
+		# Patch libiberty pex-common.h.
+		cat "$2/libiberty/pex-common.h.backup" | \
+		# See Patch 4.
+		sed 's/pid_t (\*wait)/int (*wait)/g' \
+		> "$2/libiberty/pex-common.h"
+
+		# Patch libiberty xstrerror.c.
+		# See Patch 6.
+		(
+		echo '#include <string.h>'
+		echo '#define DONT_DECLARE_STRERROR'
+		cat "$2/libiberty/xstrerror.c.backup"
+		) > "$2/libiberty/xstrerror.c"
+
+		# 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/libiberty/Makefile.in.backup" "$2/libiberty/Makefile.in"
+		rm -f "$2/include/fnmatch_hide.h" "$2/libiberty/fnmatch_hide.c"
+		mv -f "$2/include/fnmatch.h.backup" "$2/include/fnmatch.h"
+		mv -f "$2/libiberty/fnmatch.c.backup" "$2/libiberty/fnmatch.c"
+		mv -f "$2/libiberty/pex-common.h.backup" "$2/libiberty/pex-common.h"
+		mv -f "$2/libiberty/xstrerror.c.backup" "$2/libiberty/xstrerror.c"
+		mv -f "$2/opcodes/configure.backup" "$2/opcodes/configure"
+		;;
+	*)
+		;;
+esac
+
Index: uspace/app/binutils/patch.awk
===================================================================
--- uspace/app/binutils/patch.awk	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
+++ uspace/app/binutils/patch.awk	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
@@ -0,0 +1,51 @@
+#! /bin/awk -f
+
+#
+# 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.
+#
+
+#
+# This script is reserved for transformation of native
+# uspace/Makefile.common so it would be compatible with ported
+# application and its operations could be intercepted.
+#
+
+# Rename 'all' target so it can be hijacked.
+/^all/ {
+	$1 = "all_:"
+}
+
+# Rename 'clean' target so it can be hijacked.
+/^clean/ {
+	$1 = "clean_:"
+}
+
+# Print rest of the lines unaltered.
+{
+	print
+}
+
Index: uspace/app/binutils/toolchain.sh
===================================================================
--- uspace/app/binutils/toolchain.sh	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
+++ uspace/app/binutils/toolchain.sh	(revision 64639256fa3f0d80b3d76b8d985a9528ede74547)
@@ -0,0 +1,167 @@
+#! /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.
+#
+
+# 
+# This script is intended to be called indirectly from the Makefile.
+# Given information from Makefile.common (e.g. CFLAGS), this shell
+# script generates false toolchain consisting of a short shell script
+# for each tool. Therefore, generated false tool already contains some
+# filtered information from the HelenOS side. When the actual call is
+# intercepted, information passed from the binutils side is filtered
+# and stored. Information from both sides is then joined together
+# and passed to the real tool.
+#
+# Basic idea behind filtering the information is that binutils is
+# dominant provider for the compilation, whereas HelenOS is dominant
+# for the linkage. In that way, the compilation command from binutils
+# is left untouched and only extended with a couple of flags that are
+# specific for HelenOS (i.e. include directories, preprocessor 
+# directives, preprocessor flags, standard libc exclusion). Similarly,
+# the linkage command is taken from HelenOS and extended with the
+# filtered information from binutils (i.e. output binary, objects,
+# binutils libraries).
+#
+# Most of the false tools are straightforward. However, gcc needs a 
+# special approach because binutils use it for both compilation and
+# linkage. In case the linking usage is detected, the call is redirected
+# to the linker. There is also special case for configure script tests
+# that require compiler link step.
+#
+
+case "$1" in
+	"gcc")
+		(
+		echo '#! /bin/bash'
+		echo 'AS_LINK="`echo \"$*\" | grep '\'as-new\''`"'
+		echo 'LD_LINK="`echo \"$*\" | grep '\'ld-new\''`"'
+		echo 'LINK="`echo -n "$AS_LINK""$LD_LINK"`"'
+		echo 'if [ -n "$LINK" ]; then'
+		echo '	LD_ARGS="`echo \" $*\" | \'
+		echo '		sed '\'s/ -O[^ ]*//g\'' | \'
+		echo '		sed '\'s/ -W[^ ]*//g\'' | \'
+		echo '		sed '\'s/ -g//g\'' | \'
+		echo '		sed '\'s/ -l[^ ]*//g\'' | \'
+		echo '		sed '\'s/ [ ]*/ /g\''`"'
+		echo '	ld $LD_ARGS'
+		echo 'else'
+		CFLAGS="`echo " $3" | \
+			sed 's/ -O[^ ]*//g' | \
+			sed 's/ -W[^ ]*//g' | \
+			sed 's/ -pipe//g' | \
+			sed 's/ -g//g' | \
+			sed 's/ [ ]*/ /g'`"
+		echo '	CONFTEST="`echo \"$*\" | grep '\' conftest \''`"'
+		echo '	if [ -n "$CONFTEST" ]; then'
+		echo '		LFLAGS="-Xlinker -z -Xlinker muldefs"'
+		echo '		echo' \'"$2"\' '"$@"' \'"$CFLAGS -T $4"\' '"$LFLAGS"' \'"$5"\'
+		echo "		$2" '$@' "$CFLAGS -T $4" '$LFLAGS' "$5"
+		echo '	else'
+					# Remove flags:
+					# -Werror
+					#		Avoid build failure due to some harmless bugs
+					#		(e.g. unused parameter) in the HelenOS.
+					# -Wc++-compat
+					#		Required just for gold linker.
+		echo '		GCC_ARGS="`echo \" $*\" | \'
+		echo '			sed '\'s/ -Werror//g\'' | \'
+		echo '			sed '\'s/ -Wc++-compat//g\'' | \'
+		echo '			sed '\'s/ [ ]*/ /g\''`"'
+					# Add flags:
+					# -Wno-shadow
+					#		Silents the warning caused by 
+					#		harmless bug in ld/ldlang.h and ld/ldlex.c.
+#		echo '		GCC_ARGS="$GCC_ARGS -Wno-shadow"'
+		echo '		echo' \'"$2"\' '"$GCC_ARGS"' \'"$CFLAGS"\'
+		echo "		$2" '$GCC_ARGS' "$CFLAGS"
+		echo '	fi'
+		echo 'fi'
+		) > 'gcc'
+		chmod a+x 'gcc'
+		;;
+	"as")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
+		echo "$2" '$@'
+		) > 'as'
+		chmod a+x 'as'
+		;;
+	"ar")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
+		echo "$2" '$@'
+		) > 'ar'
+		chmod a+x 'ar'
+		;;
+	"ranlib")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' 'ar -s' '"$@"'
+		echo 'ar -s' '$@'
+		) > 'ranlib'
+		chmod a+x 'ranlib'
+		;;
+	"ld")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' \'"$2 -n $3 -T $4"\' '"$@"' \'"$5"\'
+		echo "$2 -n $3 -T $4" '$@' "$5"
+		) > 'ld'
+		chmod a+x 'ld'
+		;;
+	"objdump")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
+		echo "$2" '$@'
+		) > 'objdump'
+		chmod a+x 'objdump'
+		;;
+	"objcopy")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
+		echo "$2" '$@'
+		) > 'objcopy'
+		chmod a+x 'objcopy'
+		;;
+	"strip")
+		(
+		echo '#! /bin/bash'
+		echo 'echo' \'"$2"\' '"$@"'
+		echo "$2" '$@'
+		) > 'strip'
+		chmod a+x 'strip'
+		;;
+	*)
+		;;
+esac
+
Index: uspace/drv/bus/usb/usbhid/kbd.h
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd.h	(revision 4069f5c448feea0259e2e4055190f10c6d9ee0b0)
+++ 	(revision )
@@ -1,5 +1,0 @@
-/*
- * Dummy file because of shared layout sources.
- *
- * Do not delete.
- */
Index: uspace/drv/bus/usb/usbhid/kbd/layout.h
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd/layout.h	(revision 4069f5c448feea0259e2e4055190f10c6d9ee0b0)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../layout.h
Index: uspace/drv/bus/usb/usbhid/layout.h
===================================================================
--- uspace/drv/bus/usb/usbhid/layout.h	(revision 4069f5c448feea0259e2e4055190f10c6d9ee0b0)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/*
- * Copyright (c) 2009 Jiri Svoboda
- * Copyright (c) 2011 Lubos Slovak 
- * (copied from /uspace/srv/hid/kbd/include/layout.h)
- * 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * Keyboard layout.
- */
-
-#ifndef USB_HID_LAYOUT_H_
-#define USB_HID_LAYOUT_H_
-
-#include <sys/types.h>
-#include <io/console.h>
-
-typedef struct {
-	void (*reset)(void);
-	wchar_t (*parse_ev)(kbd_event_t *);
-} layout_op_t;
-
-extern layout_op_t us_qwerty_op;
-extern layout_op_t us_dvorak_op;
-extern layout_op_t cz_op;
-
-#endif
-
-/**
- * @}
- */
