Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision d7f2cd639fbae683ae373adf9383d6c3e0ae69cc)
+++ tools/autotool.py	(revision 12d6c984367491a333f4e1724f2e966246811839)
@@ -186,4 +186,5 @@
 	gnu_target = None
 	clang_target = None
+	helenos_target = None
 	cc_args = []
 	
@@ -195,12 +196,15 @@
 			gnu_target = "arm-linux-gnueabi"
 			clang_target = "arm-unknown-linux"
+			helenos_target = "arm-helenos-gnueabi"
 		
 		if (config['CROSS_TARGET'] == "ia32"):
 			gnu_target = "i686-pc-linux-gnu"
 			clang_target = "i386-unknown-linux"
+			helenos_target = "i686-pc-helenos"
 		
 		if (config['CROSS_TARGET'] == "mips32"):
 			gnu_target = "mipsel-linux-gnu"
 			clang_target = "mipsel-unknown-linux"
+			helenos_target = "mipsel-helenos"
 			common['CC_ARGS'].append("-mabi=32")
 	
@@ -209,4 +213,5 @@
 		gnu_target = "amd64-linux-gnu"
 		clang_target = "x86_64-unknown-linux"
+		helenos_target = "amd64-helenos"
 	
 	if (config['PLATFORM'] == "arm32"):
@@ -214,4 +219,5 @@
 		gnu_target = "arm-linux-gnueabi"
 		clang_target = "arm-unknown-linux"
+		helenos_target = "arm-helenos-gnueabi"
 	
 	if (config['PLATFORM'] == "ia32"):
@@ -219,8 +225,10 @@
 		gnu_target = "i686-pc-linux-gnu"
 		clang_target = "i386-unknown-linux"
+		helenos_target = "i686-pc-helenos"
 	
 	if (config['PLATFORM'] == "ia64"):
 		target = config['PLATFORM']
 		gnu_target = "ia64-pc-linux-gnu"
+		helenos_target = "ia64-pc-helenos"
 	
 	if (config['PLATFORM'] == "mips32"):
@@ -232,4 +240,5 @@
 			gnu_target = "mipsel-linux-gnu"
 			clang_target = "mipsel-unknown-linux"
+			helenos_target = "mipsel-helenos"
 		
 		if ((config['MACHINE'] == "bmalta")):
@@ -237,4 +246,5 @@
 			gnu_target = "mips-linux-gnu"
 			clang_target = "mips-unknown-linux"
+			helenos_target = "mips-helenos"
 	
 	if (config['PLATFORM'] == "mips64"):
@@ -246,4 +256,5 @@
 			gnu_target = "mips64el-linux-gnu"
 			clang_target = "mips64el-unknown-linux"
+			helenos_target = "mips64el-helenos"
 	
 	if (config['PLATFORM'] == "ppc32"):
@@ -251,4 +262,5 @@
 		gnu_target = "ppc-linux-gnu"
 		clang_target = "powerpc-unknown-linux"
+		helenos_target = "ppc-helenos"
 	
 	if (config['PLATFORM'] == "sparc64"):
@@ -256,6 +268,7 @@
 		gnu_target = "sparc64-linux-gnu"
 		clang_target = "sparc-unknown-linux"
-	
-	return (target, cc_args, gnu_target, clang_target)
+		helenos_target = "sparc64-helenos"
+	
+	return (target, cc_args, gnu_target, clang_target, helenos_target)
 
 def check_app(args, name, details):
@@ -697,4 +710,10 @@
 		cross_prefix = "/usr/local/cross"
 	
+	# HelenOS cross-compiler prefix
+	if ('CROSS_HELENOS_PREFIX' in os.environ):
+		cross_helenos_prefix = os.environ['CROSS_HELENOS_PREFIX']
+	else:
+		cross_helenos_prefix = "/usr/local/cross-helenos"
+	
 	# Prefix binutils tools on Solaris
 	if (os.uname()[0] == "SunOS"):
@@ -719,5 +738,5 @@
 		common['CC_ARGS'] = []
 		if (config['COMPILER'] == "gcc_cross"):
-			target, cc_args, gnu_target, clang_target = get_target(config)
+			target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
 			
 			if (target is None) or (gnu_target is None):
@@ -727,4 +746,21 @@
 			path = "%s/%s/bin" % (cross_prefix, target)
 			prefix = "%s-" % gnu_target
+			
+			check_gcc(path, prefix, common, PACKAGE_CROSS)
+			check_binutils(path, prefix, common, PACKAGE_CROSS)
+			
+			check_common(common, "GCC")
+			common['CC'] = common['GCC']
+			common['CC_ARGS'].extend(cc_args)
+		
+		if (config['COMPILER'] == "gcc_helenos"):
+			target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
+			
+			if (target is None) or (helenos_target is None):
+				print_error(["Unsupported compiler target for GNU GCC.",
+				             "Please contact the developers of HelenOS."])
+			
+			path = "%s/%s/bin" % (cross_helenos_prefix, target)
+			prefix = "%s-" % helenos_target
 			
 			check_gcc(path, prefix, common, PACKAGE_CROSS)
