[backfire] scripts, toolchain: backport external toolchain integration and spec patch...
authorjow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Sat, 28 Jan 2012 00:09:11 +0000 (00:09 +0000)
committerjow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Sat, 28 Jan 2012 00:09:11 +0000 (00:09 +0000)
git-svn-id: svn://svn.openwrt.org/openwrt/branches/backfire@29925 3c298f89-4303-0410-b956-a3cf2f4a3e73

scripts/ext-toolchain.sh [new file with mode: 0755]
scripts/patch-specs.sh [new file with mode: 0755]
toolchain/Makefile
toolchain/gcc/Makefile
toolchain/wrapper/Makefile [new file with mode: 0644]

diff --git a/scripts/ext-toolchain.sh b/scripts/ext-toolchain.sh
new file mode 100755 (executable)
index 0000000..257e0d8
--- /dev/null
@@ -0,0 +1,540 @@
+#!/usr/bin/env bash
+#
+#   Script for various external toolchain tasks, refer to
+#   the --help output for more information.
+#
+#   Copyright (C) 2012 Jo-Philipp Wich <jow@openwrt.org>
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+CC=""
+CXX=""
+CPP=""
+
+CFLAGS=""
+TOOLCHAIN="."
+
+LIBC_TYPE=""
+
+
+# Library specs
+LIB_SPECS="
+       c:        ld-* lib{anl,c,cidn,crypt,dl,m,nsl,nss_dns,nss_files,resolv,util}
+       rt:       librt-* librt
+       pthread:  libpthread-* libpthread
+       stdcpp:   libstdc++
+       gcc:      libgcc_s
+       ssp:      libssp
+       gfortran: libgfortran
+"
+
+# Binary specs
+BIN_SPECS="
+       ldd:       ldd
+       ldconfig:  ldconfig
+       gdb:       gdb
+       gdbserver: gdbserver
+"
+
+
+test_c() {
+       cat <<-EOT | "${CC:-false}" $CFLAGS -o /dev/null -x c - 2>/dev/null
+               #include <stdio.h>
+
+               int main(int argc, char **argv)
+               {
+                       printf("Hello, world!\n");
+                       return 0;
+               }
+       EOT
+}
+
+test_cxx() {
+       cat <<-EOT | "${CXX:-false}" $CFLAGS -o /dev/null -x c++ - 2>/dev/null
+               #include <iostream>
+
+               using namespace std;
+
+               int main()
+               {
+                       cout << "Hello, world!" << endl;
+                       return 0;
+               }
+       EOT
+}
+
+test_softfloat() {
+       cat <<-EOT | "$CC" $CFLAGS -msoft-float -o /dev/null -x c - 2>/dev/null
+               int main(int argc, char **argv)
+               {
+                       double a = 0.1;
+                       double b = 0.2;
+                       double c = (a + b) / (a * b);
+                       return 1;
+               }
+       EOT
+}
+
+test_uclibc() {
+       local sysroot="$("$CC" $CFLAGS -print-sysroot 2>/dev/null)"
+       if [ -d "${sysroot:-$TOOLCHAIN}" ]; then
+               local lib
+               for lib in "${sysroot:-$TOOLCHAIN}"/{lib,usr/lib,usr/local/lib}/ld-uClibc*.so*; do
+                       if [ -f "$lib" ] && [ ! -h "$lib" ]; then
+                               return 0
+                       fi
+               done
+       fi
+       return 1
+}
+
+test_feature() {
+       local feature="$1"; shift
+
+       # find compilers, libc type
+       probe_cc
+       probe_cxx
+       probe_libc
+
+       # common toolchain feature tests
+       case "$feature" in
+               c)     test_c;         return $? ;;
+               c++)   test_cxx;       return $? ;;
+               soft*) test_softfloat; return $? ;;
+       esac
+
+       # assume eglibc/glibc supports all libc features
+       if [ "$LIBC_TYPE" != "uclibc" ]; then
+               return 0
+       fi
+
+       # uclibc feature tests
+       local inc
+       local sysroot="$("$CC" "$@" -muclibc -print-sysroot 2>/dev/null)"
+       for inc in "include" "usr/include" "usr/local/include"; do
+               local conf="${sysroot:-$TOOLCHAIN}/$inc/bits/uClibc_config.h"
+               if [ -f "$conf" ]; then
+                       case "$feature" in
+                               lfs)     grep -q '__UCLIBC_HAS_LFS__ 1'     "$conf"; return $?;;
+                               ipv6)    grep -q '__UCLIBC_HAS_IPV6__ 1'    "$conf"; return $?;;
+                               rpc)     grep -q '__UCLIBC_HAS_RPC__ 1'     "$conf"; return $?;;
+                               locale)  grep -q '__UCLIBC_HAS_LOCALE__ 1'  "$conf"; return $?;;
+                               wchar)   grep -q '__UCLIBC_HAS_WCHAR__ 1'   "$conf"; return $?;;
+                               threads) grep -q '__UCLIBC_HAS_THREADS__ 1' "$conf"; return $?;;
+                       esac
+               fi
+       done
+
+       return 1
+}
+
+
+find_libs() {
+       local spec="$(echo "$LIB_SPECS" | sed -ne "s#^[[:space:]]*$1:##ip")"
+
+       if [ -n "$spec" ] && probe_cpp; then
+               local libdir libdirs
+               for libdir in $(
+                       "$CPP" $CFLAGS -v -x c /dev/null 2>&1 | \
+                               sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'
+               ); do
+                       if [ -d "$libdir" ]; then
+                               libdirs="$libdirs $(cd "$libdir"; pwd)/"
+                       fi
+               done
+
+               local pattern
+               for pattern in $(eval echo $spec); do
+                       find $libdirs -name "$pattern.so*" | sort -u
+               done
+
+               return 0
+       fi
+
+       return 1
+}
+
+find_bins() {
+       local spec="$(echo "$BIN_SPECS" | sed -ne "s#^[[:space:]]*$1:##ip")"
+
+       if [ -n "$spec" ] && probe_cpp; then
+               local sysroot="$("$CPP" -print-sysroot)"
+
+               local bindir bindirs
+               for bindir in $(
+                       echo "${sysroot:-$TOOLCHAIN}/bin";
+                       echo "${sysroot:-$TOOLCHAIN}/usr/bin";
+                       echo "${sysroot:-$TOOLCHAIN}/usr/local/bin";
+                       "$CPP" $CFLAGS -v -x c /dev/null 2>&1 | \
+                               sed -ne 's#:# #g; s#^COMPILER_PATH=##p'
+               ); do
+                       if [ -d "$bindir" ]; then
+                               bindirs="$bindirs $(cd "$bindir"; pwd)/"
+                       fi
+               done
+
+               local pattern
+               for pattern in $(eval echo $spec); do
+                       find $bindirs -name "$pattern" | sort -u
+               done
+
+               return 0
+       fi
+
+       return 1
+}
+
+
+wrap_bins() {
+       if probe_cc; then
+               mkdir -p "$1" || return 1
+
+               local cmd
+               for cmd in "${CC%-*}-"*; do
+                       if [ -x "$cmd" ]; then
+                               local out="$1/${cmd##*/}"
+
+                               echo '#!/bin/sh' > "$out"
+                               case "${cmd##*/}" in
+                                       *-*cc|*-*cc-*|*-*++|*-*++-*|*-cpp)
+                                               echo -n 'exec "'"$cmd"'" '"$CFLAGS"' '         >> "$out"
+                                               echo -n '${STAGING_DIR:+-idirafter '           >> "$out"
+                                               echo -n '"$STAGING_DIR/usr/include" '          >> "$out"
+                                               echo -n '-L "$STAGING_DIR/usr/lib" '           >> "$out"
+                                               echo -n '-Wl,-rpath-link,'                     >> "$out"
+                                               echo    '"$STAGING_DIR/usr/lib"} "$@"'         >> "$out"
+                                       ;;
+                                       *-ld)
+                                               echo -n 'exec "'"$cmd"'" ${STAGING_DIR:+'      >> "$out"
+                                               echo -n '-L "$STAGING_DIR/usr/lib" '           >> "$out"
+                                               echo -n '-rpath-link '                         >> "$out"
+                                               echo    '"$STAGING_DIR/usr/lib"} "$@"'         >> "$out"
+                                       ;;
+                                       *)
+                                               echo "exec '$cmd' \"\$@\"" >> "$out"
+                                       ;;
+                               esac
+                               chmod +x "$out"
+                       fi
+               done
+
+               return 0
+       fi
+
+       return 1
+}
+
+
+print_config() {
+       local mktarget="$1"
+       local mksubtarget
+
+       local target="$("$CC" $CFLAGS -dumpmachine)"
+       local cpuarch="${target%%-*}"
+       local prefix="${CC##*/}"; prefix="${prefix%-*}-"
+       local config="${0%/scripts/*}/.config"
+
+       # if no target specified, print choice list and exit
+       if [ -z "$mktarget" ]; then
+               # prepare metadata
+               if [ ! -f "${0%/scripts/*}/tmp/.targetinfo" ]; then
+                       "${0%/*}/scripts/config/mconf" prepare-tmpinfo
+               fi
+
+               local mktargets=$(
+                       sed -ne "
+                               /^Target: / { h };
+                               /^Target-Arch: $cpuarch\$/ { x; s#^Target: ##p }
+                       " "${0%/scripts/*}/tmp/.targetinfo" | sort -u
+               )
+
+               for mktarget in $mktargets; do
+                       case "$mktarget" in */*)
+                               mktargets=$(echo "$mktargets" | sed -e "/^${mktarget%/*}\$/d")
+                       esac
+               done
+
+               if [ -n "$mktargets" ]; then
+                       echo "Available targets:"                               >&2
+                       echo $mktargets                                         >&2
+               else
+                       echo -e "Could not find a suitable OpenWrt target for " >&2
+                       echo -e "CPU architecture '$cpuarch' - you need to "    >&2
+                       echo -e "define one first!"                             >&2
+               fi
+               return 1
+       fi
+
+       # bail out if there is a .config already
+       if [ -f "${0%/scripts/*}/.config" ]; then
+               echo "There already is a .config file, refusing to overwrite!" >&2
+               return 1
+       fi
+
+       case "$mktarget" in */*)
+               mksubtarget="${mktarget#*/}"
+               mktarget="${mktarget%/*}"
+       ;; esac
+
+
+       echo "CONFIG_TARGET_${mktarget}=y" > "$config"
+
+       if [ -n "$mksubtarget" ]; then
+               echo "CONFIG_TARGET_${mktarget}_${mksubtarget}=y" >> "$config"
+       fi
+
+       if test_feature "softfloat"; then
+               echo "CONFIG_SOFT_FLOAT=y" >> "$config"
+       else
+               echo "# CONFIG_SOFT_FLOAT is not set" >> "$config"
+       fi
+
+       if test_feature "ipv6"; then
+               echo "CONFIG_IPV6=y" >> "$config"
+       else
+               echo "# CONFIG_IPV6 is not set" >> "$config"
+       fi
+
+       if test_feature "locale"; then
+               echo "CONFIG_BUILD_NLS=y" >> "$config"
+       else
+               echo "# CONFIG_BUILD_NLS is not set" >> "$config"
+       fi
+
+       echo "CONFIG_DEVEL=y" >> "$config"
+       echo "CONFIG_EXTERNAL_TOOLCHAIN=y" >> "$config"
+       echo "CONFIG_TOOLCHAIN_ROOT=\"$TOOLCHAIN\"" >> "$config"
+       echo "CONFIG_TOOLCHAIN_PREFIX=\"$prefix\"" >> "$config"
+       echo "CONFIG_TARGET_NAME=\"$target\"" >> "$config"
+
+       local lib
+       for lib in C RT PTHREAD GCC STDCPP SSP GFORTRAN; do
+               local file
+               local spec=""
+               local llib="$(echo "$lib" | sed -e 's#.*#\L&#')"
+               for file in $(find_libs "$lib"); do
+                       spec="${spec:+$spec }$(echo "$file" | sed -e "s#^$TOOLCHAIN#.#")"
+               done
+               if [ -n "$spec" ]; then
+                       echo "CONFIG_PACKAGE_lib${llib}=y" >> "$config"
+                       echo "CONFIG_LIB${lib}_FILE_SPEC=\"$spec\"" >> "$config"
+               else
+                       echo "# CONFIG_PACKAGE_lib${llib} is not set" >> "$config"
+               fi
+       done
+
+       local bin
+       for bin in LDD LDCONFIG; do
+               local file
+               local spec=""
+               local lbin="$(echo "$bin" | sed -e 's#.*#\L&#')"
+               for file in $(find_bins "$bin"); do
+                       spec="${spec:+$spec }$(echo "$file" | sed -e "s#^$TOOLCHAIN#.#")"
+               done
+               if [ -n "$spec" ]; then
+                       echo "CONFIG_PACKAGE_${lbin}=y" >> "$config"
+                       echo "CONFIG_${bin}_FILE_SPEC=\"$spec\"" >> "$config"
+               else
+                       echo "# CONFIG_PACKAGE_${lbin} is not set" >> "$config"
+               fi
+       done
+
+       # inflate
+       make -C "${0%/scripts/*}" defconfig
+       return 0
+}
+
+
+probe_cc() {
+       if [ -z "$CC" ]; then
+               local bin
+               for bin in "bin" "usr/bin" "usr/local/bin"; do
+                       local cmd
+                       for cmd in "$TOOLCHAIN/$bin/"*-*cc*; do
+                               if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
+                                       CC="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
+                                       return 0
+                               fi
+                       done
+               done
+               return 1
+       fi
+       return 0
+}
+
+probe_cxx() {
+       if [ -z "$CXX" ]; then
+               local bin
+               for bin in "bin" "usr/bin" "usr/local/bin"; do
+                       local cmd
+                       for cmd in "$TOOLCHAIN/$bin/"*-*++*; do
+                               if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
+                                       CXX="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
+                                       return 0
+                               fi
+                       done
+               done
+               return 1
+       fi
+       return 0
+}
+
+probe_cpp() {
+       if [ -z "$CPP" ]; then
+               local bin
+               for bin in "bin" "usr/bin" "usr/local/bin"; do
+                       local cmd
+                       for cmd in "$TOOLCHAIN/$bin/"*-cpp*; do
+                               if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
+                                       CPP="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
+                                       return 0
+                               fi
+                       done
+               done
+               return 1
+       fi
+       return 0
+}
+
+probe_libc() {
+       if [ -z "$LIBC_TYPE" ]; then
+               if test_uclibc; then
+                       LIBC_TYPE="uclibc"
+               else
+                       LIBC_TYPE="glibc"
+               fi
+       fi
+       return 0
+}
+
+
+while [ -n "$1" ]; do
+       arg="$1"; shift
+       case "$arg" in
+               --toolchain)
+                       [ -d "$1" ] || {
+                               echo "Toolchain directory '$1' does not exist." >&2
+                               exit 1
+                       }
+                       TOOLCHAIN="$(cd "$1"; pwd)"; shift
+               ;;
+
+               --cflags)
+                       CFLAGS="${CFLAGS:+$CFLAGS }$1"; shift
+               ;;
+
+               --print-libc)
+                       if probe_cc; then
+                               probe_libc
+                               echo "$LIBC_TYPE"
+                               exit 0
+                       fi
+                       echo "No C compiler found in '$TOOLCHAIN'." >&2
+                       exit 1
+               ;;
+
+               --print-target)
+                       if probe_cc; then
+                               exec "$CC" $CFLAGS -dumpmachine
+                       fi
+                       echo "No C compiler found in '$TOOLCHAIN'." >&2
+                       exit 1
+               ;;
+
+               --print-bin)
+                       if [ -z "$1" ]; then
+                               echo "Available programs:"                      >&2
+                               echo $(echo "$BIN_SPECS" | sed -ne 's#:.*$##p') >&2
+                               exit 1
+                       fi
+
+                       find_bins "$1" || exec "$0" --toolchain "$TOOLCHAIN" --print-bin
+                       exit 0
+               ;;
+
+               --print-libs)
+                       if [ -z "$1" ]; then
+                               echo "Available libraries:"                     >&2
+                               echo $(echo "$LIB_SPECS" | sed -ne 's#:.*$##p') >&2
+                               exit 1
+                       fi
+
+                       find_libs "$1" || exec "$0" --toolchain "$TOOLCHAIN" --print-libs
+                       exit 0
+               ;;
+
+               --test)
+                       test_feature "$1"
+                       exit $?
+               ;;
+
+               --wrap)
+                       [ -n "$1" ] || exec "$0" --help
+                       wrap_bins "$1"
+                       exit $?
+               ;;
+
+               --config)
+                       if probe_cc; then
+                               print_config "$1"
+                               exit $?
+                       fi
+                       echo "No C compiler found in '$TOOLCHAIN'." >&2
+                       exit 1
+               ;;
+
+               -h|--help)
+                       me="$(basename "$0")"
+                       echo -e "\nUsage:\n"                                            >&2
+                       echo -e "  $me --toolchain {directory} --print-libc"            >&2
+                       echo -e "    Print the libc implementation and exit.\n"         >&2
+                       echo -e "  $me --toolchain {directory} --print-target"          >&2
+                       echo -e "    Print the GNU target name and exit.\n"             >&2
+                       echo -e "  $me --toolchain {directory} --print-bin {program}"   >&2
+                       echo -e "    Print executables belonging to given program,"     >&2
+                       echo -e "    omit program argument to get a list of names.\n"   >&2
+                       echo -e "  $me --toolchain {directory} --print-libs {library}"  >&2
+                       echo -e "    Print shared objects belonging to given library,"  >&2
+                       echo -e "    omit library argument to get a list of names.\n"   >&2
+                       echo -e "  $me --toolchain {directory} --test {feature}"        >&2
+                       echo -e "    Test given feature, exit code indicates success."  >&2
+                       echo -e "    Possible features are 'c', 'c++', 'softfloat',"    >&2
+                       echo -e "    'lfs', 'rpc', 'ipv6', 'wchar', 'locale' and "      >&2
+                       echo -e "    'threads'.\n"                                      >&2
+                       echo -e "  $me --toolchain {directory} --wrap {directory}"      >&2
+                       echo -e "    Create wrapper scripts for C and C++ compiler, "   >&2
+                       echo -e "    linker, assembler and other key executables in "   >&2
+                       echo -e "    the directory given with --wrap.\n"                >&2
+                       echo -e "  $me --toolchain {directory} --config {target}"       >&2
+                       echo -e "    Analyze the given toolchain and print a suitable"  >&2
+                       echo -e "    .config for the given target. Omit target "        >&2
+                       echo -e "    argument to get a list of names.\n"                >&2
+                       echo -e "  $me --help"                                          >&2
+                       echo -e "    Display this help text and exit.\n\n"              >&2
+                       echo -e "  Most commands also take a --cflags parameter which " >&2
+                       echo -e "  is used to specify C flags to be passed to the "     >&2
+                       echo -e "  cross compiler when performing tests."               >&2
+                       echo -e "  This paremter may be repeated multiple times."       >&2
+                       exit 1
+               ;;
+
+               *)
+                       echo "Unknown argument '$arg'" >&2
+                       exec $0 --help
+               ;;
+       esac
+done
+
+exec $0 --help
diff --git a/scripts/patch-specs.sh b/scripts/patch-specs.sh
new file mode 100755 (executable)
index 0000000..4d02a00
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+DIR="$1"
+FOUND=0
+
+if [ -d "$DIR" ]; then
+       DIR="$(cd "$DIR"; pwd)"
+else
+       echo "Usage: $0 toolchain-dir"
+       exit 1
+fi
+
+echo -n "Locating cpp ... "
+for bin in bin usr/bin usr/local/bin; do
+       for cmd in "$DIR/$bin/"*-cpp; do
+               if [ -x "$cmd" ]; then
+                       echo "$cmd"
+                       CPP="$cmd"
+                       break
+               fi
+       done
+done
+
+if [ ! -x "$CPP" ]; then
+       echo "Can't locate a cpp executable in '$DIR' !"
+       exit 1
+fi
+
+for lib in $(STAGING_DIR="$dir" "$CPP" -x c -v /dev/null 2>&1 | sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'); do
+       if [ -d "$lib" ]; then
+               grep -qs "STAGING_DIR" "$lib/specs" && rm -f "$lib/specs"
+               if [ $FOUND -lt 1 ]; then
+                       echo -n "Patching specs ... "
+                       STAGING_DIR="$dir" "$CPP" -dumpspecs | awk '
+                               mode ~ "link" {
+                                       sub("%{L.}", "%{L*} -L %:getenv(STAGING_DIR /usr/lib) -rpath-link %:getenv(STAGING_DIR /usr/lib)")
+                               }
+                               mode ~ "cpp" {
+                                       $0 = $0 " -idirafter %:getenv(STAGING_DIR /usr/include)"
+                               }
+                               {
+                                       print $0
+                                       mode = ""
+                               }
+                               /^\*cpp:/ {
+                                       mode = "cpp"
+                               }
+                               /^\*link.*:/ {
+                                       mode = "link"
+                               }
+                       ' > "$lib/specs"
+                       echo "ok"
+                       FOUND=1
+               fi
+       fi
+done
+
+if [ $FOUND -lt 1 ]; then
+       echo "Failed to locate library directory!"
+       exit 1
+else
+       echo "Toolchain successfully patched."
+       exit 0
+fi
index 161b139..d9d0496 100644 (file)
@@ -28,7 +28,7 @@
 curdir:=toolchain
 
 # subdirectories to descend into
-$(curdir)/builddirs := $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_INSIGHT),insight) $(if $(CONFIG_EXTERNAL_TOOLCHAIN),,kernel-headers binutils gcc $(LIBC) $(if $(CONFIG_GLIBC_PORTS),glibc-ports))
+$(curdir)/builddirs := $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_INSIGHT),insight) $(if $(CONFIG_EXTERNAL_TOOLCHAIN),wrapper,kernel-headers binutils gcc $(LIBC) $(if $(CONFIG_GLIBC_PORTS),glibc-ports))
 $(curdir)/builddirs-compile:=$($(curdir)/builddirs-prepare)
 $(curdir)/builddirs-install:=$($(curdir)/builddirs-compile)
 
