[scripts] ext-toolchain.sh: properly handle toolchains without sysroot support
[openwrt.git] / scripts / ext-toolchain.sh
index de5d676..26dc198 100755 (executable)
@@ -1,6 +1,23 @@
 #!/usr/bin/env bash
-# Script to copy a toolchain from given source to given
-# destination directory.
+#
+#   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=""
@@ -72,9 +89,9 @@ test_softfloat() {
 
 test_uclibc() {
        local sysroot="$("$CC" $CFLAGS -print-sysroot 2>/dev/null)"
-       if [ -d "$sysroot" ]; then
+       if [ -d "${sysroot:-$TOOLCHAIN}" ]; then
                local lib
-               for lib in "$sysroot"/{lib,usr/lib,usr/local/lib}/ld-uClibc*.so*; do
+               for lib in "${sysroot:-$TOOLCHAIN}"/{lib,usr/lib,usr/local/lib}/ld-uClibc*.so*; do
                        if [ -f "$lib" ] && [ ! -h "$lib" ]; then
                                return 0
                        fi
@@ -107,7 +124,7 @@ test_feature() {
        local inc
        local sysroot="$("$CC" "$@" -muclibc -print-sysroot 2>/dev/null)"
        for inc in "include" "usr/include" "usr/local/include"; do
-               local conf="$sysroot/$inc/bits/uClibc_config.h"
+               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 $?;;
@@ -157,12 +174,9 @@ find_bins() {
 
                local bindir bindirs
                for bindir in $(
-                       echo "$sysroot/bin";
-                       echo "$sysroot/usr/bin";
-                       echo "$sysroot/usr/local/bin";
-                       echo "$TOOLCHAIN/bin";
-                       echo "$TOOLCHAIN/usr/bin";
-                       echo "$TOOLCHAIN/usr/local/bin";
+                       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
@@ -289,21 +303,6 @@ probe_libc() {
 while [ -n "$1" ]; do
        arg="$1"; shift
        case "$arg" in
-               -l|--libs)
-                       [ -n "$1" ] || {
-                               echo "No library given, specify one of:"$(echo "$LIB_SPECS" | sed -ne 's#:.*$##p') >&1
-                               exit 1
-                       }
-                       FINDLIB="$1"; shift
-               ;;
-               -b|--bins)
-                       [ -n "$1" ] || {
-                               echo "No binary given, specify one of:"$(echo "$BIN_SPECS" | sed -ne 's#:.*$##p') >&1
-                               exit 1
-                       }
-                       FINDBIN="$1"; shift
-               ;;
-
                --toolchain)
                        [ -d "$1" ] || {
                                echo "Toolchain directory '$1' does not exist." >&2
@@ -328,9 +327,7 @@ while [ -n "$1" ]; do
 
                --print-target)
                        if probe_cc; then
-                               CC="${CC##*/}"
-                               echo "${CC%-*}"
-                               exit 0
+                               exec "$CC" $CFLAGS -dumpmachine
                        fi
                        echo "No C compiler found in '$TOOLCHAIN'." >&2
                        exit 1
@@ -407,4 +404,4 @@ while [ -n "$1" ]; do
        esac
 done
 
-exit 0
+exec $0 --help
This page took 0.023252 seconds and 4 git commands to generate.