Index: tools/toolchain-binutils-2.23.1.patch
===================================================================
--- tools/toolchain-binutils-2.23.1.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
+++ tools/toolchain-binutils-2.23.1.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
@@ -0,0 +1,242 @@
+diff -ud -rud binutils-2.23.1/bfd/config.bfd binutils-2.23.1/bfd/config.bfd
+--- binutils-2.23.1/bfd/config.bfd	2012-09-04 16:14:59.000000000 +0200
++++ binutils-2.23.1/bfd/config.bfd	2013-07-25 09:47:45.116719403 +0200
+@@ -203,7 +203,7 @@
+     targ_defvec=ecoffalpha_little_vec
+     want64=true
+     ;;
+-  ia64*-*-freebsd* | ia64*-*-netbsd* | ia64*-*-linux-* | ia64*-*-elf* | ia64*-*-kfreebsd*-gnu)
++  ia64*-*-freebsd* | ia64*-*-netbsd* | ia64*-*-linux-* | ia64*-*-elf* | ia64*-*-kfreebsd*-gnu | ia64*-*-helenos)
+     targ_defvec=bfd_elf64_ia64_little_vec
+     targ_selvecs="bfd_elf64_ia64_big_vec bfd_pei_ia64_vec"
+     want64=true
+@@ -315,6 +315,7 @@
+     ;;
+   arm-*-elf | arm-*-freebsd* | arm*-*-linux-* | arm*-*-conix* | \
+   arm*-*-uclinux* | arm-*-kfreebsd*-gnu | \
++  arm-helenos-gnueabi | \
+   arm*-*-eabi* )
+     targ_defvec=bfd_elf32_littlearm_vec
+     targ_selvecs=bfd_elf32_bigarm_vec
+@@ -600,7 +601,7 @@
+     targ_selvecs=bfd_elf32_i386_vec
+     targ_underscore=yes
+     ;;
+-  i[3-7]86-*-linux-*)
++  i[3-7]86-*-linux-* | i[3-7]86-*-helenos*)
+     targ_defvec=bfd_elf32_i386_vec
+     targ_selvecs="i386linux_vec i386pei_vec"
+     targ64_selvecs="bfd_elf64_x86_64_vec bfd_elf32_x86_64_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec"
+@@ -643,7 +644,7 @@
+     targ_selvecs="bfd_elf32_i386_vec i386netbsd_vec i386coff_vec i386pei_vec x86_64pei_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec"
+     want64=true
+     ;;
+-  x86_64-*-linux-*)
++  x86_64-*-linux-* | x86_64-*-helenos*)
+     targ_defvec=bfd_elf64_x86_64_vec
+     targ_selvecs="bfd_elf32_i386_vec bfd_elf32_x86_64_vec i386linux_vec i386pei_vec x86_64pei_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec"
+     want64=true
+@@ -1016,7 +1017,7 @@
+     targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec ecoff_big_vec ecoff_little_vec"
+     ;;
+ #ifdef BFD64
+-  mips64*el-*-linux*)
++  mips64*el-*-linux* | mips64el-*-helenos*)
+     targ_defvec=bfd_elf32_ntradlittlemips_vec
+     targ_selvecs="bfd_elf32_ntradbigmips_vec bfd_elf32_tradlittlemips_vec bfd_elf32_tradbigmips_vec bfd_elf64_tradlittlemips_vec bfd_elf64_tradbigmips_vec"
+     want64=true
+@@ -1026,12 +1027,12 @@
+     targ_selvecs="bfd_elf32_ntradlittlemips_vec bfd_elf32_tradbigmips_vec bfd_elf32_tradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec"
+     want64=true
+     ;;
+-  mips*el-*-linux*)
++  mips*el-*-linux* | mipsel-*-helenos*)
+     targ_defvec=bfd_elf32_tradlittlemips_vec
+     targ_selvecs="bfd_elf32_tradbigmips_vec ecoff_little_vec ecoff_big_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradlittlemips_vec bfd_elf32_ntradbigmips_vec bfd_elf64_tradbigmips_vec"
+     want64=true
+     ;;
+-  mips*-*-linux*)
++  mips*-*-linux* | mips-*-helenos*)
+     targ_defvec=bfd_elf32_tradbigmips_vec
+     targ_selvecs="bfd_elf32_tradlittlemips_vec ecoff_big_vec ecoff_little_vec bfd_elf32_ntradbigmips_vec bfd_elf64_tradbigmips_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradlittlemips_vec"
+     want64=true
+@@ -1179,6 +1180,7 @@
+     want64=true
+     ;;
+   powerpc64-*-elf* | powerpc-*-elf64* | powerpc64-*-linux* | \
++  powerpc64-*-helenos* | \
+   powerpc64-*-*bsd*)
+     targ_defvec=bfd_elf64_powerpc_vec
+     targ_selvecs="bfd_elf64_powerpcle_vec bfd_elf32_powerpc_vec bfd_elf32_powerpcle_vec rs6000coff_vec rs6000coff64_vec aix5coff64_vec"
+@@ -1197,6 +1199,7 @@
+     ;;
+   powerpc-*-*bsd* | powerpc-*-elf* | powerpc-*-sysv4* | powerpc-*-eabi* | \
+   powerpc-*-solaris2* | powerpc-*-linux-* | powerpc-*-rtems* | \
++  powerpc-*-helenos* | \
+   powerpc-*-chorus*)
+     targ_defvec=bfd_elf32_powerpc_vec
+     targ_selvecs="rs6000coff_vec bfd_elf32_powerpcle_vec ppcboot_vec"
+@@ -1495,7 +1498,7 @@
+     targ_underscore=yes
+     want64=true
+     ;;
+-  sparc64*-*-linux-*)
++  sparc64*-*-linux-* | sparc64-*-helenos*)
+     targ_defvec=bfd_elf64_sparc_vec
+     targ_selvecs="bfd_elf32_sparc_vec sparclinux_vec sunos_big_vec"
+     want64=true
+diff -ud -rud binutils-2.23.1/config.sub binutils-2.23.1/config.sub
+--- binutils-2.23.1/config.sub	2012-04-25 17:53:25.000000000 +0200
++++ binutils-2.23.1/config.sub	2013-07-25 09:36:54.354122235 +0200
+@@ -1359,6 +1359,7 @@
+ 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ 	      | -chorusos* | -chorusrdb* | -cegcc* \
+ 	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
++	      | -helenos* \
+ 	      | -mingw32* | -linux-gnu* | -linux-android* \
+ 	      | -linux-newlib* | -linux-uclibc* \
+ 	      | -uxpv* | -beos* | -mpeix* | -udk* \
+diff -ud -rud binutils-2.23.1/gas/configure.tgt binutils-2.23.1/gas/configure.tgt
+--- binutils-2.23.1/gas/configure.tgt	2012-09-04 14:53:45.000000000 +0200
++++ binutils-2.23.1/gas/configure.tgt	2013-07-25 09:53:00.181319734 +0200
+@@ -119,7 +119,8 @@
+   arm-*-kaos*)				fmt=elf ;;
+   arm-*-conix*)				fmt=elf ;;
+   arm-*-linux*aout*)			fmt=aout em=linux ;;
+-  arm-*-linux-*eabi*)			fmt=elf  em=armlinuxeabi ;;
++  arm-*-linux-*eabi* | arm-helenos-*eabi*)
++  					fmt=elf  em=armlinuxeabi ;;
+   arm-*-linux-*)			fmt=elf  em=linux ;;
+   arm-*-uclinux*eabi*)			fmt=elf  em=armlinuxeabi ;;
+   arm-*-uclinux*)			fmt=elf  em=linux ;;
+@@ -210,7 +211,7 @@
+   i386-*-linux*aout*)			fmt=aout em=linux ;;
+   i386-*-linux*oldld)			fmt=aout em=linux ;;
+   i386-*-linux*coff*)			fmt=coff em=linux ;;
+-  i386-*-linux-*)			fmt=elf em=linux
++  i386-*-linux-* | i386-*-helenos*)	fmt=elf em=linux
+     case ${cpu}-${os} in
+       x86_64*-linux-gnux32)		arch=x86_64:32 ;;
+     esac ;;
+@@ -256,7 +257,7 @@
+   ia64-*-elf*)				fmt=elf ;;
+   ia64-*-*vms*)				fmt=elf em=vms ;;
+   ia64-*-aix*)				fmt=elf em=ia64aix ;;
+-  ia64-*-linux-*)			fmt=elf em=linux ;;
++  ia64-*-linux-* | ia64-*-helenos*)	fmt=elf em=linux ;;
+   ia64-*-hpux*)				fmt=elf em=hpux ;;
+   ia64-*-netbsd*)			fmt=elf em=nbsd ;;
+ 
+@@ -304,7 +305,7 @@
+   mips-*-irix*)				fmt=ecoff em=irix ;;
+   mips-*-lnews*)			fmt=ecoff em=lnews ;;
+   mips-*-riscos*)			fmt=ecoff ;;
+-  mips*-*-linux*)			fmt=elf em=tmips ;;
++  mips*-*-linux* | mips*-*-helenos*)	fmt=elf em=tmips ;;
+   mips*-*-freebsd* | mips*-*-kfreebsd*-gnu)
+ 					fmt=elf em=freebsd ;;
+   mips-*-sysv4*MP* | mips-*-gnu*)	fmt=elf em=tmips ;;
+@@ -349,7 +350,7 @@
+   ppc-*-beos*)				fmt=coff ;;
+   ppc-*-*n*bsd* | ppc-*-elf*)		fmt=elf ;;
+   ppc-*-eabi* | ppc-*-sysv4*)		fmt=elf ;;
+-  ppc-*-linux-*)			fmt=elf em=linux ;;
++  ppc-*-linux-* | ppc-*-helenos)	fmt=elf em=linux ;;
+   ppc-*-solaris*)			fmt=elf em=solaris ;;
+   ppc-*-rtems*)				fmt=elf ;;
+   ppc-*-macos*)				fmt=coff em=macos ;;
+@@ -392,7 +393,7 @@
+   sparc-*-aout)				fmt=aout em=sparcaout ;;
+   sparc-*-coff)				fmt=coff ;;
+   sparc-*-linux*aout*)			fmt=aout em=linux ;;
+-  sparc-*-linux-*)			fmt=elf em=linux ;;
++  sparc-*-linux-* | sparc-*-helenos*)	fmt=elf em=linux ;;
+   sparc-fujitsu-none)			fmt=aout ;;
+   sparc-*-elf)				fmt=elf ;;
+   sparc-*-sysv4*)			fmt=elf ;;
+diff -ud -rud binutils-2.23.1/ld/configure.tgt binutils-2.23.1/ld/configure.tgt
+--- binutils-2.23.1/ld/configure.tgt	2012-09-04 14:53:47.000000000 +0200
++++ binutils-2.23.1/ld/configure.tgt	2013-07-25 09:56:05.498734292 +0200
+@@ -87,7 +87,8 @@
+ 			targ_extra_emuls="armelfb armelf armelf_linux"
+ 			targ_extra_libpath="armelf_linux"
+ 			;;
+-arm*-*-linux-*eabi*)	targ_emul=armelf_linux_eabi
++arm*-*-linux-*eabi* | arm-helenos-*eabi*)
++			targ_emul=armelf_linux_eabi
+ 			targ_extra_emuls=armelfb_linux_eabi
+ 			targ_extra_libpath=$targ_extra_emuls
+ 			;;
+@@ -206,7 +207,8 @@
+ 			targ_extra_emuls=elf_i386
+ 			tdir_elf_i386=`echo ${targ_alias} | sed -e 's/aout//'` ;;
+ i[3-7]86-*-linux*oldld)	targ_emul=i386linux; targ_extra_emuls=elf_i386 ;;
+-i[3-7]86-*-linux-*)	targ_emul=elf_i386
++i[3-7]86-*-linux-* | i[3-7]86-*-helenos*)
++			targ_emul=elf_i386
+ 			targ_extra_emuls=i386linux
+ 			targ64_extra_emuls="elf_x86_64 elf32_x86_64 elf_l1om elf_k1om"
+ 			targ64_extra_libpath=elf_x86_64
+@@ -217,7 +219,8 @@
+ 			targ_extra_libpath="elf_i386 elf_x86_64 elf_l1om elf_k1om"
+ 			tdir_i386linux=`echo ${targ_alias}aout | sed -e 's/x86_64/i386/' -e 's/-linux-gnux32/-linux-gnu/'`
+ 			tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/' -e 's/-linux-gnux32/-linux-gnu/'` ;;
+-x86_64-*-linux-*)	targ_emul=elf_x86_64
++x86_64-*-linux-* | x86_64-*-helenos*)
++			targ_emul=elf_x86_64
+ 			targ_extra_emuls="elf32_x86_64 elf_i386 i386linux elf_l1om elf_k1om"
+ 			targ_extra_libpath="elf_i386 elf32_x86_64 elf_l1om elf_k1om"
+ 			tdir_i386linux=`echo ${targ_alias}aout | sed -e 's/x86_64/i386/'`
+@@ -334,7 +337,8 @@
+ 		        targ_emul=elf64_ia64_fbsd
+ 			targ_extra_emuls="elf64_ia64" ;;
+ ia64-*-netbsd*)		targ_emul=elf64_ia64 ;;
+-ia64-*-linux*)		targ_emul=elf64_ia64 ;;
++ia64-*-linux* | ia64-*-helenos*)
++			targ_emul=elf64_ia64 ;;
+ ia64-*-*vms*)		targ_emul=elf64_ia64_vms ;;
+ ia64-*-aix*)		targ_emul=elf64_aix
+ 			;;
+@@ -434,16 +438,19 @@
+ mips*-*-vxworks*)	targ_emul=elf32ebmipvxworks
+ 		        targ_extra_emuls="elf32elmipvxworks" ;;
+ mips*-*-windiss)	targ_emul=elf32mipswindiss ;;
+-mips64*el-*-linux-*)	targ_emul=elf32ltsmipn32
++mips64*el-*-linux-* | mips64*el-*-helenos*)
++			targ_emul=elf32ltsmipn32
+ 			targ_extra_emuls="elf32btsmipn32 elf32ltsmip elf32btsmip elf64ltsmip elf64btsmip"
+ 			targ_extra_libpath=$targ_extra_emuls ;;
+ mips64*-*-linux-*)	targ_emul=elf32btsmipn32
+ 			targ_extra_emuls="elf32ltsmipn32 elf32btsmip elf32ltsmip elf64btsmip elf64ltsmip"
+ 			targ_extra_libpath=$targ_extra_emuls ;;
+-mips*el-*-linux-*)	targ_emul=elf32ltsmip
++mips*el-*-linux-* | mipsel-*-helenos*)
++			targ_emul=elf32ltsmip
+ 			targ_extra_emuls="elf32btsmip elf32ltsmipn32 elf64ltsmip elf32btsmipn32 elf64btsmip"
+ 			targ_extra_libpath=$targ_extra_emuls ;;
+-mips*-*-linux-*)	targ_emul=elf32btsmip
++mips*-*-linux-* | mips-*-helenos*)
++			targ_emul=elf32btsmip
+ 			targ_extra_emuls="elf32ltsmip elf32btsmipn32 elf64btsmip elf32ltsmipn32 elf64ltsmip"
+ 			targ_extra_libpath=$targ_extra_emuls ;;
+ mips64*el-*-freebsd* | mips64*el-*-kfreebsd*-gnu)
+@@ -503,7 +510,8 @@
+ 			tdir_elf32ppc=`echo "${targ_alias}" | sed -e 's/64//'`
+ 			tdir_elf32ppc_fbsd=$tdir_elf32ppc
+ 			;;
+-powerpc*-*-linux*)	case "${targ}" in
++powerpc*-*-linux* | powerpc*-*-helenos*)
++			case "${targ}" in
+ 			*64*)	targ_emul=elf64ppc
+ 				targ_extra_emuls="elf32ppclinux elf32ppc elf32ppcsim"
+ 				targ_extra_libpath="elf32ppclinux elf32ppc"
+@@ -642,7 +650,8 @@
+ 			targ_extra_emuls="elf32_sparc sun4"
+ 			tdir_elf32_sparc=`echo ${targ_alias} | sed -e 's/aout//'`
+ 			tdir_sun4=sparc-sun-sunos4 ;;
+-sparc64-*-linux-*)	targ_emul=elf64_sparc
++sparc64-*-linux-* | sparc64-*-helenos*)
++			targ_emul=elf64_sparc
+ 			targ_extra_emuls="elf32_sparc sparclinux sun4"
+ 			targ_extra_libpath=elf32_sparc
+ 			tdir_elf32_sparc=`echo ${targ_alias} | sed -e 's/64//'`
Index: tools/toolchain-gcc-4.8.1-headers.patch
===================================================================
--- tools/toolchain-gcc-4.8.1-headers.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
+++ tools/toolchain-gcc-4.8.1-headers.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
@@ -0,0 +1,267 @@
+diff -ud -Nrud gcc-4.8.1/gcc/config/arm/helenos-arm32.h gcc-4.8.1/gcc/config/arm/helenos-arm32.h
+--- gcc-4.8.1/gcc/config/arm/helenos-arm32.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/arm/helenos-arm32.h	2013-07-12 13:13:18.292688885 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for arm32. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "arm32", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/arm/helenos.h gcc-4.8.1/gcc/config/arm/helenos.h
+--- gcc-4.8.1/gcc/config/arm/helenos.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/arm/helenos.h	2013-07-12 13:13:22.362704068 +0200
+@@ -0,0 +1,16 @@
++/* Definitions for HelenOS compiled for arm32.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/arm/linux-eabi.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS() 		\
++  do 						\
++    {						\
++      TARGET_BPABI_CPP_BUILTINS();		\
++      GNU_USER_TARGET_OS_CPP_BUILTINS();	\
++      ANDROID_TARGET_OS_CPP_BUILTINS();		\
++      HELENOS_CPP_BUILTINS();			\
++      HELENOS_ARCH_CPP_BUILTINS();		\
++    }						\
++  while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/helenos.h gcc-4.8.1/gcc/config/helenos.h
+--- gcc-4.8.1/gcc/config/helenos.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/helenos.h	2013-07-12 12:06:57.780007295 +0200
+@@ -0,0 +1,6 @@
++/* Common definitions for HelenOS. */
++
++#define HELENOS_CPP_BUILTINS() \
++	do { \
++		builtin_define_std("__helenos__"); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/ia64/helenos.h gcc-4.8.1/gcc/config/ia64/helenos.h
+--- gcc-4.8.1/gcc/config/ia64/helenos.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/ia64/helenos.h	2013-07-12 13:17:35.477164401 +0200
+@@ -0,0 +1,13 @@
++/* Definitions for HelenOS compiled for ia64.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/ia64/linux.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()		\
++do {						\
++	GNU_USER_TARGET_OS_CPP_BUILTINS();	\
++	builtin_define("_LONGLONG");		\
++	HELENOS_CPP_BUILTINS();			\
++	HELENOS_ARCH_CPP_BUILTINS();		\
++} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/ia64/helenos-ia64.h gcc-4.8.1/gcc/config/ia64/helenos-ia64.h
+--- gcc-4.8.1/gcc/config/ia64/helenos-ia64.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/ia64/helenos-ia64.h	2013-07-12 13:17:30.663808636 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for ia64. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "ia64", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/i386/helenos-amd64.h gcc-4.8.1/gcc/config/i386/helenos-amd64.h
+--- gcc-4.8.1/gcc/config/i386/helenos-amd64.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/i386/helenos-amd64.h	2013-07-12 10:14:11.843671034 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for amd64. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "amd64", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/i386/helenos.h gcc-4.8.1/gcc/config/i386/helenos.h
+--- gcc-4.8.1/gcc/config/i386/helenos.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/i386/helenos.h	2013-07-12 10:12:55.409994661 +0200
+@@ -0,0 +1,15 @@
++/* Definitions for HelenOS compiled for ia32/amd64.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/i386/linux-common.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()               \
++  do                                           \
++    {                                          \
++      GNU_USER_TARGET_OS_CPP_BUILTINS();       \
++      ANDROID_TARGET_OS_CPP_BUILTINS();	       \
++      HELENOS_CPP_BUILTINS();		       \
++      HELENOS_ARCH_CPP_BUILTINS();             \
++    }                                          \
++  while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/i386/helenos-ia32.h gcc-4.8.1/gcc/config/i386/helenos-ia32.h
+--- gcc-4.8.1/gcc/config/i386/helenos-ia32.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/i386/helenos-ia32.h	2013-07-12 10:14:07.256983828 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for ia32. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "ia32", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/mips/helenos.h gcc-4.8.1/gcc/config/mips/helenos.h
+--- gcc-4.8.1/gcc/config/mips/helenos.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/mips/helenos.h	2013-07-12 10:22:48.782642814 +0200
+@@ -0,0 +1,16 @@
++/* Definitions for HelenOS compiled for mips32/mips64.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/mips/linux-common.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()				\
++  do {								\
++    GNU_USER_TARGET_OS_CPP_BUILTINS();				\
++    /* The GNU C++ standard library requires this.  */		\
++    if (c_dialect_cxx ())					\
++      builtin_define ("_GNU_SOURCE");				\
++    ANDROID_TARGET_OS_CPP_BUILTINS();				\
++    HELENOS_CPP_BUILTINS();					\
++    HELENOS_ARCH_CPP_BUILTINS();				\
++  } while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/mips/helenos-mips32eb.h gcc-4.8.1/gcc/config/mips/helenos-mips32eb.h
+--- gcc-4.8.1/gcc/config/mips/helenos-mips32eb.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/mips/helenos-mips32eb.h	2013-07-12 10:21:30.262295740 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for mips32eb. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "mips32eb", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/mips/helenos-mips32el.h gcc-4.8.1/gcc/config/mips/helenos-mips32el.h
+--- gcc-4.8.1/gcc/config/mips/helenos-mips32el.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/mips/helenos-mips32el.h	2013-07-12 10:21:15.885565349 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for mips32el. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "mips32", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/mips/helenos-mips64el.h gcc-4.8.1/gcc/config/mips/helenos-mips64el.h
+--- gcc-4.8.1/gcc/config/mips/helenos-mips64el.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/mips/helenos-mips64el.h	2013-07-12 10:20:27.942019112 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for mips64. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "mips64", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/rs6000/helenos.h gcc-4.8.1/gcc/config/rs6000/helenos.h
+--- gcc-4.8.1/gcc/config/rs6000/helenos.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/rs6000/helenos.h	2013-07-12 13:15:10.209819251 +0200
+@@ -0,0 +1,18 @@
++/* Definitions for HelenOS compiled for ppc32.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/rs6000/linux.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()		\
++  do						\
++    {						\
++      builtin_define_std ("PPC");		\
++      builtin_define_std ("powerpc");		\
++      builtin_assert ("cpu=powerpc");		\
++      builtin_assert ("machine=powerpc");	\
++      TARGET_OS_SYSV_CPP_BUILTINS ();		\
++      HELENOS_CPP_BUILTINS();			\
++      HELENOS_ARCH_CPP_BUILTINS();		\
++    }						\
++  while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/rs6000/helenos-ppc32.h gcc-4.8.1/gcc/config/rs6000/helenos-ppc32.h
+--- gcc-4.8.1/gcc/config/rs6000/helenos-ppc32.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/rs6000/helenos-ppc32.h	2013-07-12 13:15:02.986452099 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for ppc32. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "ppc32", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/rs6000/helenos-ppc64.h gcc-4.8.1/gcc/config/rs6000/helenos-ppc64.h
+--- gcc-4.8.1/gcc/config/rs6000/helenos-ppc64.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/rs6000/helenos-ppc64.h	2013-07-12 13:16:27.720181662 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for ppc64. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "ppc64", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/rs6000/helenos64.h gcc-4.8.1/gcc/config/rs6000/helenos64.h
+--- gcc-4.8.1/gcc/config/rs6000/helenos64.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/rs6000/helenos64.h	2013-07-12 13:16:31.873534389 +0200
+@@ -0,0 +1,32 @@
++/* Definitions for HelenOS compiled for ppc64.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/rs6000/linux64.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()			\
++  do							\
++    {							\
++      if (TARGET_64BIT)					\
++	{						\
++	  builtin_define ("__PPC__");			\
++	  builtin_define ("__PPC64__");			\
++	  builtin_define ("__powerpc__");		\
++	  builtin_define ("__powerpc64__");		\
++	  if (!DOT_SYMBOLS)				\
++	    builtin_define ("_CALL_LINUX");		\
++	  builtin_assert ("cpu=powerpc64");		\
++	  builtin_assert ("machine=powerpc64");		\
++	}						\
++      else						\
++	{						\
++	  builtin_define_std ("PPC");			\
++	  builtin_define_std ("powerpc");		\
++	  builtin_assert ("cpu=powerpc");		\
++	  builtin_assert ("machine=powerpc");		\
++	  TARGET_OS_SYSV_CPP_BUILTINS ();		\
++	}						\
++      HELENOS_CPP_BUILTINS();				\
++      HELENOS_ARCH_CPP_BUILTINS();			\
++    }							\
++  while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/sparc/helenos-sparc64.h gcc-4.8.1/gcc/config/sparc/helenos-sparc64.h
+--- gcc-4.8.1/gcc/config/sparc/helenos-sparc64.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/sparc/helenos-sparc64.h	2013-07-12 13:19:25.411009134 +0200
+@@ -0,0 +1,6 @@
++/* Definitions for HelenOS compiled for sparc64. */
++
++#define HELENOS_ARCH_CPP_BUILTINS() \
++	do { \
++		builtin_define_with_value("helenos_uarch", "sparc64", 0); \
++	} while (0)
+diff -ud -Nrud gcc-4.8.1/gcc/config/sparc/helenos64.h gcc-4.8.1/gcc/config/sparc/helenos64.h
+--- gcc-4.8.1/gcc/config/sparc/helenos64.h	1970-01-01 01:00:00.000000000 +0100
++++ gcc-4.8.1/gcc/config/sparc/helenos64.h	2013-07-12 13:19:16.480967658 +0200
+@@ -0,0 +1,19 @@
++/* Definitions for HelenOS compiled for sparc64.
++ *
++ * (TARGET_OS_CPP_BUILTINS copied from $GCC_ROOT/gcc/config/sparc/linux64.h)
++ */
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()		\
++  do						\
++    {						\
++      GNU_USER_TARGET_OS_CPP_BUILTINS();	\
++      if (TARGET_ARCH64)			\
++        builtin_define ("_LONGLONG");		\
++      if (TARGET_ARCH32				\
++          && TARGET_LONG_DOUBLE_128)		\
++	builtin_define ("__LONG_DOUBLE_128__");	\
++      HELENOS_CPP_BUILTINS();			\
++      HELENOS_ARCH_CPP_BUILTINS();		\
++    }						\
++  while (0)
Index: tools/toolchain-gcc-4.8.1-targets.patch
===================================================================
--- tools/toolchain-gcc-4.8.1-targets.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
+++ tools/toolchain-gcc-4.8.1-targets.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
@@ -0,0 +1,273 @@
+diff -ud -Nrud gcc-4.8.1/config.sub gcc-4.8.1/config.sub
+--- gcc-4.8.1/config.sub	2013-01-11 14:02:58.000000000 +0100
++++ gcc-4.8.1/config.sub	2013-07-12 09:10:19.136870930 +0200
+@@ -1369,6 +1369,7 @@
+ 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ 	      | -chorusos* | -chorusrdb* | -cegcc* \
+ 	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
++	      | -helenos \
+ 	      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+ 	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+ 	      | -uxpv* | -beos* | -mpeix* | -udk* \
+diff -ud -Nrud gcc-4.8.1/gcc/config.gcc gcc-4.8.1/gcc/config.gcc
+--- gcc-4.8.1/gcc/config.gcc	2013-03-13 10:47:41.000000000 +0100
++++ gcc-4.8.1/gcc/config.gcc	2013-07-12 13:20:08.321208280 +0200
+@@ -624,7 +624,7 @@
+   # need_64bit_hwint=yes # system compiler has this for all arch!
+   use_gcc_stdint=wrap
+   ;;
+-*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu)
++*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-helenos*)
+   extra_options="$extra_options gnu-user.opt"
+   gas=yes
+   gnu_ld=yes
+@@ -642,7 +642,7 @@
+   # glibc / uclibc / bionic switch.
+   # uclibc and bionic aren't usable for GNU/Hurd and neither for GNU/k*BSD.
+   case $target in
+-    *linux*)
++    *linux* | *helenos*)
+       extra_options="$extra_options linux.opt";;
+   esac
+   case $target in
+@@ -663,7 +663,7 @@
+   use_gcc_stdint=wrap
+   # Add Android userspace support to Linux targets.
+   case $target in
+-    *linux*)
++    *linux* | *helenos*)
+       tm_file="$tm_file linux-android.h"
+       extra_options="$extra_options linux-android.opt"
+       ;;
+@@ -681,6 +681,10 @@
+   cxx_target_objs="${cxx_target_objs} glibc-c.o"
+   tmake_file="${tmake_file} t-glibc"
+   target_has_targetcm=yes
++  # HelenOS
++  case $target in
++    *-helenos*) tm_file="$tm_file helenos.h" ;;
++  esac
+   ;;
+ *-*-netbsd*)
+   tmake_file="t-slibgcc"
+@@ -868,7 +872,7 @@
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+ 	tmake_file="${tmake_file} arm/t-arm"
+ 	;;
+-arm*-*-linux-*)			# ARM GNU/Linux with ELF
++arm*-*-linux-* | arm*-helenos-*)			# ARM GNU/Linux with ELF
+ 	tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h arm/elf.h arm/linux-gas.h arm/linux-elf.h"
+ 	case $target in
+ 	arm*b-*-linux*)
+@@ -890,6 +894,12 @@
+ 	# The EABI requires the use of __cxa_atexit.
+ 	default_use_cxa_atexit=yes
+ 	with_tls=${with_tls:-gnu}
++	# HelenOS
++	# (Strangely, tm_file ignores the defaults loaded previously and
++	# we need to add helenos.h one more time.)
++	case $target in
++	*-helenos*) tm_file="$tm_file helenos.h arm/helenos-arm32.h arm/helenos.h" ;;
++	esac
+ 	;;
+ arm*-*-uclinux*eabi*)		# ARM ucLinux
+ 	tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/linux-gas.h arm/uclinux-elf.h glibc-stdint.h"
+@@ -1257,12 +1267,12 @@
+ 	gas=yes
+ 	gnu_ld=yes
+ 	;;
+-i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
++i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu | i[34567]86-*-helenos)
+ 			# Intel 80386's running GNU/*
+ 			# with ELF format using glibc 2
+ 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h gnu-user.h glibc-stdint.h"
+ 	case ${target} in
+-	i[34567]86-*-linux*)
++	i[34567]86-*-linux* | i[34567]86-*-helenos)
+ 		tm_file="${tm_file} linux.h"
+ 		# Assume modern glibc
+ 		default_gnu_indirect_function=yes
+@@ -1318,12 +1328,16 @@
+ 		tm_file="$tm_file i386/gnu-user-common.h i386/gnu-user.h gnu.h i386/gnu.h"
+ 		;;
+ 	esac
++	# HelenOS
++	case $target in
++	*-helenos*) tm_file="$tm_file i386/helenos-ia32.h i386/helenos.h" ;;
++	esac
+ 	;;
+-x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
++x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu | x86_64-*-helenos)
+ 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h gnu-user.h glibc-stdint.h \
+ 		 i386/x86-64.h i386/gnu-user-common.h i386/gnu-user64.h"
+ 	case ${target} in
+-	x86_64-*-linux*)
++	x86_64-*-linux* | x86_64-*-helenos)
+ 		tm_file="${tm_file} linux.h i386/linux-common.h i386/linux64.h"
+ 		# Assume modern glibc
+ 		default_gnu_indirect_function=yes
+@@ -1359,6 +1373,10 @@
+ 		esac
+ 	done
+ 	TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
++	# HelenOS
++	case $target in
++	*-helenos*) tm_file="$tm_file i386/helenos-amd64.h i386/helenos.h" ;;
++	esac
+ 	;;
+ i[34567]86-pc-msdosdjgpp*)
+ 	xm_file=i386/xm-djgpp.h
+@@ -1567,10 +1585,14 @@
+ 	target_cpu_default="MASK_GNU_AS|MASK_GNU_LD"
+ 	tmake_file="${tmake_file} ia64/t-ia64"
+ 	;;
+-ia64*-*-linux*)
++ia64*-*-linux* | ia64-*-helenos)
+ 	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h ia64/sysv4.h ia64/linux.h"
+ 	tmake_file="${tmake_file} ia64/t-ia64 ia64/t-linux t-libunwind"
+ 	target_cpu_default="MASK_GNU_AS|MASK_GNU_LD"
++	# HelenOS
++	case $target in
++	*-helenos*) tm_file="$tm_file ia64/helenos-ia64.h ia64/helenos.h" ;;
++	esac
+ 	;;
+ ia64*-*-hpux*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h ia64/sysv4.h ia64/hpux.h"
+@@ -1794,7 +1816,7 @@
+ 	gas=yes
+ 	test x$with_llsc != x || with_llsc=yes
+ 	;;
+-mips64*-*-linux* | mipsisa64*-*-linux*)
++mips64*-*-linux* | mipsisa64*-*-linux* | mips64*-*-helenos)
+ 	tm_file="dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/gnu-user64.h mips/linux64.h mips/linux-common.h"
+ 	tmake_file="${tmake_file} mips/t-linux64"
+ 	tm_defines="${tm_defines} MIPS_ABI_DEFAULT=ABI_N32"
+@@ -1814,8 +1836,12 @@
+ 	gnu_ld=yes
+ 	gas=yes
+ 	test x$with_llsc != x || with_llsc=yes
++	# HelenOS
++	case $target in
++	*-helenos*) tm_file="$tm_file mips/helenos-mips64el.h mips/helenos.h" ;;
++	esac
+ 	;;
+-mips*-*-linux*)				# Linux MIPS, either endian.
++mips*-*-linux* | mips*-*-helenos)	# Linux MIPS, either endian.
+         tm_file="dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h"
+ 	if test x$enable_targets = xall; then
+ 		tm_file="${tm_file} mips/gnu-user64.h mips/linux64.h"
+@@ -1830,6 +1856,11 @@
+ 		tm_defines="${tm_defines} MIPS_ISA_DEFAULT=32"
+         esac
+ 	test x$with_llsc != x || with_llsc=yes
++	# HelenOS
++	case $target in
++	mipsel-*-helenos*) tm_file="$tm_file mips/helenos-mips32el.h mips/helenos.h" ;;
++	mips-*-helenos*) tm_file="$tm_file mips/helenos-mips32eb.h mips/helenos.h" ;;
++	esac
+ 	;;
+ mips*-mti-elf*)
+ 	tm_file="elfos.h newlib-stdint.h ${tm_file} mips/elf.h mips/sde.h mips/mti-elf.h"
+@@ -2066,7 +2097,7 @@
+ 	extra_options="${extra_options} rs6000/sysv4.opt"
+ 	tmake_file="rs6000/t-fprules rs6000/t-rtems t-rtems rs6000/t-ppccomm"
+ 	;;
+-powerpc-*-linux* | powerpc64-*-linux*)
++powerpc-*-linux* | powerpc64-*-linux* | powerpc*-*-helenos)
+ 	tm_file="${tm_file} dbxelf.h elfos.h freebsd-spec.h rs6000/sysv4.h"
+ 	extra_options="${extra_options} rs6000/sysv4.opt"
+ 	tmake_file="rs6000/t-fprules rs6000/t-ppcos ${tmake_file} rs6000/t-ppccomm"
+@@ -2079,7 +2110,7 @@
+ 	    powerpc-*-linux*spe* | powerpc-*-linux*paired*)
+ 		maybe_biarch=
+ 		;;
+-	    powerpc64-*-linux*)
++	    powerpc64-*-linux* | powerpc64-*-helenos)
+ 	    	test x$with_cpu != x || cpu_is_64bit=yes
+ 		maybe_biarch=always
+ 		;;
+@@ -2112,6 +2143,11 @@
+ 	if test x${enable_secureplt} = xyes; then
+ 		tm_file="rs6000/secureplt.h ${tm_file}"
+ 	fi
++	# HelenOS
++	case $target in
++	powerpc-*-helenos*) tm_file="$tm_file rs6000/helenos-ppc32.h rs6000/helenos.h" ;;
++	powerpc64-*-helenos*) tm_file="$tm_file rs6000/helenos-ppc64.h rs6000/helenos64.h" ;;
++	esac
+ 	;;
+ powerpc-wrs-vxworks|powerpc-wrs-vxworksae)
+ 	tm_file="${tm_file} elfos.h freebsd-spec.h rs6000/sysv4.h"
+@@ -2496,10 +2532,14 @@
+ 	extra_options="${extra_options}"
+ 	tmake_file="${tmake_file} sparc/t-sparc sparc/t-rtems-64 t-rtems"
+ 	;;
+-sparc64-*-linux*)
++sparc64-*-linux* | sparc64-*-helenos)
+ 	tm_file="sparc/biarch64.h ${tm_file} dbxelf.h elfos.h sparc/sysv4.h gnu-user.h linux.h glibc-stdint.h sparc/default-64.h sparc/linux64.h sparc/tso.h"
+ 	extra_options="${extra_options} sparc/long-double-switch.opt"
+ 	tmake_file="${tmake_file} sparc/t-sparc sparc/t-linux64"
++	# HelenOS
++	case $target in
++	*-helenos*) tm_file="$tm_file sparc/helenos-sparc64.h sparc/helenos64.h" ;;
++	esac
+ 	;;
+ sparc64-*-freebsd*|ultrasparc-*-freebsd*)
+ 	tm_file="${tm_file} ${fbsd_tm_file} dbxelf.h elfos.h sparc/sysv4.h sparc/freebsd.h"
+diff -ud -Nrud gcc-4.8.1/libgcc/config.host gcc-4.8.1/libgcc/config.host
+--- gcc-4.8.1/libgcc/config.host	2013-02-04 20:06:20.000000000 +0100
++++ gcc-4.8.1/libgcc/config.host	2013-07-12 09:10:20.120208557 +0200
+@@ -195,7 +195,7 @@
+       ;;
+   esac
+   ;;
+-*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu)
++*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-*-helenos)
+   tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver t-linux"
+   extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o"
+   ;;
+@@ -322,7 +322,7 @@
+ arm*-*-netbsdelf*)
+ 	tmake_file="$tmake_file arm/t-arm arm/t-netbsd t-slibgcc-gld-nover"
+ 	;;
+-arm*-*-linux*)			# ARM GNU/Linux with ELF
++arm*-*-linux* | arm*-helenos-gnueabi)			# ARM GNU/Linux with ELF
+ 	tmake_file="${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix"
+ 	tmake_file="${tmake_file} arm/t-elf arm/t-bpabi arm/t-linux-eabi t-slibgcc-libgcc"
+ 	tm_file="$tm_file arm/bpabi-lib.h"
+@@ -518,7 +518,7 @@
+ 	;;
+ x86_64-*-openbsd*)
+ 	;;
+-i[34567]86-*-linux*)
++i[34567]86-*-linux* | i[34567]86-*-helenos)
+ 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ 	tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
+ 	md_unwind_header=i386/linux-unwind.h
+@@ -527,7 +527,7 @@
+ 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ 	tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
+ 	;;
+-x86_64-*-linux*)
++x86_64-*-linux* | x86_64-*-helenos)
+ 	extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ 	tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
+ 	md_unwind_header=i386/linux-unwind.h
+@@ -631,7 +631,7 @@
+ 	extra_parts="$extra_parts crtfastmath.o"
+ 	tmake_file="$tmake_file ia64/t-ia64 ia64/t-ia64-elf ia64/t-eh-ia64 t-crtfm"
+ 	;;
+-ia64*-*-linux*)
++ia64*-*-linux* | ia64-*-helenos)
+ 	# Don't use crtbeginT.o from *-*-linux* default.
+ 	extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtfastmath.o"
+ 	tmake_file="$tmake_file ia64/t-ia64 ia64/t-ia64-elf t-crtfm t-softfp-tf ia64/t-softfp t-softfp ia64/t-softfp-compat ia64/t-eh-ia64 t-libunwind ia64/t-linux"
+@@ -1038,7 +1038,7 @@
+ 	tmake_file="$tmake_file t-crtfm"
+ 	extra_parts="$extra_parts crtfastmath.o"
+ 	;;
+-sparc64-*-linux*)		# 64-bit SPARC's running GNU/Linux
++sparc64-*-linux* | sparc64-*-helenos)	# 64-bit SPARC's running GNU/Linux
+ 	extra_parts="$extra_parts crtfastmath.o"
+ 	tmake_file="${tmake_file} t-crtfm sparc/t-linux"
+ 	if test "${host_address}" = 64; then
Index: tools/toolchain-gdb-7.6.patch
===================================================================
--- tools/toolchain-gdb-7.6.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
+++ tools/toolchain-gdb-7.6.patch	(revision 12d6c984367491a333f4e1724f2e966246811839)
@@ -0,0 +1,173 @@
+diff -rud gdb-7.6-original/bfd/config.bfd gdb-7.6/bfd/config.bfd
+--- gdb-7.6-original/bfd/config.bfd	2013-03-05 12:47:01.000000000 +0100
++++ gdb-7.6/bfd/config.bfd	2013-07-18 15:54:07.724777922 +0200
+@@ -221,7 +221,7 @@
+     targ_defvec=ecoffalpha_little_vec
+     want64=true
+     ;;
+-  ia64*-*-freebsd* | ia64*-*-netbsd* | ia64*-*-linux-* | ia64*-*-elf* | ia64*-*-kfreebsd*-gnu)
++  ia64*-*-freebsd* | ia64*-*-netbsd* | ia64*-*-linux-* | ia64*-*-elf* | ia64*-*-kfreebsd*-gnu | ia64*-*-helenos*)
+     targ_defvec=bfd_elf64_ia64_little_vec
+     targ_selvecs="bfd_elf64_ia64_big_vec bfd_pei_ia64_vec"
+     want64=true
+@@ -332,6 +332,7 @@
+     targ_selvecs=bfd_elf32_bigarm_vec
+     ;;
+   arm-*-elf | arm-*-freebsd* | arm*-*-linux-* | arm*-*-conix* | \
++  arm-helenos-* | \
+   arm*-*-uclinux* | arm-*-kfreebsd*-gnu | \
+   arm*-*-eabi* )
+     targ_defvec=bfd_elf32_littlearm_vec
+@@ -619,7 +620,7 @@
+     targ_selvecs=bfd_elf32_i386_vec
+     targ_underscore=yes
+     ;;
+-  i[3-7]86-*-linux-*)
++  i[3-7]86-*-linux-* | i[3-7]86-*-helenos*)
+     targ_defvec=bfd_elf32_i386_vec
+     targ_selvecs="i386linux_vec i386pei_vec"
+     targ64_selvecs="bfd_elf64_x86_64_vec bfd_elf32_x86_64_vec x86_64pei_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec"
+@@ -662,7 +663,7 @@
+     targ_selvecs="bfd_elf32_i386_vec i386netbsd_vec i386coff_vec i386pei_vec x86_64pei_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec"
+     want64=true
+     ;;
+-  x86_64-*-linux-*)
++  x86_64-*-linux-* | x86_64-*-helenos*)
+     targ_defvec=bfd_elf64_x86_64_vec
+     targ_selvecs="bfd_elf32_i386_vec bfd_elf32_x86_64_vec i386linux_vec i386pei_vec x86_64pei_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec"
+     want64=true
+@@ -1059,7 +1060,7 @@
+     targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec ecoff_big_vec ecoff_little_vec"
+     ;;
+ #ifdef BFD64
+-  mips64*el-*-linux*)
++  mips64*el-*-linux* | mips64el-*-helenos*)
+     targ_defvec=bfd_elf32_ntradlittlemips_vec
+     targ_selvecs="bfd_elf32_ntradbigmips_vec bfd_elf32_tradlittlemips_vec bfd_elf32_tradbigmips_vec bfd_elf64_tradlittlemips_vec bfd_elf64_tradbigmips_vec"
+     want64=true
+@@ -1069,12 +1070,12 @@
+     targ_selvecs="bfd_elf32_ntradlittlemips_vec bfd_elf32_tradbigmips_vec bfd_elf32_tradlittlemips_vec bfd_elf64_tradbigmips_vec bfd_elf64_tradlittlemips_vec"
+     want64=true
+     ;;
+-  mips*el-*-linux*)
++  mips*el-*-linux* | mipsel-*-helenos*)
+     targ_defvec=bfd_elf32_tradlittlemips_vec
+     targ_selvecs="bfd_elf32_tradbigmips_vec ecoff_little_vec ecoff_big_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradlittlemips_vec bfd_elf32_ntradbigmips_vec bfd_elf64_tradbigmips_vec"
+     want64=true
+     ;;
+-  mips*-*-linux*)
++  mips*-*-linux* | mips-*-helenos*)
+     targ_defvec=bfd_elf32_tradbigmips_vec
+     targ_selvecs="bfd_elf32_tradlittlemips_vec ecoff_big_vec ecoff_little_vec bfd_elf32_ntradbigmips_vec bfd_elf64_tradbigmips_vec bfd_elf32_ntradlittlemips_vec bfd_elf64_tradlittlemips_vec"
+     want64=true
+@@ -1237,6 +1238,7 @@
+     want64=true
+     ;;
+   powerpc64-*-elf* | powerpc-*-elf64* | powerpc64-*-linux* | \
++  powerpc64-*-helenos* | \
+   powerpc64-*-*bsd*)
+     targ_defvec=bfd_elf64_powerpc_vec
+     targ_selvecs="bfd_elf64_powerpcle_vec bfd_elf32_powerpc_vec bfd_elf32_powerpcle_vec rs6000coff_vec rs6000coff64_vec aix5coff64_vec"
+@@ -1255,6 +1257,7 @@
+     ;;
+   powerpc-*-*bsd* | powerpc-*-elf* | powerpc-*-sysv4* | powerpc-*-eabi* | \
+   powerpc-*-solaris2* | powerpc-*-linux-* | powerpc-*-rtems* | \
++  powerpc-*-helenos* | \
+   powerpc-*-chorus*)
+     targ_defvec=bfd_elf32_powerpc_vec
+     targ_selvecs="rs6000coff_vec bfd_elf32_powerpcle_vec ppcboot_vec"
+@@ -1553,7 +1556,7 @@
+     targ_underscore=yes
+     want64=true
+     ;;
+-  sparc64*-*-linux-*)
++  sparc64*-*-linux-* | sparc64-*-helenos*)
+     targ_defvec=bfd_elf64_sparc_vec
+     targ_selvecs="bfd_elf32_sparc_vec sparclinux_vec sunos_big_vec"
+     want64=true
+diff -rud gdb-7.6-original/config.sub gdb-7.6/config.sub
+--- gdb-7.6-original/config.sub	2013-01-11 13:57:41.000000000 +0100
++++ gdb-7.6/config.sub	2013-07-18 15:26:51.261356318 +0200
+@@ -1369,6 +1369,7 @@
+ 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ 	      | -chorusos* | -chorusrdb* | -cegcc* \
+ 	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
++	      | -helenos* \
+ 	      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+ 	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+ 	      | -uxpv* | -beos* | -mpeix* | -udk* \
+diff -rud gdb-7.6-original/gdb/configure.tgt gdb-7.6/gdb/configure.tgt
+--- gdb-7.6-original/gdb/configure.tgt	2013-03-05 14:37:10.000000000 +0100
++++ gdb-7.6/gdb/configure.tgt	2013-07-18 15:50:25.210529047 +0200
+@@ -85,7 +85,7 @@
+ 	gdb_target_obs="arm-tdep.o arm-wince-tdep.o"
+ 	build_gdbserver=yes
+ 	;;
+-arm*-*-linux*)
++arm*-*-linux* | arm*-*-helenos*)
+ 	# Target: ARM based machine running GNU/Linux
+ 	gdb_target_obs="arm-tdep.o arm-linux-tdep.o glibc-tdep.o \
+ 			solib-svr4.o symfile-mem.o linux-tdep.o"
+@@ -216,7 +216,7 @@
+ 	gdb_target_obs="i386-tdep.o i387-tdep.o i386-sol2-tdep.o sol2-tdep.o \
+ 			solib-svr4.o"
+ 	;;
+-i[34567]86-*-linux*)
++i[34567]86-*-linux* | i[34567]86-*-helenos*)
+ 	# Target: Intel 386 running GNU/Linux
+ 	gdb_target_obs="i386-tdep.o i386-linux-tdep.o glibc-tdep.o i387-tdep.o \
+ 			solib-svr4.o symfile-mem.o \
+@@ -252,7 +252,7 @@
+ 	# Target: Intel IA-64 running HP-UX
+ 	gdb_target_obs="ia64-tdep.o ia64-hpux-tdep.o"
+ 	;;
+-ia64-*-linux*)
++ia64-*-linux* | ia64-*-helenos*)
+ 	# Target: Intel IA-64 running GNU/Linux
+ 	gdb_target_obs="ia64-tdep.o ia64-linux-tdep.o linux-tdep.o \
+ 			solib-svr4.o symfile-mem.o"
+@@ -357,7 +357,7 @@
+ 	# Target: MIPS SGI running Irix 6.x
+ 	gdb_target_obs="mips-tdep.o mips-irix-tdep.o solib-irix.o"
+ 	;;
+-mips*-*-linux*)
++mips*-*-linux* | mips*-*-helenos*)
+ 	# Target: Linux/MIPS
+ 	gdb_target_obs="mips-tdep.o mips-linux-tdep.o glibc-tdep.o \
+ 			solib-svr4.o symfile-mem.o linux-tdep.o"
+@@ -421,7 +421,7 @@
+ 			ppc-sysv-tdep.o solib-svr4.o \
+ 			ravenscar-thread.o ppc-ravenscar-thread.o"
+ 	;;
+-powerpc-*-linux* | powerpc64-*-linux*)
++powerpc-*-linux* | powerpc64-*-linux* | powerpc*-*-helenos*)
+ 	# Target: PowerPC running Linux
+ 	gdb_target_obs="rs6000-tdep.o ppc-linux-tdep.o ppc-sysv-tdep.o \
+ 			ppc64-tdep.o solib-svr4.o solib-spu.o \
+@@ -515,7 +515,7 @@
+ 	fi
+ 	build_gdbserver=yes
+ 	;;
+-sparc64-*-linux*)
++sparc64-*-linux* | sparc641-*-helenos*)
+ 	# Target: GNU/Linux UltraSPARC
+ 	gdb_target_obs="sparc64-tdep.o sparc64-sol2-tdep.o sol2-tdep.o \
+ 			sparc64-linux-tdep.o sparc-tdep.o sparc-sol2-tdep.o \
+@@ -639,7 +639,7 @@
+ 	gdb_target_obs="amd64-tdep.o i386-tdep.o i387-tdep.o \
+ 			dicos-tdep.o i386-dicos-tdep.o amd64-dicos-tdep.o"
+ 	;;
+-x86_64-*-linux*)
++x86_64-*-linux* | x86_64-*-helenos*)
+ 	# Target: GNU/Linux x86-64
+ 	gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o i386-tdep.o \
+ 			i387-tdep.o i386-linux-tdep.o glibc-tdep.o \
+@@ -688,7 +688,7 @@
+ case "${targ}" in
+ *-*-freebsd* | *-*-kfreebsd*-gnu)
+ 		gdb_osabi=GDB_OSABI_FREEBSD_ELF ;;
+-*-*-linux* | *-*-uclinux*)
++*-*-linux* | *-*-uclinux* | *-*-helenos*)
+ 		gdb_osabi=GDB_OSABI_LINUX ;;
+ *-*-nto*)	gdb_osabi=GDB_OSABI_QNXNTO ;;
+ m68*-*-openbsd* | m88*-*-openbsd* | vax-*-openbsd*) ;;
Index: tools/toolchain.sh
===================================================================
--- tools/toolchain.sh	(revision d7f2cd639fbae683ae373adf9383d6c3e0ae69cc)
+++ tools/toolchain.sh	(revision 12d6c984367491a333f4e1724f2e966246811839)
@@ -55,6 +55,9 @@
 BINUTILS_VERSION="2.23.1"
 BINUTILS_RELEASE=""
