wrapper.sh 2.4 KB

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