Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision 4c5f04f66aa0d34ff3bbed6e9abebf85f59723fb)
+++ tools/autotool.py	(revision 2223ceb286f93d7d54168f4adebb3fbc5f998b5e)
@@ -185,9 +185,9 @@
 		if (config['CROSS_TARGET'] == "arm32"):
 			gnu_target = "arm-linux-gnueabi"
-			helenos_target = "arm-helenos-gnueabi"
+			helenos_target = "arm-helenos"
 
 		if (config['CROSS_TARGET'] == "ia32"):
 			gnu_target = "i686-pc-linux-gnu"
-			helenos_target = "i686-pc-helenos"
+			helenos_target = "i686-helenos"
 
 		if (config['CROSS_TARGET'] == "mips32"):
@@ -204,15 +204,15 @@
 		platform = config['PLATFORM']
 		gnu_target = "arm-linux-gnueabi"
-		helenos_target = "arm-helenos-gnueabi"
+		helenos_target = "arm-helenos"
 
 	if (config['PLATFORM'] == "ia32"):
 		platform = config['PLATFORM']
 		gnu_target = "i686-pc-linux-gnu"
-		helenos_target = "i686-pc-helenos"
+		helenos_target = "i686-helenos"
 
 	if (config['PLATFORM'] == "ia64"):
 		platform = config['PLATFORM']
 		gnu_target = "ia64-pc-linux-gnu"
-		helenos_target = "ia64-pc-helenos"
+		helenos_target = "ia64-helenos"
 
 	if (config['PLATFORM'] == "mips32"):
Index: tools/toolchain.sh
===================================================================
--- tools/toolchain.sh	(revision 4c5f04f66aa0d34ff3bbed6e9abebf85f59723fb)
+++ tools/toolchain.sh	(revision 2223ceb286f93d7d54168f4adebb3fbc5f998b5e)
@@ -29,14 +29,18 @@
 #
 
+BINUTILS_GDB_GIT="https://github.com/HelenOS/binutils-gdb.git"
+
+BINUTILS_BRANCH="binutils-2_30-helenos"
 BINUTILS_VERSION="2.30"
-BINUTILS_RELEASE=""
+
+GDB_BRANCH="gdb-8_1-helenos"
+GDB_VERSION="8.1"
+
+GCC_GIT="https://github.com/HelenOS/gcc.git"
+GCC_BRANCH="7_3_0-helenos"
 GCC_VERSION="7.3.0"
-GDB_VERSION="8.1"
 
 BASEDIR="`pwd`"
 SRCDIR="$(readlink -f $(dirname "$0"))"
-BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
-GCC="gcc-${GCC_VERSION}.tar.xz"
-GDB="gdb-${GDB_VERSION}.tar.gz"
 
 REAL_INSTALL=true
@@ -49,17 +53,4 @@
 
 		exit 1
-	fi
-}
-
-check_md5() {
-	FILE="$1"
-	SUM="$2"
-
-	COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
-	if [ "${SUM}" != "${COMPUTED}" ] ; then
-		echo
-		echo "Checksum of ${FILE} does not match."
-
-		exit 2
 	fi
 }
@@ -99,8 +90,5 @@
 	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 "(i.e. it will use *-helenos triplet instead of *-linux-*)."
 	echo "Using the HelenOS-specific toolchain is still an experimental"
 	echo "feature that is not fully supported."
@@ -148,31 +136,4 @@
 }
 
-download_fetch() {
-	SOURCE="$1"
-	FILE="$2"
-	CHECKSUM="$3"
-
-	if [ ! -f "${FILE}" ] ; then
-		change_title "Downloading ${FILE}"
-		wget -c "${SOURCE}${FILE}" -O "${FILE}".part
-		check_error $? "Error downloading ${FILE}."
-
-		mv "${FILE}".part "${FILE}"
-	fi
-
-	check_md5 "${FILE}" "${CHECKSUM}"
-}
-
-source_check() {
-	FILE="$1"
-
-	if [ ! -f "${FILE}" ] ; then
-		echo
-		echo "File ${FILE} not found."
-
-		exit 4
-	fi
-}
-
 cleanup_dir() {
 	DIR="$1"
@@ -226,28 +187,4 @@
 }
 
