aboutsummaryrefslogtreecommitdiffstats
path: root/include/target.mk
Commit message (Expand)AuthorAgeFilesLines
* buildsystem: add CONFIG_SECCOMPFlorian Eckert2021-10-161-1/+1
* build: select procd-seccomp if kernel support is presentDaniel Golle2021-10-071-0/+5
* build: select procd-ujail if !SMALL_FLASHDaniel Golle2021-10-071-0/+5
* build: use SPDX license tagsPaul Spooren2021-02-051-4/+1
* build: filter out more autogenerated kernel config optionsFelix Fietkau2020-11-131-4/+4
* Revert "target: select procd-{ujail,seccomp} if !SMALL_FLASH"Petr Štetiar2020-10-221-4/+0
* target: select procd-{ujail,seccomp} if !SMALL_FLASHDaniel Golle2020-10-211-0/+4
* target: include selinux-variants if CONFIG_SELINUX is setDaniel Golle2020-10-211-1/+7
* rtl838x: various fixesJohn Crispin2020-10-191-0/+1
* malta: update MIPS64 ISA to R2Tony Ambardar2020-10-111-0/+1
* target.mk: enable iwinfo by default with any wpad variantPiotr Dymacz2020-09-281-1/+1
* build: sort default packages and split by newlinesPaul Spooren2020-08-311-3/+32
* build: add libustream and certs to default pkgsPaul Spooren2020-08-311-1/+1
* hostapd: add wpad-basic-wolfssl variantPetr Štetiar2020-08-071-1/+1
* target.mk: change i386 CPU type to pentium-mmxRosen Penev2020-07-081-2/+2
* build: conditionally enable testing-kernel featureDavid Bauer2020-07-071-1/+3
* treewide: provide consistent basic DEVICE_TYPEAdrian Schmutzler2020-06-031-1/+2
* kernel: remove further obsolete kernel version switchesSungbo Eo2020-01-181-4/+0
* build: add urandom-seed and urngd to default packages setPetr Štetiar2019-06-111-1/+1
* build: add a config option for enabling a testing version of the target kernelFelix Fietkau2019-05-111-0/+4
* kernel: Remove support for kernel 3.18Hauke Mehrtens2019-05-031-1/+1
* toolchain: ARM: Fix toolchain compilation for gcc 8.xBoris Krasnovskiy2019-03-251-20/+0
* hostapd: add basic variantKevin Darbyshire-Bryant2018-10-161-1/+1
* target.mk: Remove obsolete octeon CPU_CFLAGSDaniel Engberg2018-08-191-1/+0
* kernel: remove linux 4.4 supportKoen Vandeputte2018-08-081-1/+1
* build: do not alter global default package selection from profilesJo-Philipp Wich2018-07-211-1/+0
* octeon: Add and set CPU type Octeon+ as defaultDaniel Engberg2018-06-201-0/+1
* mvebu: add support for MACCHIATObin (cortex-a72)Damir Samardzic2018-03-311-0/+1
* build: filter out kmod-ipt-offload from the default selection on targets that...Felix Fietkau2018-03-301-0/+4
* build: include kmod-ipt-offload in default imagesFelix Fietkau2018-03-271-1/+1
* target.mk: let profile remove from DEFAULT_PACKAGESPhilip Prindeville2018-02-131-0/+2
* target: Remove nomips16 option.Rosen Penev2018-02-131-3/+1
* target: replace odhcpd by odhcpd-ipv6onlyHans Dedecker2017-11-291-1/+1
* target: add cpu flags for powerpc64Florian Larysch2017-10-241-0/+4
* kernel: split patches folder up into backport, pending and hack foldersJohn Crispin2017-08-051-1/+3
* build: fix aarch64 default cpu selectionYousong Zhou2017-04-231-2/+2
* target.mk: check that CPU_TYPE has known CPU_CFLAGS mappingPhilip Prindeville2017-04-041-0/+5
* include: Add nomips16 CPU_SUBTYPEHauke Mehrtens2017-03-201-1/+3
* ARC: use -mcpu=XXX instead of obsolete -mXXXAlexey Brodkin2017-02-111-2/+2
* x86: unify CPU_TYPE for legacy and geodeFelix Fietkau2017-01-241-3/+2
* build: remove mips16 feature flag from target makefilesFelix Fietkau2017-01-241-0/+3
* build: remove obsolete mips32r2 CPU_TYPEFelix Fietkau2017-01-241-1/+0
* ubox: turn logd into a separate packageAndrej Vlasic2017-01-161-1/+1
* include: Cortex-A53 is also an AArch64 CPUFlorian Fainelli2016-11-041-0/+1
* ubox: move logd into ubox packageFelix Fietkau2016-08-231-1/+1
* ramips: mt7621: switch to 24kcJonas Gorski2016-08-231-1/+0
* include: remove 34k distinctionJonas Gorski2016-08-231-1/+0
* kernel: add plan 9 fs packageMatteo Croce2016-08-111-0/+3
* ramips: switch from 24kec to 24kcJonas Gorski2016-08-081-1/+0
* build: remove MIPS dsp/dsp2 CPU_SUBTYPEFelix Fietkau2016-08-031-2/+0
* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/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_bin_cc() {
	local out="$1"
	local bin="$2"

	echo    '#!/bin/sh'                                                > "$out"
	echo    'for arg in "$@"; do'                                     >> "$out"
	echo    ' case "$arg" in -l*|-L*|-shared|-static)'                >> "$out"
	echo -n '  exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'           >> "$out"
	echo -n '-idirafter "$STAGING_DIR/usr/include" '                  >> "$out"
	echo -n '-L "$STAGING_DIR/usr/lib" '                              >> "$out"
	echo    '-Wl,-rpath-link,"$STAGING_DIR/usr/lib"} "$@" ;;'         >> "$out"
	echo    ' esac'                                                   >> "$out"
	echo    'done'                                                    >> "$out"
	echo -n 'exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'             >> "$out"
	echo    '-idirafter "$STAGING_DIR/usr/include"} "$@"'             >> "$out"

	chmod +x "$out"
}

wrap_bin_ld() {
	local out="$1"
	local bin="$2"

	echo    '#!/bin/sh'                                                > "$out"
	echo -n 'exec "'"$bin"'" ${STAGING_DIR:+'                         >> "$out"
	echo -n '-L "$STAGING_DIR/usr/lib" '                              >> "$out"
	echo    '-rpath-link "$STAGING_DIR/usr/lib"} "$@"'                >> "$out"

	chmod +x "$out"
}

wrap_bin_other() {
	local out="$1"
	local bin="$2"

	echo    '#!/bin/sh'                                                > "$out"
	echo    'exec "'"$bin"'" "$@"'                                    >> "$out"

	chmod +x "$out"
}

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##*/}"
				local bin="$cmd"

				if [ -x "$out" ] && ! grep -q STAGING_DIR "$out"; then
					mv "$out" "$out.bin"
					bin='$(dirname "$0")/'"${out##*/}"'.bin'
				fi

				case "${cmd##*/}" in
					*-*cc|*-*cc-*|*-*++|*-*++-*|*-cpp)
						wrap_bin_cc "$out" "$bin"
					;;
					*-ld)
						wrap_bin_ld "$out" "$bin"
					;;
					*)
						wrap_bin_other "$out" "$bin"
					;;
				esac
			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"

	if [ "$LIBC_TYPE" != glibc ]; then
		echo "CONFIG_TOOLCHAIN_LIBC=\"$LIBC_TYPE\"" >> "$config"
	fi

	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