Index: tools/xcw/bin/helenos-bld-config
===================================================================
--- tools/xcw/bin/helenos-bld-config	(revision 5fd058627a2a82b1aeb8a700591a61bb67d8e212)
+++ 	(revision )
@@ -1,75 +1,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Jiri Svoboda
-# 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.
-#
-# Get build configration information
-# HelenOS Cross Compiler Wrapper (XCW)
-# Facilitate cross-compiling external software to HelenOS
-#
-
-SRC_ROOT="$(dirname "$0")/../../.."
-if [ -z "$EXPORT_DIR" ]; then
-	EXPORT_DIR="$SRC_ROOT/uspace/export"
-fi
-MAKEFILE_COMMON="$EXPORT_DIR"/Makefile.common
-MAKEFILE_CONFIG="$EXPORT_DIR"/Makefile.config
-CONFIG_MK="$EXPORT_DIR"/config.mk
-
-# Extract simple 'name = value' variable definition from Makefile
-function extract_field
-{
-	field_name="$1"
-	file_name="$2"
-
-	sed -n "s/^$field_name \\{0,1\\}= \\{0,1\\}\\(.*\\)$/\\1/p" "$file_name" | \
-	    sed "s/^\"//" | sed "s/\"$//"
-}
-
-case ".$1" in
-(.--cc) extract_field "CC" "$MAKEFILE_COMMON";;
-(.--ld) extract_field "LD" "$MAKEFILE_COMMON";;
-(.--uarch) extract_field "UARCH" "$MAKEFILE_CONFIG";;
-(.--endian)
-	UARCH=`extract_field "UARCH" "$MAKEFILE_CONFIG"`
-	ENDIAN=`extract_field "ENDIANESS" "$SRC_ROOT/uspace/lib/c/arch/$UARCH/Makefile.common"`
-	echo "__${ENDIAN}__"
-	;;
-*.--cflags) extract_field "HELENOS_CFLAGS" "$CONFIG_MK";;
-*.--ldflags) extract_field "HELENOS_LDFLAGS" "$CONFIG_MK";;
-*.--install-dir) echo "$(realpath "$SRC_ROOT/uspace/overlay")";;
-(*)
-	echo "Unknown option $1" >&2
-	echo "Usage: helenos-bld-config <option>" >&2
-	echo "        --cc" >&2
-	echo "        --ld" >&2
-	echo "        --uarch" >&2
-	echo "        --endian" >&2
-	echo "        --cflags" >&2
-	echo "        --ldflags" >&2
-	echo "        --install-dir" >&2
-	exit 1;;
-esac
Index: tools/xcw/bin/helenos-cc
===================================================================
--- tools/xcw/bin/helenos-cc	(revision 5fd058627a2a82b1aeb8a700591a61bb67d8e212)
+++ tools/xcw/bin/helenos-cc	(revision ecf56f8012dce1cff83b7c7cd0cdab2b6e1d082f)
@@ -32,24 +32,59 @@
 #
 
+
+
 XCW="$(dirname "$0")"
 SRC_ROOT="$XCW/../../.."
 if [ -z "$EXPORT_DIR" ]; then
-	EXPORT_DIR="$SRC_ROOT/uspace/export"
+	EXPORT_DIR="$SRC_ROOT/dist"
 fi
-UARCH="$("$XCW"/helenos-bld-config --uarch)"
-CC="$("$XCW"/helenos-bld-config --cc)"
-CFLAGS="$("$XCW"/helenos-bld-config --cflags)"
-ENDIAN="$("$XCW"/helenos-bld-config --endian)"
 
