1
0

wrapper.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # 2009 (C) Copyright Industrie Dial Face S.p.A.
  3. # Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
  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|eglibc)
  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. uclibc)
  53. GCC_SYSROOT_FLAGS="--sysroot=$TOOLCHAIN_SYSROOT -Wl,-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
  54. LD_SYSROOT_FLAGS="-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
  55. ;;
  56. musl)
  57. GCC_SYSROOT_FLAGS="--sysroot=$TOOLCHAIN_SYSROOT -Wl,-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
  58. LD_SYSROOT_FLAGS="-rpath=$TOOLCHAIN_SYSROOT/lib:$TOOLCHAIN_SYSROOT/usr/lib"
  59. ;;
  60. *)
  61. GCC_SYSROOT_FLAGS=""
  62. LD_SYSROOT_FLAGS=""
  63. ;;
  64. esac
  65. #
  66. # Run the cross-tool.
  67. #
  68. case $BINARY in
  69. cc|gcc|g++|c++|cpp)
  70. exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin $GCC_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_CFLAGS $TARGET_ROOTFS_CFLAGS "$@"
  71. ;;
  72. ld)
  73. exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin $LD_SYSROOT_FLAGS $TARGET_FUNDAMENTAL_LDFLAGS "$@"
  74. ;;
  75. as)
  76. exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin $TARGET_FUNDAMENTAL_ASFLAGS "$@"
  77. ;;
  78. *)
  79. exec $TARGET_TOOLCHAIN_TRIPLET-$BINARY.bin "$@"
  80. ;;
  81. esac
  82. exit 0