ath9k: fix compiler warning without debug enabled
[openwrt/openwrt.git] / toolchain / gcc / files / wrapper.sh
1 #!/bin/bash
2
3 # 2009 (C) Copyright Industrie Dial Face S.p.A.
4 # Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
5 #
6 # Based on original idea from WindRiver
7 #
8 # Toolchain wrapper script.
9 #
10 # This script allows us to use a small number of GCC / binutils cross-tools
11 # (one toolchain per instruction set architecture) to implement a larger
12 # number of processor- or board-specific tools. The wrapper script is
13 # configured at install time with information covering basic CFLAGS,
14 # LD options and the toolchain triplet name.
15 #
16
17 PROGNAME=$0
18 REALNAME=`readlink -f $0`
19
20 REALNAME_BASE=`basename $REALNAME`
21 REALNAME_DIR=`dirname $REALNAME`
22
23 TARGET_FUNDAMENTAL_ASFLAGS=''
24 TARGET_FUNDAMENTAL_CFLAGS=''
25 TARGET_ROOTFS_CFLAGS=''
26 TARGET_FUNDAMENTAL_LDFLAGS=''
27 TARGET_TOOLCHAIN_TRIPLET=${REALNAME_BASE%-*}
28
29 # Parse our tool name, splitting it at '-' characters.
30 BINARY=${PROGNAME##*-}
31
32 # Parse our tool name, splitting it at '-' characters.
33 IFS=- read TOOLCHAIN_ARCH TOOLCHAIN_BUILDROOT TOOLCHAIN_OS TOOLCHAIN_PLATFORM PROGNAME << EOF
34 $REALNAME_BASE
35 EOF
36
37 #
38 # We add the directory this was executed from to the PATH
39 # The toolchains (links) should be in this directory or in the users
40 # PATH.
41 #
42 TOOLCHAIN_BIN_DIR="$REALNAME_DIR/"
43
44 # Set the PATH so that our run-time location is first
45 # (get_feature is run from the path, so this has to be set)
46 export PATH="$TOOLCHAIN_BIN_DIR":$PATH
47 export GCC_HONOUR_COPTS
48
49 TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/../.."
50 if [ ! -d "$TOOLCHAIN_SYSROOT" ]; then
51 echo "Error: Unable to determine sysroot (looking for $TOOLCHAIN_SYSROOT)!" >&2
52 exit 1
53 fi
54
55 # -Wl,--dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
56 # --dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
57
58 case $TOOLCHAIN_PLATFORM in
59 gnu|glibc|eglibc)
60 GCC_SYSROOT_FLAGS="--sysroot=$TOOLCHAIN_SYSROOT -Wl,-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
61 LD_SYSROOT_FLAGS="-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
62 ;;
63 uclibc)
64 GCC_SYSROOT_FLAGS="--sysroot=$TOOLCHAIN_SYSROOT -Wl,-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
65 LD_SYSROOT_FLAGS="-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
66 ;;
67 *)
68 GCC_SYSROOT_FLAGS=""
69 LD_SYSROOT_FLAGS=""
70 ;;
71 esac
72
73 #
74 # Run the cross-tool.
75 #
76 case $BINARY in
77 cc|gcc|g++|c++|cpp)
78 exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin $GCC_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_CFLAGS $TARGET_ROOTFS_CFLAGS "$@"
79 ;;
80 ld)
81 exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin $LD_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_LDFLAGS "$@"
82 ;;
83 as)
84 exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin $TARGET_FUNDAMENTAL_ASFLAGS "$@"
85 ;;
86 *)
87 exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin "$@"
88 ;;
89 esac
90
91 exit 0