+BINUTILS_PATCHES="toolchain-binutils-2.23.1.patch"
 GCC_VERSION="4.8.1"
+GCC_PATCHES="toolchain-gcc-4.8.1-targets.patch toolchain-gcc-4.8.1-headers.patch"
 GDB_VERSION="7.6.1"
+GDB_PATCHES="toolchain-gdb-7.6.patch"
 
 BASEDIR="`pwd`"
@@ -62,4 +65,8 @@
 GCC="gcc-${GCC_VERSION}.tar.bz2"
 GDB="gdb-${GDB_VERSION}.tar.bz2"
+
+REAL_INSTALL=true
+USE_HELENOS_TARGET=false
+INSTALL_DIR="${BASEDIR}/PKG"
 
 #
@@ -135,5 +142,5 @@
 	echo
 	echo "Syntax:"
-	echo " $0 <platform>"
+	echo " $0 [--no-install] [--helenos-target] <platform>"
 	echo
 	echo "Possible target platforms are:"
@@ -152,7 +159,19 @@
 	echo " 2-way      same as 'all', but 2-way parallel"
 	echo
-	echo "The toolchain will be installed to the directory specified by"
-	echo "the CROSS_PREFIX environment variable. If the variable is not"
-	echo "defined, /usr/local/cross will be used by default."
+	echo "The toolchain is installed into directory specified by the"
+	echo "CROSS_PREFIX environment variable. If the variable is not"
+	echo "defined, /usr/local/cross/ is used as default."
+	echo
+	echo "If --no-install is present, the toolchain still uses the"
+	echo "CROSS_PREFIX as the target directory but the installation"
+	echo "copies the files into PKG/ subdirectory without affecting"
+	echo "the actual root file system. That is only useful if you do"
+	echo "not want to run the script under the super user."
+	echo
+	echo "The --helenos-target will build HelenOS-specific toolchain"
+	echo "(i.e. it will use *-helenos-* triplet instead of *-linux-*)."
+	echo "This toolchain is installed into /usr/local/cross-helenos by"
+	echo "default. The settings can be changed by setting environment"
+	echo "variable CROSS_HELENOS_PREFIX."
 	echo
 	