-echo helenos-cc "$@"
-"$CC" \
-    -O3 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32LE -finput-charset=UTF-8 \
-    $CFLAGS \
-    -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
-    -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings -ggdb \
-    -fno-omit-frame-pointer \
-    -D "$ENDIAN" \
-    "$@" \
-    -I"$XCW"/../include \
-    -I"$EXPORT_DIR"/include/libc \
-    -I"$EXPORT_DIR"/include
+HELENOS_EXPORT_ROOT="$EXPORT_DIR"
+
+source "${EXPORT_DIR}/config/config.sh"
+
+# CC is a compilation driver, so we should check which stage of compilation
+# is actually running and select which flags to provide. This makes no
+# difference for GCC, but e.g. clang warns when a flag is provided that is
+# unused
+
+needs_cflags=true
+needs_ldflags=true
+
+for flag in "$@"; do
+	case "$flag" in
+		-E)
+			needs_cflags=false
+			needs_ldflags=false
+			break
+			;;
+		-c|-S)
+			needs_ldflags=false
+			break
+			;;
+	esac
+done
+
+flags="-fwide-exec-charset=UTF-32LE -finput-charset=UTF-8 -fexec-charset=UTF-8"
+flags="$flags -isystem ${HELENOS_EXPORT_ROOT}/include/libc -idirafter ${HELENOS_EXPORT_ROOT}/include"
+
+if $needs_cflags; then
+	flags="$flags -O3 \
+	    -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
+	    -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings -ggdb"
+
+	flags="$flags $HELENOS_CFLAGS"
+fi
+
+if $needs_ldflags; then
+	flags="$flags $HELENOS_LDFLAGS"
+fi
+
+flags="$flags $@"
+
+if $needs_ldflags; then
+	flags="$flags $HELENOS_LDLIBS"
+fi
+
+echo "helenos-cc" "$@"
+PATH="$HELENOS_CROSS_PATH:$PATH" "${HELENOS_TARGET}-gcc" $flags
Index: tools/xcw/bin/helenos-ld
===================================================================
--- tools/xcw/bin/helenos-ld	(revision 5fd058627a2a82b1aeb8a700591a61bb67d8e212)
+++ 	(revision )
@@ -1,52 +1,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Jiri Svoboda
-# 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.
-#
-# Link editor (ld) wrapper
-# HelenOS Cross Compiler Wrapper (XCW)
-# Facilitate cross-compiling external software to HelenOS
-#
-
-XCW="$(dirname "$0")"
-SRC_ROOT="$XCW/../../.."
-if [ -z "$EXPORT_DIR" ]; then
-	EXPORT_DIR="$SRC_ROOT/uspace/export"
-fi
-UARCH="$("$XCW"/helenos-bld-config --uarch)"
-CFLAGS="$("$XCW"/helenos-bld-config --cflags)"
-LDFLAGS="$("$XCW"/helenos-bld-config --ldflags)"
-CC="$("$XCW"/helenos-bld-config --cc)"
-
-echo helenos-ld "$@"
-"$CC" \
-    $CFLAGS \
-    -Wl,--whole-archive \
-    "$EXPORT_DIR"/lib/libstartfiles.a \
-    -Wl,--no-whole-archive \
-    "$@" \
-    "$EXPORT_DIR"/lib/libc.a \
-    -lgcc
Index: tools/xcw/bin/helenos-pkg-config
===================================================================
--- tools/xcw/bin/helenos-pkg-config	(revision 5fd058627a2a82b1aeb8a700591a61bb67d8e212)
+++ tools/xcw/bin/helenos-pkg-config	(revision ecf56f8012dce1cff83b7c7cd0cdab2b6e1d082f)
@@ -34,7 +34,6 @@
 XCW="$(dirname "$0")"
 SRC_ROOT="$XCW/../../.."
-UARCH="$("$XCW"/helenos-bld-config --uarch)"
 if [ -z "$EXPORT_DIR" ]; then
-	EXPORT_DIR="$SRC_ROOT/uspace/export"
+	EXPORT_DIR="$SRC_ROOT/dist"
 fi
 INCLUDE_DIR="$EXPORT_DIR/include"
Index: tools/xcw/demo/Makefile
===================================================================
--- tools/xcw/demo/Makefile	(revision 5fd058627a2a82b1aeb8a700591a61bb67d8e212)
+++ tools/xcw/demo/Makefile	(revision ecf56f8012dce1cff83b7c7cd0cdab2b6e1d082f)
@@ -57,5 +57,5 @@
 
 $(output): $(objects)
-	$(LD) -o $@ $^ $(LIBS)
+	$(CC) -o $@ $^ $(LIBS)
 
 %.o: %.c
Index: tools/xcw/include/helenos
===================================================================
--- tools/xcw/include/helenos	(revision 5fd058627a2a82b1aeb8a700591a61bb67d8e212)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../uspace/lib/c/include
