wrapper.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  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 -r _ _ _ 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 ORIG_PATH=${ORIG_PATH:-$PATH}
  39. export PATH="$TOOLCHAIN_BIN_DIR":$PATH
  40. export GCC_HONOUR_COPTS
  41. TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/.."
  42. if [ ! -d "$TOOLCHAIN_SYSROOT" ]; then
  43. echo "Error: Unable to determine sysroot (looking for $TOOLCHAIN_SYSROOT)!" >&2
  44. exit 1
  45. fi
  46. # -Wl,--dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
  47. # --dynamic-linker=$TOOLCHAIN_SYSROOT/lib/ld-uClibc.so.0
  48. case $TOOLCHAIN_PLATFORM in
  49. gnu|glibc|uclibc|musl)
  50. GCC_SYSROOT_FLAGS="--sysroot=$TOOLCHAIN_SYSROOT -Wl,-rpath-link=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
  51. LD_SYSROOT_FLAGS="-rpath-link=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
  52. ;;
  53. *)
  54. GCC_SYSROOT_FLAGS=""
  55. LD_SYSROOT_FLAGS=""
  56. ;;
  57. esac
  58. #
  59. # Run the cross-tool.
  60. #
  61. case $BINARY in
  62. cc|gcc|g++|c++|cpp)
  63. exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" $GCC_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_CFLAGS $TARGET_ROOTFS_CFLAGS "$@"
  64. ;;
  65. ld)
  66. exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" $LD_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_LDFLAGS "$@"
  67. ;;
  68. as)
  69. exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" $TARGET_FUNDAMENTAL_ASFLAGS "$@"
  70. ;;
  71. *)
  72. exec "$TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin" "$@"
  73. ;;
  74. esac
  75. exit 0