index bd43738..315a55d 100644 (file)
@@ -251,6 +251,7 @@ define Stage2/Install
                done; \
        );
        $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
+       $(SCRIPT_DIR)/patch-specs.sh "$(TOOLCHAIN_DIR)"
 endef
 
 
diff --git a/toolchain/wrapper/Makefile b/toolchain/wrapper/Makefile
new file mode 100644 (file)
index 0000000..417ed8c
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=wrapper
+PKG_VERSION:=1
+
+include $(INCLUDE_DIR)/toolchain-build.mk
+
+
+# 1: args
+define toolchain_util
+$(strip $(SCRIPT_DIR)/ext-toolchain.sh --toolchain $(CONFIG_TOOLCHAIN_ROOT) \
+       --cflags $(CONFIG_TARGET_OPTIMIZATION) \
+       --cflags "-muclibc $(if $(CONFIG_SOFT_FLOAT),-msoft-float)" \
+       --cflags "$(patsubst ./%,-I$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH)))" \
+       --cflags "$(patsubst ./%,-L$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH)))" \
+       $(1))
+endef
+
+# 1: config symbol
+# 2: feature
+define toolchain_test
+$$(if $$($(1)), \
+       @echo -n "Testing external toolchain for $(2) support ... "; \
+       if $(call toolchain_util,--test "$(2)"); then \
+               echo "ok"; exit 0; \
+       else \
+               echo "failed"; \
+               echo "ERROR: $(1) is enabled but the external toolchain does not support it"; \
+               exit 1; \
+       fi)
+endef
+
+
+define Host/Prepare
+       $(call toolchain_test,CONFIG_SOFT_FLOAT,softfloat)
+       $(call toolchain_test,CONFIG_IPV6,ipv6)
+       $(call toolchain_test,CONFIG_NLS,wchar)
+       $(call toolchain_test,CONFIG_PACKAGE_libpthread,threads)
+endef
+
+define Host/Configure
+endef
+
+define Host/Compile
+endef
+
+define Host/Install
+       $(call toolchain_util,--wrap "$(TOOLCHAIN_DIR)/bin")
+endef
+
+define Host/Clean
+       rm -rf $(TOOLCHAIN_DIR)/bin
+endef
+
+$(eval $(call HostBuild))