@@ -292,4 +311,16 @@
 }
 
+patch_sources() {
+	PATCH_FILE="$1"
+	PATCH_STRIP="$2"
+	DESC="$3"
+	
+	change_title "Patching ${DESC}"
+	echo " >>> Patching ${DESC} with ${PATCH_FILE}"
+	
+	patch -t "-p${PATCH_STRIP}" <"$PATCH_FILE"
+	check_error $? "Error patching ${DESC}."
+}
+
 prepare() {
 	show_dependencies
@@ -306,7 +337,61 @@
 }
 
+set_target_from_platform() {
+	case "$1" in
+		"amd64")
+			LINUX_TARGET="amd64-linux-gnu"
+			HELENOS_TARGET="amd64-helenos"
+			;;
+		"arm32")
+			LINUX_TARGET="arm-linux-gnueabi"
+			HELENOS_TARGET="arm-helenos-gnueabi"
+			;;
+		"ia32")
+			LINUX_TARGET="i686-pc-linux-gnu"
+			HELENOS_TARGET="i686-pc-helenos"
+			;;
+		"ia64")
+			LINUX_TARGET="ia64-pc-linux-gnu"
+			HELENOS_TARGET="ia64-pc-helenos"
+			;;
+		"mips32")
+			LINUX_TARGET="mipsel-linux-gnu"
+			HELENOS_TARGET="mipsel-helenos"
+			;;
+		"mips32eb")
+			LINUX_TARGET="mips-linux-gnu"
+			HELENOS_TARGET="mips-helenos"
+			;;
+		"mips64")
+			LINUX_TARGET="mips64el-linux-gnu"
+			HELENOS_TARGET="mips64el-helenos"
+			;;
+		"ppc32")
+			LINUX_TARGET="ppc-linux-gnu"
+			HELENOS_TARGET="ppc-helenos"
+			;;
+		"ppc64")
+			LINUX_TARGET="ppc64-linux-gnu"
+			HELENOS_TARGET="ppc64-helenos"
+			;;
+		"sparc64")
+			LINUX_TARGET="sparc64-linux-gnu"
+			HELENOS_TARGET="sparc64-helenos"
+			;;
+		*)
+			check_error 1 "No target known for $1."
+			;;
+	esac
+}
+
 build_target() {
 	PLATFORM="$1"
-	TARGET="$2"
+	# This sets the *_TARGET variables
+	set_target_from_platform "$PLATFORM"
+	if $USE_HELENOS_TARGET; then
+		TARGET="$HELENOS_TARGET"
+	else
+		TARGET="$LINUX_TARGET"
+	fi
 	
 	WORKDIR="${BASEDIR}/${PLATFORM}"
@@ -319,6 +404,13 @@
 		CROSS_PREFIX="/usr/local/cross"
 	fi
-	
-	PREFIX="${CROSS_PREFIX}/${PLATFORM}"
+	if [ -z "${CROSS_HELENOS_PREFIX}" ] ; then
+		CROSS_HELENOS_PREFIX="/usr/local/cross-helenos"
+	fi
+	
+	if $USE_HELENOS_TARGET; then
+		PREFIX="${CROSS_HELENOS_PREFIX}/${PLATFORM}"
+	else
+		PREFIX="${CROSS_PREFIX}/${PLATFORM}"
+	fi
 	
 	echo ">>> Downloading tarballs"
@@ -328,8 +420,8 @@
 	
 	echo ">>> Removing previous content"
-	cleanup_dir "${PREFIX}"
+	$REAL_INSTALL && cleanup_dir "${PREFIX}"
 	cleanup_dir "${WORKDIR}"
 	
-	create_dir "${PREFIX}" "destination directory"
+	$REAL_INSTALL && create_dir "${PREFIX}" "destination directory"
 	create_dir "${OBJDIR}" "GCC object directory"
 	
@@ -344,4 +436,15 @@
 	unpack_tarball "${BASEDIR}/${GDB}" "GDB"
 	
+	echo ">>> Applying patches"
+	for p in $BINUTILS_PATCHES; do
+		patch_sources "${BASEDIR}/${p}" 0 "binutils"
+	done
+	for p in $GCC_PATCHES; do
+		patch_sources "${BASEDIR}/${p}" 0 "GCC"
+	done
+	for p in $GDB_PATCHES; do
+		patch_sources "${BASEDIR}/${p}" 0 "GDB"
+	done
+	
 	echo ">>> Processing binutils (${PLATFORM})"
 	cd "${BINUTILSDIR}"
@@ -349,10 +452,22 @@
 	
 	change_title "binutils: configure (${PLATFORM})"
-	CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
+	CFLAGS=-Wno-error ./configure \
+		"--target=${TARGET}" \
+		"--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
+		--disable-nls --disable-werror
 	check_error $? "Error configuring binutils."
 	
 	change_title "binutils: make (${PLATFORM})"
-	make all install
-	check_error $? "Error compiling/installing binutils."
+	make all
+	check_error $? "Error compiling binutils."
+	
+	change_title "binutils: install (${PLATFORM})"
+	if $REAL_INSTALL; then
+		make install
+	else
+		make install "DESTDIR=${INSTALL_DIR}"
+	fi
+	check_error $? "Error installing binutils."
+	
 	
 	echo ">>> Processing GCC (${PLATFORM})"
@@ -361,10 +476,25 @@
 	
 	change_title "GCC: configure (${PLATFORM})"
-	"${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --enable-languages=c,objc,c++,obj-c++ --disable-multilib --disable-libgcj --without-headers --disable-shared --enable-lto --disable-werror
+	PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${GCCDIR}/configure" \
+		"--target=${TARGET}" \
+		"--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
+		--with-gnu-as --with-gnu-ld --disable-nls --disable-threads \
+		--enable-languages=c,objc,c++,obj-c++ \
+		--disable-multilib --disable-libgcj --without-headers \
+		--disable-shared --enable-lto --disable-werror
 	check_error $? "Error configuring GCC."
 	
 	change_title "GCC: make (${PLATFORM})"
-	PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
-	check_error $? "Error compiling/installing GCC."
+	PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc
+	check_error $? "Error compiling GCC."
+	
+	change_title "GCC: install (${PLATFORM})"
+	if $REAL_INSTALL; then
+		PATH="${PATH}:${PREFIX}/bin" make install-gcc
+	else
+		PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
+	fi
+	check_error $? "Error installing GCC."
+	
 	
 	echo ">>> Processing GDB (${PLATFORM})"
@@ -373,10 +503,21 @@
 	
 	change_title "GDB: configure (${PLATFORM})"
-	./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
+	PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" ./configure \
+		"--target=${TARGET}" \
+		"--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
 	check_error $? "Error configuring GDB."
 	
 	change_title "GDB: make (${PLATFORM})"
-	make all install
-	check_error $? "Error compiling/installing GDB."
+	PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all
+	check_error $? "Error compiling GDB."
+	
+	change_title "GDB: make (${PLATFORM})"
+	if $REAL_INSTALL; then
+		PATH="${PATH}:${PREFIX}/bin" make install
+	else
+		PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
+	fi
+	check_error $? "Error installing GDB."
+	
 	
 	cd "${BASEDIR}"
@@ -389,4 +530,20 @@
 	echo ">>> Cross-compiler for ${TARGET} installed."
 }
