Root/target/toolchain/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
17PROGNAME=$0
18REALNAME=`readlink -f $0`
19
20REALNAME_BASE=`basename $REALNAME`
21REALNAME_DIR=`dirname $REALNAME`
22
23TARGET_FUNDAMENTAL_ASFLAGS=''
24TARGET_FUNDAMENTAL_CFLAGS=''
25TARGET_ROOTFS_CFLAGS=''
26TARGET_FUNDAMENTAL_LDFLAGS=''
27TARGET_TOOLCHAIN_TRIPLET=${REALNAME_BASE%-*}
28
29# Parse our tool name, splitting it at '-' characters.
30BINARY=${PROGNAME##*-}
31
32# Parse our tool name, splitting it at '-' characters.
33IFS=- read TOOLCHAIN_ARCH TOOLCHAIN_BUILDROOT TOOLCHAIN_OS TOOLCHAIN_PLATFORM PROGNAME << EOF
34$REALNAME_BASE
35EOF
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#
42TOOLCHAIN_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)
46export PATH="$TOOLCHAIN_BIN_DIR":$PATH
47export GCC_HONOUR_COPTS
48
49TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/../.."
50if [ ! -d "$TOOLCHAIN_SYSROOT" ]; then
51  echo "Error: Unable to determine sysroot (looking for $TOOLCHAIN_SYSROOT)!" >&2
52  exit 1
53fi
54
55# -Wl,--dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
56# --dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
57
58case $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       ;;
71esac
72
73#
74# Run the cross-tool.
75#
76case $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        ;;
89esac
90
91exit 0
92

Archive Download this file



interactive