blob: 09a9cac928abd9f38e55e4b7ef6e6a0bb415f0e9 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/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
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 -r _ _ _ 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 ORIG_PATH=${ORIG_PATH:-$PATH}
47export PATH="$TOOLCHAIN_BIN_DIR":$PATH
48export GCC_HONOUR_COPTS
49
50TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/.."
51if [ ! -d "$TOOLCHAIN_SYSROOT" ]; then
52 echo "Error: Unable to determine sysroot (looking for $TOOLCHAIN_SYSROOT)!" >&2
53 exit 1
54fi
55
56# -Wl,--dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
57# --dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
58
59case $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 ;;
68esac
69
70#
71# Run the cross-tool.
72#
73case $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 ;;
86esac
87
88exit 0