ath79: add support for 8Devices Carambola3 board
[openwrt/openwrt.git] / target / toolchain / files / wrapper.sh
1 #!/bin/sh
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 -r _ _ _ 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 ORIG_PATH=${ORIG_PATH:-$PATH}
47 export PATH="$TOOLCHAIN_BIN_DIR":$PATH
48 export GCC_HONOUR_COPTS
49
50 TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/.."
51 if [ ! -d "$TOOLCHAIN_SYSROOT" ]; then
52 echo "Error: Unable to determine sysroot (looking for $TOOLCHAIN_SYSROOT)!" >&2
53 exit 1
54 fi
55
56 # -Wl,--dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
57 # --dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
58
59 case $TOOLCHAIN_PLATFORM in
60 gnu|glibc|uclibc|musl)
61 GCC_SYSROOT_FLAGS="--sysroot=$TOOLCHAIN_SYSROOT -Wl,-rpath-link=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
62 LD_SYSROOT_FLAGS="-rpath-link=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
63 ;;
64 *)
65 GCC_SYSROOT_FLAGS=""
66 LD_SYSROOT_FLAGS=""
67 ;;
68 esac
69
70 #
71 # Run the cross-tool.
72 #
73 case $BINARY in
74 cc|gcc|g++|c++|cpp)
75 exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" $GCC_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_CFLAGS $TARGET_ROOTFS_CFLAGS "$@"
76 ;;
77 ld)
78 exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" $LD_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_LDFLAGS "$@"
79 ;;
80 as)
81 exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" $TARGET_FUNDAMENTAL_ASFLAGS "$@"
82 ;;
83 *)
84 exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" "$@"
85 ;;
86 esac
87
88 exit 0