+
+while [ "$#" -gt 1 ]; do
+	case "$1" in
+		--no-install)
+			REAL_INSTALL=false
+			shift
+			;;
+		--helenos-target)
+			USE_HELENOS_TARGET=true
+			shift
+			;;
+		*)
+			show_usage
+			;;
+	esac
+done
 
 if [ "$#" -lt "1" ]; then
@@ -395,91 +552,55 @@
 
 case "$1" in
-	"amd64")
+	amd64|arm32|ia32|ia64|mips32|mips32eb|mips64|ppc32|ppc64|sparc64)
 		prepare
-		build_target "amd64" "amd64-linux-gnu"
-		;;
-	"arm32")
-		prepare
-		build_target "arm32" "arm-linux-gnueabi"
-		;;
-	"ia32")
-		prepare
-		build_target "ia32" "i686-pc-linux-gnu"
-		;;
-	"ia64")
-		prepare
-		build_target "ia64" "ia64-pc-linux-gnu"
-		;;
-	"mips32")
-		prepare
-		build_target "mips32" "mipsel-linux-gnu"
-		;;
-	"mips32eb")
-		prepare
-		build_target "mips32eb" "mips-linux-gnu"
-		;;
-	"mips64")
-		prepare
-		build_target "mips64" "mips64el-linux-gnu"
-		;;
-	"ppc32")
-		prepare
-		build_target "ppc32" "ppc-linux-gnu"
-		;;
-	"ppc64")
-		prepare
-		build_target "ppc64" "ppc64-linux-gnu"
-		;;
-	"sparc64")
-		prepare
-		build_target "sparc64" "sparc64-linux-gnu"
+		build_target "$1"
 		;;
 	"all")
 		prepare