-unpack_tarball() {
-	FILE="$1"
-	DESC="$2"
-
-	change_title "Unpacking ${DESC}"
-	echo " >>> Unpacking ${DESC}"
-
-	case "${FILE}" in
-		*.gz)
-			tar -xzf "${FILE}"
-			;;
-		*.xz)
-			tar -xJf "${FILE}"
-			;;
-		*.bz2)
-			tar -xjf "${FILE}"
-			;;
-		*)
-			check_error 1 "Don't know how to unpack ${DESC}."
-			;;
-	esac
-	check_error $? "Error unpacking ${DESC}."
-}
-
 prepare() {
 	show_dependencies
@@ -258,21 +195,13 @@
 	check_error $? "Change directory failed."
 
-	BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
-	GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
-	GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
-
-	echo ">>> Downloading tarballs"
-
-	download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "cc47a2f256b4a593206b4d7e62a60b32"
-	download_fetch "${GCC_SOURCE}" "${GCC}" "be2da21680f27624f3a87055c4ba5af2"
-	download_fetch "${GDB_SOURCE}" "${GDB}" "0c85ecbb43569ec43b1c9230622e84ab"
-
-	echo ">>> Unpacking tarballs"
-	cd "${WORKDIR}"
-	check_error $? "Change directory failed."
-
-	unpack_tarball "${BASEDIR}/downloads/${BINUTILS}" "binutils"
-	unpack_tarball "${BASEDIR}/downloads/${GCC}" "GCC"
-	unpack_tarball "${BASEDIR}/downloads/${GDB}" "GDB"
+	echo ">>> Downloading sources"
+	git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION"
+	git clone --depth 1 -b "$GDB_BRANCH" "$BINUTILS_GDB_GIT" "gdb-$GDB_VERSION"
+	git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION"
+
+	# If the directory already existed, pull upstream changes.
+	git -C "binutils-$BINUTILS_VERSION" pull
+	git -C "gdb-$GDB_VERSION" pull
+	git -C "gcc-$GCC_VERSION" pull
 
 	echo ">>> Downloading GCC prerequisites"
@@ -284,50 +213,38 @@
 set_target_from_platform() {
 	case "$1" in
+		"arm32")
+			GNU_ARCH="arm"
+			;;
+		"ia32")
+			GNU_ARCH="i686"
+			;;
+		"mips32")
+			GNU_ARCH="mipsel"
+			;;
+		"mips32eb")
+			GNU_ARCH="mips"
+			;;
+		"mips64")
+			GNU_ARCH="mips64el"
+			;;
+		"ppc32")
+			GNU_ARCH="ppc"
+			;;
+		*)
+			GNU_ARCH="$1"
+			;;
+	esac
+
+	HELENOS_TARGET="${GNU_ARCH}-helenos"
+
+	case "$1" in
 		"amd64")
-			LINUX_TARGET="amd64-unknown-elf"
-			HELENOS_TARGET="amd64-helenos"
+			LINUX_TARGET="${GNU_ARCH}-unknown-elf"
 			;;
 		"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"
-			;;
-		"riscv64")
-			LINUX_TARGET="riscv64-unknown-linux-gnu"
-			HELENOS_TARGET="riscv64-helenos"
-			;;
-		"sparc64")
-			LINUX_TARGET="sparc64-linux-gnu"
-			HELENOS_TARGET="sparc64-helenos"
+			LINUX_TARGET="${GNU_ARCH}-linux-gnueabi"
 			;;
 		*)
-			check_error 1 "No target known for $1."
+			LINUX_TARGET="${GNU_ARCH}-linux-gnu"
 			;;
 	esac
@@ -355,4 +272,8 @@
 	fi
 
+	if [ -z "$JOBS" ] ; then
+		JOBS=`nproc`
+	fi
+
 	PREFIX="${CROSS_PREFIX}/${TARGET}"
 
@@ -362,4 +283,15 @@
 	check_dirs "${PREFIX}" "${WORKDIR}"
 
+	if $USE_HELENOS_TARGET ; then
+		echo ">>> Creating build sysroot"
+		mkdir -p "${WORKDIR}/sysroot/include"
+		mkdir "${WORKDIR}/sysroot/lib"
+		cp -r -L -t "${WORKDIR}/sysroot/include" \
+			${SRCDIR}/../abi/include/* \
+			${SRCDIR}/../uspace/lib/c/arch/${PLATFORM}/include/* \
+			${SRCDIR}/../uspace/lib/c/include/*
+		check_error $? "Failed to create build sysroot."
+	fi
+
 	echo ">>> Processing binutils (${PLATFORM})"
 	mkdir -p "${BINUTILSDIR}"
@@ -370,11 +302,16 @@
 	CFLAGS=-Wno-error "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \
 		"--target=${TARGET}" \
-		"--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
-		--disable-nls --disable-werror --enable-gold \
-		--enable-deterministic-archives
+		"--prefix=${PREFIX}" \
+		"--program-prefix=${TARGET}-" \
+		--disable-nls \
+		--disable-werror \
+		--enable-gold \
+		--enable-deterministic-archives \
+		--disable-gdb \
+		--with-sysroot
 	check_error $? "Error configuring binutils."
 
 	change_title "binutils: make (${PLATFORM})"
-	make all
+	make all -j$JOBS
 	check_error $? "Error compiling binutils."
 
@@ -389,20 +326,46 @@
 	check_error $? "Change directory failed."
 
+	if $USE_HELENOS_TARGET ; then
+		SYSROOT=--with-sysroot --with-build-sysroot="${WORKDIR}/sysroot"
+	else
+		SYSROOT=--without-headers
+	fi
+
 	change_title "GCC: configure (${PLATFORM})"
 	PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/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
+		"--prefix=${PREFIX}" \
+		"--program-prefix=${TARGET}-" \
+		--with-gnu-as \
+		--with-gnu-ld \
+		--disable-nls \
+		--enable-languages=c,objc,c++,obj-c++,go \
+		--enable-lto \
+		--disable-shared \
+		--disable-werror \
+		$SYSROOT
 	check_error $? "Error configuring GCC."
 
 	change_title "GCC: make (${PLATFORM})"
-	PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc
+	PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc -j$JOBS
 	check_error $? "Error compiling GCC."
+
+	if $USE_HELENOS_TARGET ; then
+		PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libgcc -j$JOBS
+		check_error $? "Error compiling libgcc."
+		# TODO: needs some extra care
+		#PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libatomic -j$JOBS
+		#check_error $? "Error compiling libatomic."
+		#PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libstdc++-v3 -j$JOBS
+		#check_error $? "Error compiling libstdc++."
+	fi
 
 	change_title "GCC: install (${PLATFORM})"
 	PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
+	if $USE_HELENOS_TARGET ; then
+		PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libgcc "DESTDIR=${INSTALL_DIR}"
+		#PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libatomic "DESTDIR=${INSTALL_DIR}"
+		#PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libstdc++-v3 "DESTDIR=${INSTALL_DIR}"
+	fi
 	check_error $? "Error installing GCC."
 
@@ -416,14 +379,15 @@
 	PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \
 		"--target=${TARGET}" \
-		"--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
-		--enable-werror=no --without-guile
+		"--prefix=${PREFIX}" \
+		"--program-prefix=${TARGET}-" \
+		--enable-werror=no
 	check_error $? "Error configuring GDB."
 
 	change_title "GDB: make (${PLATFORM})"
-	PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all
+	PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gdb -j$JOBS
 	check_error $? "Error compiling GDB."
 
 	change_title "GDB: make (${PLATFORM})"
-	PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
+	PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gdb "DESTDIR=${INSTALL_DIR}"
 	check_error $? "Error installing GDB."
 