-		build_target "amd64" "amd64-linux-gnu"
-		build_target "arm32" "arm-linux-gnueabi"
-		build_target "ia32" "i686-pc-linux-gnu"
-		build_target "ia64" "ia64-pc-linux-gnu"
-		build_target "mips32" "mipsel-linux-gnu"
-		build_target "mips32eb" "mips-linux-gnu"
-		build_target "mips64" "mips64el-linux-gnu"
-		build_target "ppc32" "ppc-linux-gnu"
-		build_target "ppc64" "ppc64-linux-gnu"
-		build_target "sparc64" "sparc64-linux-gnu"
+		build_target "amd64"
+		build_target "arm32"
+		build_target "ia32"
+		build_target "ia64"
+		build_target "mips32"
+		build_target "mips32eb"
+		build_target "mips64"
+		build_target "ppc32"
+		build_target "ppc64"
+		build_target "sparc64"
 		;;
 	"parallel")
 		prepare
-		build_target "amd64" "amd64-linux-gnu" &
-		build_target "arm32" "arm-linux-gnueabi" &
-		build_target "ia32" "i686-pc-linux-gnu" &
-		build_target "ia64" "ia64-pc-linux-gnu" &
-		build_target "mips32" "mipsel-linux-gnu" &
-		build_target "mips32eb" "mips-linux-gnu" &
-		build_target "mips64" "mips64el-linux-gnu" &
-		build_target "ppc32" "ppc-linux-gnu" &
-		build_target "ppc64" "ppc64-linux-gnu" &
-		build_target "sparc64" "sparc64-linux-gnu" &
+		build_target "amd64" &
+		build_target "arm32" &
+		build_target "ia32" &
+		build_target "ia64" &
+		build_target "mips32" &
+		build_target "mips32eb" &
+		build_target "mips64" &
+		build_target "ppc32" &
+		build_target "ppc64" &
+		build_target "sparc64" &
 		wait
 		;;
 	"2-way")
 		prepare
-		build_target "amd64" "amd64-linux-gnu" &
-		build_target "arm32" "arm-linux-gnueabi" &
+		build_target "amd64" &
+		build_target "arm32" &
 		wait
 		
-		build_target "ia32" "i686-pc-linux-gnu" &
-		build_target "ia64" "ia64-pc-linux-gnu" &
+		build_target "ia32" &
+		build_target "ia64" &
 		wait
 		
-		build_target "mips32" "mipsel-linux-gnu" &
-		build_target "mips32eb" "mips-linux-gnu" &
+		build_target "mips32" &
+		build_target "mips32eb" &
 		wait
 		
-		build_target "mips64" "mips64el-linux-gnu" &
-		build_target "ppc32" "ppc-linux-gnu" &
+		build_target "mips64" &
+		build_target "ppc32" &
 		wait
 		
-		build_target "ppc64" "ppc64-linux-gnu" &
-		build_target "sparc64" "sparc64-linux-gnu" &
+		build_target "ppc64" &
+		build_target "sparc64" &
 		wait
 		;;
